New Makefile for automatic updates
[infodrom.org/www.zeitungsliste.de] / bin / zeitungen-tidy
index 51f98f3..aed6ae3 100755 (executable)
@@ -28,7 +28,7 @@ my $dbh = DBI->connect('dbi:Pg:dbname=zlist') or die "Can't connect to database\
 
 sub tidy_online
 {
-    my $query = q{SELECT uid FROM online WHERE activity < now() - interval'12 hours'};
+    my $query = q{SELECT uid FROM online WHERE activity < now() - interval'48 hours'};
 
     my $sth = $dbh->prepare ($query) or die "Can't prepare Query: $DBI::errstr\n";
     my $rv = $sth->execute or die "Can't execute query: $DBI::errstr\n";
@@ -43,6 +43,23 @@ sub tidy_online
     }
 }
 
+sub tidy_activation
+{
+    my $query = q{SELECT uid,id FROM activation WHERE register_date < now() - interval'35 days'};
+
+    my $sth = $dbh->prepare ($query) or die "Can't prepare Query: $DBI::errstr\n";
+    my $rv = $sth->execute or die "Can't execute query: $DBI::errstr\n";
+
+    my @uids = ();
+    push @uids, $_->{uid} while ($_ = $sth->fetchrow_hashref);
+
+    if ($#uids > -1) {
+       $query = sprintf('DELETE FROM users WHERE id in (%s)',
+                        join(',', @uids));
+       $dbh->do($query);
+    }
+}
+
 sub archive_topics
 {
     my $query = q{SELECT id FROM topics WHERE archived IS false AND modified < now() - interval'2 weeks'};
@@ -80,3 +97,4 @@ sub tidy_tags
 tidy_online;
 archive_topics;
 # tidy_tags;
+tidy_activation;