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;
# ---------------------------------------------