Gossamer Forum
Home : Products : Links 2.0 : Customization :

Script to re-numerate the links.db field ID

Quote Reply
Script to re-numerate the links.db field ID
I have found that because of a problem with the linksid.txt file some records have the same ID.

Did anyone know how to give all records a unique number?


Dominique,
link-s@gmx.net
http://www.softds.ch/links/
Quote Reply
Re: Script to re-numerate the links.db field ID In reply to
Download the links.db file and import it into Excel (or some such program). Renumber there, save it as a text file, and upload. Remember to adjust the linksid.txt to reflect one more than the new last number.

Hope this helps. Smile
-Joyce
Quote Reply
Re: Script to re-numerate the links.db field ID In reply to
Or you can put the following script in your data directory as chg_id.pl. chmod the script to 755 and chmod the data directory to 777, and run the script:

Code:
#!/usr/bin/perl
# -------------------------------------------
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> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
$counter++;
@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;
# ---------------------------------------------

You will now have a new file, links_new.db, in your data directory. Check it over to be sure everything worked. Then rename your links.db file to links_org.db (just in case you need to restore it) and rename links_new.db to links.db. You should now have a completely renumbered links database. You will also have a linksid_new.txt in the data directory. You should rename linksid.txt to linksid_org.txt and then rename linksid_new.txt to linksid.txt.

After you are satisfied that all is well, you can delete the links_org.db and linksid_org.txt files.

By the way, I would ensure that you have no records in validate.db or modified.db before doing this.

I hope this helps.

[This message has been edited by Bobsie (edited May 27, 1999).]
Quote Reply
Re: Script to re-numerate the links.db field ID In reply to
Tanks a lot for the help.
Worked perfect.


Dominique
http://www.softds.ch/links/
Quote Reply
Re: Script to re-numerate the links.db field ID In reply to
Would Bobsie's script above work to add the numbering to an existing non-links db file that I want to import to links? At the moment I am figuring I may have to add the numbers by hand. I am on the Mac and do not own Excel, which is what many of you said you use for converting database files to links. I have BBedit, which has a search and replace function that I think I can use to add the required links fields, but I am not sure if there is an easy way to add numbering...
Just a point of info for a newbie, how do you run Bobsie's script? When he says run the script in the instructions, I am not sure how this is done.
Thanks,
-V

[This message has been edited by V Silly (edited October 14, 1999).]
Quote Reply
Re: Script to re-numerate the links.db field ID In reply to
Hi!

Is there any workaround for this program if I'm using remote ratings mod? People use their ID to rate their site remotely!

thnks!


Quote Reply
Re: Script to re-numerate the links.db field ID In reply to
I responded to your duplicate post.

Regards,

Eliot Lee

Quote Reply
Re: [Stealth] Script to re-numerate the links.db field ID In reply to
I tried running this script but got an internal server error (everything is cmod corectly so not sure why?)

So then I tried to just do it manually, but when I export from excel and save, it doesn't have the same format. What are the steps to export and get the same format as the .db file which is using | as its delimeter. Or, do I have to import into access and then export to get this format. I remember having to do that for something else awhile back.

Tawnya

Last edited by:

Tawnya: May 13, 2005, 11:11 AM