Gossamer Forum
Home : Products : DBMan : Customization :

auto archive

Quote Reply
auto archive
has anyone a clue on how to autoArchive DBentries after a certain time (eg 5days) which fullfill certain criteria like a DBfield is tagged "ok4archive".

Quote Reply
Re: auto archive In reply to
There's an "Auto-Archive" MOD in the Resource section for DBMan, I'm sure it would be easy to hack in the "archiveok" criteria.

Good luck!

- Mark


Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: auto archive In reply to
great! thanx a lot.

but I couldn't find the time schedule part. even it says in the description "after a certain lenght of time" there was no way of spotting that option in the code!

ideas??

Quote Reply
Re: auto archive In reply to
Hi 4wallaby,

I made the same reflexion as you and made this hack of the mod to suit my purposes.

Code:

sub check_archive {
# This sub checks if there is any records which has passed its' expiry date,
# and, if so, archives it and deletes it from the database
# When this is done the user is taken either to the login form or the
# search page

my $today = &date_to_unix(&get_date);
my @lines;

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

open (ARC, ">>$db_archive_name") or &cgierr("error in check_archive. Unable to open archive database: $db_archive_name.\nReason: $!");
if ($db_use_flock) {
flock(ARC, 2) or &cgierr("unable to get exclusive lock on $db_archive_name.\nReason: $!");
}

open (DB, ">$db_file_name") or &cgierr("error in check_archive. 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: $!");
}

$count_archive = 0;

foreach (@lines) {
next if /^#/;
next if /^\s*$/;
chomp;

@fields = &split_decode ($_);
$expiry_date = &date_to_unix($fields[$archive_key]) + 1;

if ( $today > $expiry_date) {
print ARC $_, "\n";
$count_archive++;
}
else {
print DB $_, "\n";
}
}
close ARC; # automatically removes file lock
close DB;

# send mail to admin on archive result
if ($count_archive > 0) {
&mail_archive;
}

if ($in{'archive'} eq 'signin') {
&html_login_form;
}
else {

$per_view = 1;
$db_uid = "default";
$db_script_link_url = "$db_script_url?db=$db_setup&uid=$db_uid";
&html_view_search;
}
}

# Mail archiving to admin
sub mail_archive{
my $today = &get_date;
open (MAIL, "$mailprog") || &cgierr( "Can't open mail program!\n");
print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: Archive of $database_name\n\n";
print MAIL "Date: $today\n";
print MAIL "$count_archive records have been archived from $db_file_name to $db_archive_name.\n\n";
close (MAIL);
}
I have expiry_date as an explicit field in the database, but I suppose you can use the creation date as the $archive_key and set
Code:

$expiry_date = &date_to_unix($fields[$archive_key]) + $stay_alive;
and set $stay_alive = 6 to have the record archived after five days.

This routine works as a pre-login routine which makes sure that regardless if the user enters the database as a guest or a registered user all old records will be archived in the beginning of the session: The link to the database includes &archive=guest or &archive=signin.

This requires of course
Code:

elsif ($in{'archive'}) {
&check_archive;
in the long elsif sequence in sub main.

Hope this is of some help.

Quote Reply
Re: [O grain] auto archive In reply to
Has anyone implemented this successfully? I added his hack on the hack. It gave me no errors, but I am unsure about his explanation of the expiry_date. He says, "I have expiry_date as an explicit field in the database". I have in my default.cfg a field called 'Date' at #20. Is this the creation date? If so, how do I tell this hack to use that field at this code he suggests using if you want to use the creation date:

$expiry_date = &date_to_unix($fields[$archive_key]) + $stay_alive;

Also, he says if I do use that code to, "set $stay_alive = 6". Where would I add that?

Ideally, I need auto-archiving to happen every 2 weeks. I can't use the auto-delete, as we need to keep the old records.
Quote Reply
Re: [O grain] auto archive In reply to
Is this the routine I/we need to add to make JP's Archive mod an "auto-archive" mod??

Not sure whether this is the code or [O grain's] modification of an original auto-archive code...
Quote Reply
Re: [omegadm] auto archive In reply to
Just read it a bit more thoroughly :) I guess it IS all the code that is required.

To run each time anyone uses DBMan, can I simply add:
&check_archive

in db.pl, just above:
# Main Menu.





Quote Reply
Re: [omegadm] auto archive In reply to
O grain stated:

This routine works as a pre-login routine which makes sure that regardless if the user enters the database as a guest or a registered user all old records will be archived in the beginning of the session: The link to the database includes &archive=guest or &archive=signin.
-------

So I you could add that to the links to access the database.

What I do with the auto delete mod is to add the code within the auth.pl file you can test and see if this would work for the archive.

You could place within sub auth_check_password

after:

open(AUTH, ">$auth_dir/$db_uid") or &cgierr("unable to open auth file: $auth_dir/$uid. Reason: $!\n");
print AUTH "$uid: $ENV{'REMOTE_HOST'}\n";
close AUTH;

&check_archive;

and before:

foreach (0 .. 3) { $permissions[$_] = int($permissions[$_]); }
&auth_logging('logged on', $userid) if ($auth_logging);
return ('ok', $db_uid, $view, $add, $del, $mod, $admin);
}

