Gossamer Forum
Home : Products : DBMan : Customization :

External Text File

Quote Reply
External Text File
Hi,
I am using the external text file, it's a great way to save space in the database.

But I have 2 problems I need help with though.

When I login as admin to clean up the database, I deleted an entry created by admin. Instead of deleting that 1 entry it deleted all the associated text files.

Also sometimes the text file seems to disappear, the data is in the database but no associated file is there. The database will not load because it can not find the text file.

Any ideas?

Thanks

Sean

Quote Reply
Re: External Text File In reply to
In your db.cgi file sub delete_records make sure you have your code in the correct place and all your brackets.
In the database I'm using this in I have:

if ($delete_list{$data[$db_key_pos]}) {
$delete_list{$data[$db_key_pos]} = 0; # then mark it deleted and don't print it to the new database.
unlink "$counter_dir/$data[$db_key_pos]"; ## delete counter
unlink "$save_text_dir/$data[$db_key_pos].txt"; ## external text file mod
}
else {
$output .= $line . "\n"; # otherwise print it.
}
}

Let me know if that helps or perhaps you could post the urls to text copies of your files.

Was the database working fine before installing that mod?

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: External Text File In reply to
Lois,
thanks for getting back to me. here is a copy of my
sub delete_records. I have not noticed any problems before but a lot of time the issues don't come up until you get so far along. Hope this helps, if you need more info please let me know.

Thanks

Sean

sub delete_records {
# --------------------------------------------------------
# Deletes a single or multiple records. First the routine goes thrrough
# the form input and makes sure there are some records to delete. It then goes
# through the database deleting each entry and marking it deleted. If there
# are any keys not deleted, an error message will be returned saying which keys
# were not found and not deleted, otherwise the user will go to the success page.

my ($key, %delete_list, $rec_to_delete, @lines, $line, @data, $errstr, $succstr, $output, $restricted);
$rec_to_delete = 0;
foreach $key (keys %in) { # Build a hash of keys to delete.
if ($in{$key} eq "delete") {
$delete_list{$key} = 1;
$rec_to_delete = 1;
}
}
if (!$rec_to_delete) {
&html_delete_failure("no records specified.");
return;
}

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

($restricted = 1) if ($auth_modify_own and !$per_admin);

LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
@data = &split_decode($line);
($output .= "$line\n" and next LINE) if ($restricted and ($db_userid ne $data[$auth_user_field]));

if ($delete_list{$data[$db_key_pos]}) { # if this id is one we want to delete
$delete_list{$data[$db_key_pos]} = 0; # then mark it deleted and don't print it to the new database.
unlink "$save_text_dir/$data[$db_key_pos].txt";
}
else {
$output .= $line . "\n"; # otherwise print it.
}

# If you have already made changes to this portion of sub
# delete_records (such as with the file upload mod), after

$delete_list{$data[$db_key_pos]} = 0;

# add

unlink "$save_text_dir/$data[$db_key_pos].txt";
}

foreach $key (keys %delete_list) {
$delete_list{$key} ? # Check to see if any items weren't deleted
($errstr .= "$key,") : # that should have been.
($succstr .= "$key,"); # For logging, we'll remember the one's we deleted.
}
chop($succstr); # Remove trailing delimeter
chop($errstr); # Remove trailing delimeter

open (DB, ">$db_file_name") or &cgierr("error in delete_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

&auth_logging("deleted records: $succstr") if ($auth_logging);
$errstr ? # Do we have an error?
&html_delete_failure($errstr) : # If so, then let's report go to the failure page,
&html_delete_success($succstr); # else, everything went fine.
}