3 # zeitungen-tidy - Daily Tidy run for www.zeitungsliste.de
4 # Copyright (c) 2008 Joey Schulze <joey@infodrom.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 my $dsn = 'dbi:Pg:dbname=zlist';
27 my $dbh = DBI->connect('dbi:Pg:dbname=zlist') or die "Can't connect to database\n";
31 my $query = q{SELECT uid FROM online WHERE activity < now() - interval'12 hours'};
33 my $sth = $dbh->prepare ($query) or die "Can't prepare Query: $DBI::errstr\n";
34 my $rv = $sth->execute or die "Can't execute query: $DBI::errstr\n";
37 push @uids, $_->{uid} while ($_ = $sth->fetchrow_hashref);
40 $query = sprintf('DELETE FROM online WHERE uid in (%s)',
48 my $query = q{SELECT uid,id FROM activation WHERE register_date < now() - interval'35 days'};
50 my $sth = $dbh->prepare ($query) or die "Can't prepare Query: $DBI::errstr\n";
51 my $rv = $sth->execute or die "Can't execute query: $DBI::errstr\n";
54 push @uids, $_->{uid} while ($_ = $sth->fetchrow_hashref);
57 $query = sprintf('DELETE FROM users WHERE id in (%s)',
65 my $query = q{SELECT id FROM topics WHERE archived IS false AND modified < now() - interval'2 weeks'};
67 my $sth = $dbh->prepare ($query) or die "Can't prepare Query: $DBI::errstr\n";
68 my $rv = $sth->execute or die "Can't execute query: $DBI::errstr\n";
71 push @ids, $_->{id} while ($_ = $sth->fetchrow_hashref);
74 $query = sprintf('UPDATE topics SET archived=true WHERE id in (%s)',
82 my $query = q{SELECT id FROM tags WHERE id NOT IN (SELECT DISTINCT tag FROM zeitung_tags)};
84 my $sth = $dbh->prepare ($query) or die "Can't prepare Query: $DBI::errstr\n";
85 my $rv = $sth->execute or die "Can't execute query: $DBI::errstr\n";
88 push @ids, $_->{id} while ($_ = $sth->fetchrow_hashref);
91 $query = sprintf('DELETE FROM SET tags WHERE id in (%s)',