Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Import AltCategories

Quote Reply
Import AltCategories
Add this code to your Import.pl file to automatically import the Alternate Categories data into Links SQL when importing your Links 2.0 database:

In the section:

# INSERT Links.

starting at approximately line 96 you'll see:

Code:
eval { $res = $db->add_record (\%values); };
$@ and print "Fatal: $@\n$.: @values\n" and next;
$res or print "Error: $Links: BSQL::error\n$.: @values\n" and next;

Right after the code above on about line 99 replace this:

}
close DB;

with this:

Code:
$ALT_CAT{$res} = $values{'AltCategories'};
}
close DB;

# INSERT Alternate Categories.
foreach $link_id (keys %ALT_CAT) {
@altcategories = split /\|/, $ALT_CAT{$link_id};
foreach $altcat (@altcategories) {
$altcat =~ tr/_/ /;
$altcat_id = $CAT_IDS{$altcat};
$altcat_id or print "Error: can't find category id for '$altcat'\n" and next;
$res = $db->do ("INSERT INTO CategoryAlternates VALUES ($altcat_id, $link_id)");
$res or print "Error inserting Alternate Category ($link_id) => $altcat\n";
}
}

All of your AltCategories from Links 2.0 will be imported into the CategoryAlternates table. The only problem you could have would be if your Alternate Categories field in Links 2.0 was called something other than 'AltCategories'. If that's the case just change 'AltCategories' in the first line of the replacement code to:
'thenameofthealternatecategoriesfieldinyourdatabase'

Brent
Quote Reply
Re: Import AltCategories In reply to
Hello Brent!

I missed reading this thread. Thats what I was wondering how to do this, but its there. Nice.

My question, any idea how to do the import via editor.cgi?

This Alex has mentioned in my thread as follows :

www.gossamer-threads.com/scripts/forum/resources/Forum9/HTML/000154.html

Alex tried to give a solution for normal categories import. Please note that few lines above the suggested code there is a bug which I beleive he should have included in the next distribution. Further, I wonder that if once the Alt_Cat gets converted in to their IDs,

How will I be able to get it out back to their Names?

Getting alone the Links Table after re importing the Category Table alone gets a new Auto_increment number and shall have no relation to the related links ID!!! I am very very confused.

So I beleive that if a links is exported, it should come out with its related Alt_Cat name in a seperate column and thereafter if imported back, it goes into the right place.

------------------
rajani











Quote Reply
Re: Import AltCategories In reply to
Hello!

Lets say,.........
#



if ($table eq '$Links') {
if ($record{'AltCatID'} !~ /^\d*$/) {
$record{'AltCatID'} = &get_category_id ($record{'AltCatID'});
$record{'LinkID'} = &get_category_id ($record{'LinkID'});
$res = $db->do ("INSERT INTO CategoryAlternates VALUES ($record{'AltCatID'}, $record{'LinksID'})");
$res or print "Error inserting Alternate Category ($link_id) => $altcat\n";

}
}

This ofcourse does not work.

------------------
rajani