Gossamer Forum
Home : Products : DBMan : Customization :

Unarchive doesn't work for me

Quote Reply
Unarchive doesn't work for me
Hi all,

has anybody installed the archive-mod and its working for him??

For me its works nearly perfect, but if I want to unarchive a record, the new line in default.db contains only ||||||||||||||||||||||||.

What can this be??

Thanx for help.

Pit

Quote Reply
Re: Unarchive doesn't work for me In reply to
Are you using the latest version of this mod?

I know there was a correction made on May 7th. I would compare the version you have to be sure it is the same.

The correction was in sub archive_records.

You need to change code:

print ARC &join_encode(%in);

to code:

print ARC "$line\n";

This may not be related to your problem, but it's possible.

You get get the latest version at:
http://www.jpdeni.com/dbman/Mods/archive.txt

If not, you may want to search the forum and see if you can find a solution.

Quote Reply
Re: Unarchive doesn't work for me In reply to
Hi LoisC,

yes I have the newest mod.

Does someone have installed this mod without my problem of unarchiving?

Pit

Quote Reply
Re: Unarchive doesn't work for me In reply to
I think you may be the first person to use the mod. No one has said anything about it before.

I'm pretty sure I've found the problem.

In sub unarchive_records, change

print DB &join_encode(%in);

to

print DB "$line\n";

Looks like I had fixed it in the "archive" portion, but not the "unarchive" portion. I'll get that fixed right away.


JPD
Quote Reply
Re: Unarchive doesn't work for me In reply to
Hi Carol,

I will try your fix today.

Thanx very much for it.

I'm sure, a lot of people use this mod, but a very few people use the unarchive part of it.

Pit

Quote Reply
Re: Unarchive doesn't work for me In reply to
Hi Carol,

thanx very much for bugfixing the archive mod. It works fantastic.

I've made a autoarchive mod yesterday, but I want to make a few new things into it next weekend.

I have one other question:

If I unarchive a record, is it possible to get the new date in my &getdate field.
For now it is so, that the old dateadded field is again in the default.db.

That isn't good for working with the autoarchive-mod :-)

Cu until friday, because tomorrow is free here (like sunday).

Pit

Quote Reply
Re: Unarchive doesn't work for me In reply to
Yes, it would be possible to reset the date, but a little messy. Smile

First, you would need to add something to your .cfg file to tell the script which field was the date field:

$db_date_field = 4; # The number of the date field.

Then, in sub unarchive records, instead of

print DB "$line\n";

use


$data[$db_date_field] = &get_date;
$new_data = join $db_delim,@data;
print DB, "$new_data\n";




JPD
Quote Reply
Re: Unarchive doesn't work for me In reply to
Hi Carol,

hm, it doesn't work for me.

I also tried to change the data with

$data[$db_date_field] = &get_date;
print DB "$line\n";

because I thought, that it is a simple change of one element of an array.

But it also doesn't work.

Pit

Quote Reply
Re: Unarchive doesn't work for me In reply to
How doesn't it work? Are you getting an error message? Is the field blank? Is the original date still there? Does it mess up your whole record?

In Reply To:
I also tried to change the data with

$data[$db_date_field] = &get_date;
print DB "$line\n";
No, that won't work. Changing the value of the array item will not change the text in the $line variable. You need to change the array item and then join the array into a variable and write that variable to the file.



JPD
Quote Reply
Re: Unarchive doesn't work for me In reply to
Hi Carol,

now I found the thread. Please close the other.

How it does not work:

There is still the original date in my database, no error, but also no new date.

Pit

Quote Reply
Re: Unarchive doesn't work for me In reply to
That's the only way I can think that you could do it.

You break up the record into an array --
@data = &split_decode($line);

You put the new date into the array location that corresponds to the date field --
$data[$db_date_field] = &get_date;

You put the array back together into one string, using the delimiter --
$new_data = join $db_delim,@data;

Then you print the string to the database --
print DB, "$new_data\n";

It's the only way it can be done.


JPD
Quote Reply
Re: Unarchive doesn't work for me In reply to
Hi Carol,

I will test it today.

But first I want to thank you for your explicit answer.
This answer is gold for me learning perl.

Thanx and I will say you, if it works

Pit

