Home : Products : Gossamer Links : Discussions :

Products: Gossamer Links: Discussions: Re: [hennagaijin] mass deletion of duplicate links: Edit Log

Here is the list of edits for this post
Re: [hennagaijin] mass deletion of duplicate links
I'm fairly sure you'd need a script.

Code:
my %data;
my $sth = $DB->table('Links','CatLinks')->select;
while (my ($rec) = $sth->fetchrow_hashref) {
$data{$rec->{Title}} = [];
push @{$data{$rec->{Title}}}, $rec->{CategoryID};
}

...what that will do is make a hash of all link titles and will store their category ids.

Then what you can do it remove any entries where there is only one category, as this means the link isn't a duplicate....

Code:
my %unique = map { $_ => $data{$_} } grep scalar @{$data{$_}} > 1, keys %data;

Then you can sort all values by category id and remove the lowest id which you want to keep....

Code:
foreach my $key (keys %data) {
shift @{$data{$key}};
@{$data{$key}} = sort @{$data{$key}};
}

...then go on to delete everything.

Code:
foreach my $key (keys %data) {
foreach my $ids (@{$data{$key}}) {
$DB->table('CatLinks')->delete({ CategoryID => $ids });
}
}

I've done that step by step so you can see. I may have it totally wrong but it's the best I can do at the moment Crazy

If you *do* try it - make sure you have a backup.

Last edited by:

Paul: Mar 18, 2003, 9:40 AM

Edit Log: