Gossamer Forum
Home : Products : Links 2.0 : Discussions :

Record numbers in links.db are repeating

Quote Reply
Record numbers in links.db are repeating
We recently had some troubles with hackers on our site, and I had to do some manual work on the links.db. Now when new records are added to the database, they are re-using numbers which already exist in the database. So for example, I have 2 records listed as number 1161.

Could someone let me know how to get links back on track with record numbers for new links added?

Thanks in advance.
Quote Reply
Re: Record numbers in links.db are repeating In reply to
Put this script in your admin/data directory. chmod it to 755 and chmod the directory to 777. Then run the script. It will renumber your database consecutively. The new database will be in the links_new.db file and there will also be a linksid_new.txt file created which will contain the highest number used.

Save your original links.db and linksid.txt file and then rename (mv) links_new.db to links.db and linksid_new.txt to linksid.txt. That should straighten things out.

I hope this helps.

Code:
#!/usr/bin/perl
# -------------------------------------------
# Change next line to full path to links.cfg if you have problems
require "../links.cfg";
require "$db_lib_path/db_utils.pl";
require "$db_lib_path/links.def";

$counter = 0;
$ENV{'REQUEST_METHOD'} and (print "Content-type: text/plain\n\n");
open (DB, "<$db_links_name")
or print "Unable to open links database 'links.db'. Reason: $!\n" and exit;
open (DBOUT, ">$db_script_path/data/links_new.db")
or print "Unable to open output database. Reason: $!\n" and exit;
LINE: while (<DB> )
{
$counter++;
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@rec = &split_decode($_);
$rec[$db_key] = $counter;
print DBOUT &join_encode(&array_to_hash(0, @rec));
}
close DB;
close DBOUT;
open (DBID, ">$db_script_path/data/linksid_new.txt")
or print "Unable to open linksid.txt. Reason: $!" and exit;
print DBID $counter;
close DBID;
# ---------------------------------------------
Quote Reply
Re: Record numbers in links.db are repeating In reply to
Thanks Bobsie.
I chose not to use your script as I have several websites which link directly to their rating page (which uses the record number I believe?) and I did not want them to find they were suddenly linking to another websites rating page.
So... I manually corrected the few which had been added incorrectly to links.db, then I changed the linksid.txt file to the next number for my database.
Worked like a dream. Thanks again - you are a great help.