Gossamer Forum
Home : Products : DBMan : Customization :

auto delete mod problems

Quote Reply
auto delete mod problems
I have auto delete mod insalled but instead of deleting a record i wish to change 1 value if it gets older than $remove

So far i have this and it works but it changes the value eveytime someone logs in
Anybody help with what i may missed

sub auto_delete {
# ------------------------------------------
# Change field entry older then $remove # days old.
#
my $remove = 14; # Number of days old.
my $date_field = 2; # Field Position of date field.

my $today = &date_to_unix(&get_date);
my $removeby = $today - ($remove * 86400);
my (@lines, @values);
open (DB, $db_file_name) or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 1); }
@lines = <DB>;
close DB;
open (DB, ">$db_file_name") or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 2); }
foreach (@lines) {
next if /^#/;
next if /^\s*$/;
chomp;
@values = &split_decode ($_);
%rec = &array_to_hash(0,@values);
$rec{'hilight'} = '';
print DB &join_encode(%rec);
}
close DB;
}


Quote Reply
Re: auto delete mod problems In reply to
Why you run it when admin log into your system?


Quote Reply
Re: auto delete mod problems In reply to
All i want to do is change a field, i dont want to delete old records

And this is checked via the &auto_delete being added to the auth.pl file.
So when anyone logs in it checks and changes old records value for me



Quote Reply
Re: auto delete mod problems In reply to
Add another field and default value is 0. When you wnat to delete set it to 1.

Regards,

Mark

Quote Reply
Re: auto delete mod problems In reply to
lemme explain the problem again

with my above code it changes all the record fields for
$rec{'hilight'} = '';
no matter what the age is

i seem to have missed somthing, i only want to change
$rec{'hilight'} = '';
if the record is older then 14 days


Quote Reply
Re: auto delete mod problems In reply to
You did not compare the date field in your database with the remove date please change this function to:

sub auto_delete {
# ------------------------------------------
# Change field entry older then $remove # days old.
#
my $remove = 14; # Number of days old.
my $date_field = 2; # Field Position of date field.

my $today = &date_to_unix(&get_date);
my $removeby = $today - ($remove * 86400);
my (@lines, @values);
open (DB, $db_file_name) or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 1); }
@lines = <DB>;
close DB;
open (DB, ">$db_file_name") or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 2); }
foreach (@lines) {
next if /^#/;
next if /^\s*$/;
chomp;
@values = &split_decode ($_);
%rec = &array_to_hash(0,@values);
$date_in_db = &date_to_unix($rec{date});
if($date_in_db < $removeby){
$rec{'hilight'} = '';
}
print DB &join_encode(%rec);
}
close DB;
}


Quote Reply
Re: auto delete mod problems In reply to
Thankyou very much it worked like a charm :)

One other thing to add to this if possible

when $rec{'hilight'} = '' is done i would like to be able to delete the picture thats linked with the same field

so when the field hilight becomes older than 14 days it is = '' and the image file they uploaded is deleted.

ive tried adding this but it doesnt seem to work

sub auto_delete {
# ------------------------------------------
# Change field entry older then $remove # days old.
#
my $remove = 14; # Number of days old.
my $date_field = 2; # Field Position of date field.

my $today = &date_to_unix(&get_date);
my $removeby = $today - ($remove * 86400);
my (@lines, @values);
open (DB, $db_file_name) or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 1); }
@lines = <DB>;
close DB;
open (DB, ">$db_file_name") or &cgierr ("Can't open: $db_file_name. Reason: $!");
if ($db_use_flock) { flock (DB, 2); }
foreach (@lines) {
next if /^#/;
next if /^\s*$/;
chomp;
@values = &split_decode ($_);
%rec = &array_to_hash(0,@values);
$date_in_db = &date_to_unix($rec{'date'});
if($date_in_db < $removeby){
$rec{'hilight'} = '';

if (-e "$SAVE_DIRECTORY/$data[$db_key_pos]") {
opendir (GRAPHIC, "$SAVE_DIRECTORY/$data[$db_key_pos]") or &cgierr("unable to open directory in delete records: $SAVE_DIRECTORY/$data[$db_key_pos]. Reason: $!");
@files = readdir(GRAPHIC);
closedir (GRAPHIC);
foreach $file (@files) {
unlink ("$SAVE_DIRECTORY/$data[$db_key_pos]/$file");
}
rmdir "$SAVE_DIRECTORY/$data[$db_key_pos]";
}


}
print DB &join_encode(%rec);
}
close DB;
}



If this would be easier with single upload mod than multi upload mod i will change to it.
Only thing with single upload mod is i would like to rename the files other than the ID field .... possible?

Thanks for your help so far


Quote Reply
Re: auto delete mod problems In reply to
I 've read your code but can not find any thing wrong. Please try again. You can change the file name when upload.


Quote Reply
Re: auto delete mod problems In reply to
nothing is deleted with the above code
i wish to delete the file plus make change the field
this possible?


with single upload you cannot keep the existing filename that you upload, it is changed to the ID
I dont want this, is it possible that it is renamed to a format of my choosing from fields within the database?
It also writes the file path into the database were the file was uploaded, can i get it to put yes like the multiupload mod and no if there isnt one

what i am trying to do is have 1 upload per record
when you login and the upload field is yes then you get sent to home
If the records get 14 days old the upload field is changed to no and the uploaded file is deleted
when you login and the upload field is no you are sent to modify record and forced to upload a file

Im trying to use the database as a reviews board

Hoping for help on this one

Quote Reply
Re: auto delete mod problems In reply to
Could you send me (dainguyen@gossamermail.com) all the files?
So we can have a closer look and figure out what happed.

Regards,

Mark

Quote Reply
Re: auto delete mod problems In reply to
what files do you need, all of em?
not sure if it can be sent in 1 email attatchment

Quote Reply
Re: auto delete mod problems In reply to
Please Zip all the file cgi and your config file and send to me.

Regards,

Mark