Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

problem deleting Links using plugin

Quote Reply
problem deleting Links using plugin
Hi,

I'm having a problem deleting Links from the Links_Links table. The aim of this plugin is to delete Links that are older than 2 days. The plugin would be run via a cron job at a specific time. The code is as follows:

# ==================================================================
# Plugins::remove_links - Auto Generated Program Module
#
# Plugins::remove_links
# Author : Dean Browett
# Version : 0.1
# Updated : Fri Apr 12 14:28:21 2002
#
# ==================================================================
#

package Plugins::remove_links;
# ==================================================================

use strict;
use GT::Date qw/:all/;
use GT::Base;
use GT::Plugins qw/STOP CONTINUE/;
use Links qw/$CFG $IN $DB/;

# Inherit from base class for debug and error methods
@Plugins::remove_links::ISA = qw(GT::Base);

sub update_links {
# Your code begins here! Good Luck!
my $args = shift;


my $table = $DB->table('Links');

my $sth = $table->select ( ['ID','LinkOwner','Add_Date','Directory'] );

my $concerts = 'concerts';
my $courses = 'courses';
my $result;

my $cond1 = GT::SQL::Condition->new ('Directory','=',$concerts, 'Directory','=',$courses);
$cond1->bool('or');

while (my $row = $sth->fetchrow_hashref) {

my $cond2 = GT::SQL::Condition->new ('ID','=',$row->{ID}, $cond1 );

my $diff = GT::Date::date_diff(GT::Date::date_get_gm(),$row->{Add_Date});

if ($diff > 2) {
$result = $table->delete($cond2);
if (! (defined $result)) {
printf FYL "ERROR DELETING LINK: %d, %s\n", $row->{ID}, $row->{LinkOwner};
}
}

}
GT::Plugins->action ( CONTINUE );

return $args;

}
# Always end with a 1.
1;


The program always bombs out on line 179 of Links/Link.pm after what looks like a number of iterations:

$ret = $self->SUPER::delete ({ ID => $id }) if ($delete_link);



Can someone clear this up for me.

TIA

Dean
Quote Reply
Re: [wobbly] problem deleting Links using plugin In reply to
Hmm you don't really need a plugin for that, its just a matter of:

DELETE FROM prefix_Links WHERE Add_Date < (time - 172800)

You could do a simple script like:

Code:
#!/usr/bin/perl

use strict;
use Links qw/$DB/;
use lib '/path/to/admin';
use GT::SQL::Condition;

Links::init('/path/to/admin/');

my $cond = GT::SQL::Condition->new('Add_Date', '<', (time - 172800));
$DB->table('Links')->delete( $cond );

Your code seems to be doing other stuff so you'd need to add that in but I wouldn't do it as a plugin (IMO)

Last edited by:

Paul: Apr 16, 2002, 6:20 AM
Quote Reply
Re: [Paul] problem deleting Links using plugin In reply to
Although don't just do the SQL, or else it won't properly clean up the other tables.

Cheers,

Alex
--
Gossamer Threads Inc.