From de2c01c711867eb764b295ca33e0b764ca1b4011 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 12 Sep 2013 13:25:13 -0500 Subject: bury a thread --- cgi-bin/bury | 39 +++++++++++++++++++++++++++++++++++++++ lib/db.pm | 26 ++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100755 cgi-bin/bury diff --git a/cgi-bin/bury b/cgi-bin/bury new file mode 100755 index 0000000..9aa43b8 --- /dev/null +++ b/cgi-bin/bury @@ -0,0 +1,39 @@ +#!/usr/bin/perl +######################################### +# not bless +######################################### + +use localbucky; + +$dbh = DBI->connect ($dsn); + +our ($USER, $lastlog) = checkin(); +logout() unless ($USER != -1); + +my $id = $input->{id}; +if (get_thread($id) == -1) + { error("no such thread"); } +my $changed_date = get_most_recent_change($id); +if ($changed_date > 0) { + print $id . "\n"; + print $changed_date . "\n"; + update_thread_lastmodified($id, $changed_date); +} +redirect("$BUCKY/index"); + +$dbh->disconnect (); + +sub get_most_recent_change { + my ($id) = @_; + my $files = get_recent_files($id); + my $comments_date = get_thread_comment_modified($id); + my $date = 0; + if ($files != -1) { + my $d = $files->[-1]->{'date'}; + $date = $d >= $date ? $d : $date; + } + if ($comments != -1) { + my $d = $comments_date; + $date = $d >= $date ? $d : $date; + } +} diff --git a/lib/db.pm b/lib/db.pm index 1faa3f4..aefdbe3 100644 --- a/lib/db.pm +++ b/lib/db.pm @@ -944,6 +944,24 @@ sub get_recent_files return \@rows; } +sub get_thread_comment_modified + { + my ($id) = @_; + my $query; + + $id = $dbh->quote($id); + $query = "SELECT MAX(date) FROM comments WHERE id=$id"; + + $sth = $dbh->prepare($query); + $sth->execute(); + my ($date) = $sth->fetchrow_array(); + $sth->finish(); + + if ($date == 0) + { return -1; } + + return $date; + } @@ -1684,6 +1702,14 @@ sub update_thread_size $rows = $dbh->do($query); } +sub update_thread_lastmodified + { + my ($id, $disp) = @_; + $id = $dbh->quote($id); + $disp = $dbh->quote($disp); + $query = "UPDATE threads SET lastmodified=$disp WHERE id=$id"; + $dbh->do($query); + } sub update_thread_display { my ($id, $disp) = @_; -- cgit v1.2.3-70-g09d2