Quote Reply
Re: Unarchive doesn't work for me In reply to
Hi Carol,

juuuuuhhhhuuuuu, it works like a charm for me now. Great.

The only, what was false in your code, was a comma:

not print DB, "$new_data\n"; but print DB "$new_data\n";

But than, it works, and works and works.

Carol, one other question I have:

Because of archiving and unarchiving I want to sort my databases after (un)archiving prozesses and want to delete the empty lines.

Can you tell me how to sort the lines so, that key1 is the first and key(last) is my last record in the database?

To delete the empty lines, I think I could try myself, but sort the database I tried a few days before, but no success for me.

Pit

And thanx again, Carol for your help!!!






Quote Reply
Re: Unarchive doesn't work for me In reply to
Sorry 'bout the comma. I'm glad it worked for you.

One of the basics in database theory is that it doesn't matter what order the records are in within the file. If you modify any record, the order will change anyway. As long as you include a "sb" setting when you do a search, the records will come up in the right order.

As for the blank lines, they will be eliminated by the script as soon as you modify any record.


JPD
Quote Reply
Re: Unarchive doesn't work for me In reply to
Hi Carol,

its right what You said, but for me as the admin of my database, it would be easier to work with the datas, if the could be in the right order.
In my case, first ID1 for example and not ID5.

Pit

Quote Reply
Re: Unarchive doesn't work for me In reply to
I understand. But it would be a lot of work to write the script and take a lot of CPU time to rearrange all of the records in your .db file -- and then as soon as you modified a record, it would be out of order again.

Nevertheless, if you want to do it, you can do it.

In sub unarchive_records, after

&auth_logging("unarchived records: $succstr") if ($auth_logging);

add

Code:

open (DB, "<$db_file_name") or &cgierr("error in archive_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;

foreach $line (@lines) {
unless ($line =~ /^#/) {
++$line_count;
}
}

$in{$db_key} = "*";
$in{'mh'} = $line_count;
$in{'sb'} = $db_key_pos;
$output = "";

my ($status,@hits) = &query{'view'};
my ($numhits) = ($#hits+1) / ($#db_cols+1);
for (0 .. $numhits - 1) {
% rec = &array_to_hash($_, @hits); # Be sure to take out the space between % and rec
$output .= &join_encode(% rec) . "\n";
}

open (DB, ">$db_file_name") or &cgierr("error in unarchive_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
}
print DB $output;
close DB; # automatically removes file lock
If you want to keep the records in order after they are modified, add the same code to sub modify_record, before

&auth_logging("modified record: $in{$db_key}") if ($auth_logging);



JPD
Quote Reply
Re: Unarchive doesn't work for me In reply to
Hi Carol,

first of all, thanx again alot!!!!!!

I will try this mod in about 2 days.

***I understand. But it would be a lot of work to write the script and take a lot of CPU time to rearrange all of the records in your .db file -- and then as soon as you modified a record, it would be out of order again.***

Yes, you are right! But I have 2 good reasons for this mod.
First is, that I tried it for my own and I could`'t get my own to work. So I have to learn it, and you are the best teacher of all!
Second is, that I want this mod to work in my autoarchive-mod, that will run in a cron at 3 o' clock in the morning, so the server (cpu) is not so bussy.
Because that I also do not have to rearrange the database after every modification of record, once a day will be enough.

But managing my database is easier to do, if the sorting order is ok.

And: The sorting order of searchresult, if nothing is specified, is so, as the are in your textfile.
But I want for my database, that the entries, that came first, are also the first in search-result, if the searcher has nothing other specified.

So, you see, I want something good for the recordholders in my database for coming early (puh, english language is sometimes soooo difficult for me...)

Greetings to all of you

Pit


Quote Reply
Re: Unarchive doesn't work for me In reply to
First, I had forgotten to put something into the previous code. I added it in blue in the code that was there.

In Reply To:
Second is, that I want this mod to work in my autoarchive-mod, that will run in a cron at 3 o' clock in the
morning, so the server (cpu) is not so bussy.
Probably not a good idea. The code I gave you relies on sub query in order to run. And sub query relies on having the data within your .cfg file. If you want to write a new query subroutine for your cron script, that would be okay I guess. But it's more work than I want to do.


JPD