Gossamer Forum
Home : Products : Links 2.0 : Customization :

Need info on a delete MOD for Links 2.0

Quote Reply
Need info on a delete MOD for Links 2.0
Hi all,
It's my 1st time posting here :)

I am using the links 2.0 and have seen the posts for the MOD to delete dead sites, 404 302 500.. etc..
I have someone that made one for me but after deleting about 30-50 sites, every window that shows whether the site has been deleted, they shows 0 sites have been deleted. Then I look in my FTP to my site and instead of the links.db file showing 1400KB it shows something like 512KB. ThankG__ I have everything backed up :)

Has anyone created one that does not crash?
Thanks in advance for any help!

oh PS::
Some the file I have is NOT my own I more than likely can not share it.
Sorry in advance too.

Last edited by:

MistressR: Apr 26, 2006, 2:18 PM
Quote Reply
Re: [MistressR] Need info on a delete MOD for Links 2.0 In reply to
Welcome!

Nedd more details:
- What so you mean "crash"?
- Are the links being deleted? Since your db is smaller, something was removed...
- Are you deleting therough the admin? Or from a Links-built page?
- Hard to help when we can't see the code...


Leonard
aka PerlFlunkie
Quote Reply
Re: [PerlFlunkie] Need info on a delete MOD for Links 2.0 In reply to
Hi!
The script that was written compiles the links.db, from that, a new file is created with the click of a link called delete.db. My tech added delete buttons. When that is clicked, a new window opens as if it was being deleted thru the admin. This is basically what it look like to bring up the delete.db

Checked 121 - Request Failed (302). Message: Found, but data resides under different URL (add a /).

BUTTON IS HERE

URL: http://www.sitename.net

I can delete aprox 50 sites with the script the way this tech wrote it. After that cetain amt. of deletions, instead of "this site was sucessfully deleted", the message is:
Check which records you wish to delete and then press "Delete ":
Your search returned 0 matches.

Error: no matching records.

Then I check my .db file and the file size is next to nothing. The links were removed. Here is an example of sizes
starting size of db - 2054KB, after the errors are received -535KB.

thanks again!
Quote Reply
Re: [PerlFlunkie] Need info on a delete MOD for Links 2.0 In reply to
I talked my tech into letting me post his adjustments to the script.

Instead of always reading the whole database (links.db),
set it to read only delete.db if called from the new admin link:
$db_file_name = './data/links.db';
63,72d56

my $db_delete_name;
if ($ENV{'QUERY_STRING'} =~ m/db=([a-z0-9\.]+)/) {
$db_file_name = "./data/$1";
} else {
$db_file_name = './data/links.db';
$db_delete_name = './data/delete.db';
}



Specify which status codes qualify a link to
be added to delete.db:
119,130d100

my %delete_status = (
-1, "Could not lookup server",
301, "Found, but moved",
302, "Found, but data resides under different URL (add a / ?)",
401, "Unauthorized",
403, "Forbidden",
404, "File Not found",
500, "Internal Error",
502, "Service temporarily overloaded"
);


If we're running the whole links.db, save files
which ought to be deleted into delete.db:
137,140d103
if ($db_delete_name) {
open(DELE, ">$db_delete_name") or die "could not open '$db_delete_name': $!";
}

167,171d123
if ( ($db_delete_name) && (exists $delete_status{$status}) ) {
print DELE $_, "\n";
$willdelete = 'DELETE';
}
Add the requested button to delete them directly.
This calls the same old delete function the same
way it was called before, just with fewer clicks:
173,186c125,127
if ( ($use_html) && ($db_file_name =~ m/delete\.db/) ) {
$willdelete = qq|
<form action="http://MYSITE.com/links/admin/admin.cgi" METHOD="POST" target="_blank">
<input type="hidden" name="$id" value="delete">
<INPUT TYPE="SUBMIT" name="delete_records" VALUE="Delete">
</form>
|;
}


Also display the word "DELETE" in red if it's being added to the delete list:
189,193c130,132
if ($use_html) {
print qq|<br /><br />Checked <a href="$url" target="_blank">$id</a> - Request Failed. ($status) Message: $error. <font color="red">$willdelete</font> URL: <a href="$url" target="_blank">$url<a/><br />\n|;
} else {
print qq|Checked $id - Request Failed. ($status) Message: $error. $willdelete URL: $url\n|;
}
---
$use_html ?
print qq|Checked <a href="$url" target="_blank">$id</a> - Request Failed. Message: $error. URL: $url\n| :
print qq|Checked $id - Request Failed. Message: $error. URL: $url\n|;


Just some house keeping closing delete.db:
200,204d138
close DELE if ($db_delete_name);


Return code -1 for a DNS error, rather than no error code at all:
246,254c180
);
unless ($sock) {
if ($@ =~ /Bad hostname/) {
return -1, $@;
} else {
return undef, $@;
}
}

---
) or return undef, $@;

This is the fully automatic delete routine which is NOT
being called in the current code:
265,307c191
}



sub remove_links {
# for efficiency and safety in case of IO error we'll read and write in place
my @delete_ids = @_;

my (@data, $total, $request, %seen, $status, $error, $url, $id);
open (DB, "+<$db_file_name") or &cgierr("error in verify_links. unable to open db file: $db_file_name. Reason: $!");
flock(DB,2);
my $oldh = select(DB);
$| = 1;
select($oldh);
seek(DB,0,0);
my $readpos;
my $writepos = 0;
while (<DB>) {
$readpos = tell(DB);
if ( (/^\s*$/) || (/^#/) ) {
seek(DB, $writepos, 0);
print DB $_;
$writepos = tell(DB);
next; # Skip comment lines and blank lines.
}
@data = &split_decode($_);
if ( ($data[$db_url] =~ /^http/) or ($data[$db_url] =~ /^ftp/) ) {
my $id = $data[$db_key_pos];
seek(DB, $writepos, 0);
print DB $_ unless ( grep(/^$id$/, @delete_ids) );
$writepos = tell(DB);
} else {
seek(DB, $writepos, 0);
print DB $_;
$writepos = tell(DB);
}
seek(DB, $readpos, 0);
}
truncate( DB, $writepos );
close DB;
}


---
}