#!/usr/local/bin/perl use strict; use lib './'; use Links qw/$DB $IN $USER $CFG/; use Links::SiteHTML; use GT::Mail; use CGI::Carp qw(fatalsToBrowser); use Links::Plugins; use Links; use vars qw/$REC_CFG/; Links::init('./'); Links::init_user(); my $start_cat_id = 1234; my $end_cat_id = 2345; my $sth = $DB->table('CatLinks')->select( { CategoryID => $start_cat_id } ); while (my $hit = $sth->fetchrow_hashref) { # check if it already exists in $end_cat_id if ($DB->table('CatLinks')->count( { CategoryID => $end_cat_id, LinkID => $hit->{LinkID} } ) > 0) { # it already exists - so no need to add it # remove entry from OLD category, and dont bother re-adding it to the new category - as it already exists (and we would get a duplicate otherwise) $DB->table('CatLinks')->do_query(qq|DELETE FROM glinks_CatLinks WHERE CategoryID = $start_cat_id AND LinkID = $hit->{LinkID})|) || die $GT::SQL::error; print qq|Moved $hit->{LinkID} to new category... \n|; } else { # it doesn't exist in the new category, so lets add it. $DB->table('CatLinks')->do_query(qq|INSERT INTO glinks_CatLinks (CategoryID,LinkID) VALUES ($end_cat_id,$hit->{LinkID})|) || die $GT::SQL::error; # remove entry from OLD category $DB->table('CatLinks')->do_query(qq|DELETE FROM glinks_CatLinks WHERE CategoryID = $start_cat_id AND LinkID = $hit->{LinkID})|) || die $GT::SQL::error; print qq|Moved $hit->{LinkID} to new category, and removed from old one... \n|; } }