Test and see if it works and let us know.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] auto archive In reply to
i think the issue for me with putting it there (in auth.pl) is that the auto-archive will only take place when a user is trying to log on. I need to have this when ever the public searches DBMan and/or a user logs in.

I am wondering though that if I do put it the &check_archive above the elseif statements in db.pl, if this will put a large overhead on the script/server i.e. constantly reading the contents of the the default.db into an array...

BTW, for the mod you need to add to the default.cfg:
$archive_key = 'DateOfEntry';

or whatever your date key is.

Also I think the line:
$expiry_date = &date_to_unix($fields[$archive_key]) + $stay_alive;


Should be:
$expiry_date = &date_to_unix($fields[$archive_key]) + (3600*24*$stay_alive);

Best regards, Brian
Quote Reply
Re: [omegadm] auto archive In reply to
I guess I could just modify sub auth_check_password of auth.pl

From:
if ($auth_no_authentication || (($db_uid eq 'default') && $auth_allow_default)) {
return ('ok', 'default', @auth_default_permissions);
}

To:
if ($auth_no_authentication || (($db_uid eq 'default') && $auth_allow_default)) {
&check_archive;
return ('ok', 'default', @auth_default_permissions);
}

and that covers both scenarios??

At the moment all records are being archived as soon as I log in Unimpressed
Quote Reply
Re: [omegadm] auto archive In reply to
OK got it - implimented my last 2 posts but changed:

$archive_key = 'DateOfEntry';

to:
$archive_key = '8';

Working nicely :)))
Quote Reply
Re: [omegadm] auto archive In reply to
OK final mod for this...

I wish to email the owners of each record that gets auto-archived. I have made the following changes:

if ( $today > $expiry_date) {
# next if statement retreives the email address from the db
# the number in {} must match the number in the .cfg file
# data separator is '|' in this case but could use $db_delim
if ($_ =~ /(.*\|){10}(.+\@.+)$/){
$record_email = $2;
$record_email =~ s/\@/\\\@/;
&mail_owner($record_email);
}
print ARC $_, "\n";
$count_archive++;
} else {
print DB $_, "\n";
}


New sub routine
# Mail archiving to record owner
sub mail_owner{
local ($record_email) = @_;
$todaybc = &get_date;
open (MAIL, "$mailprog") || &cgierr( "Can't open mail program!\n");
print MAIL "To: $record_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $html_title: Record Archived\n\n";
print MAIL "On date: $todaybc\n";
print MAIL "A record from your account has been archived from the database as it is older than $stay_alive days.\n\n";
print MAIL "Regards, \n$html_title Database Administrator.\n Email = >$record_email<\n";
close (MAIL);
}


However no mail comes through to the owner - the apache error_log file shows there is a bad header in the to: field when calling sendmail.

If I fix as:
print MAIL "To: webmaster\@omegadm.co.uk\n";

It works - email is sent with the last line "Email = " correctly set as the owner of the record e.g. owner\@omegadm.co.uk!!

Can anyone please help me with the syntax for this?

Last edited by:

omegadm: May 29, 2002, 12:57 PM
Quote Reply
Re: [omegadm] auto archive In reply to
Just a guess by trying adding:

%rec = &get_record($in{$db_key});

to the top of sub mail_owner {

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] auto archive In reply to
Nope.. that stops the archive file being written to properly - I just get blank lines (same nuumber as there should be archived records!). If I comment your line out it works again.

What's your thinking LoisC??

I can't understand how the variable can print out correctly but the email is not being sent Unsure

Best regards, Brian
Quote Reply
Re: [omegadm] auto archive In reply to
Do you have defined within your .cfg file:

Under # Authorization Options

$db_email_field = 'Email';

to be the name of your email field? If so, it should be able to read the email address from within the record. Unless of course you are sending the email after the record is archived and in that case wouldn't you need to read the email from the archive.db ?

Maybe looking at other email mods and routines would help you find a solution. Or perhaps someone might jump in here and help out.

Just a thought perhaps some of the coding written for the autodelete mod might help you out. Check out http://webmagic.hypermart.net/autodel.htm and click on the link for "Auto Notify - notify via email of deletion".

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] auto archive In reply to
In Reply To:
Do you have defined within your .cfg file:

Under # Authorization Options

$db_email_field = 'Email';
Quote Reply
Re: [omegadm] auto archive In reply to
put all together, as anyone made this work?

I need help- as soon as I login it takes all the records and puts them into never-never land
Quote Reply
Re: [mabel] auto archive In reply to
Yes, this is working for me now.

Not sure what happened to my last post as it has been cut off...

Anyhow, just follow the thread and make the suggested changes. My last post concerned emailing the record owners when their advertisements were archived so they could login and unarchive them if necessary (I plan to use auto delete if they don't). If you need this let me know and I'll did out what I did again.

Best regards, Brian