issue: order by last update, changed on reply
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 20 Oct 2019 04:07:07 +0000 (06:07 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 9 Nov 2019 06:08:13 +0000 (07:08 +0100)
Initial value determined by:

UPDATE issues SET updated = greatest(created, closed, (
SELECT max(created) FROM comments WHERE page = issues.link
));

issue/index.php
widget/comments.sql
widget/reply.php

index d8f9c261e65b877764dafca34e28488dc2e9cfa4..2c50624f9a7fc1cbc7fae406ce4fb65f76eea1a6 100644 (file)
@@ -39,7 +39,7 @@ if ($_POST) {
                $_POST = [];
 }
 
-$query = $Db->query('SELECT * FROM issues ORDER BY created DESC');
+$query = $Db->query('SELECT * FROM issues ORDER BY updated DESC');
 
 ob_start();
 print '<ul>';
@@ -48,7 +48,7 @@ while ($row = $query->fetch()) {
                "/$Page/{$row->id}/{$row->link}",
                sprintf($row->closed ? '<strike>%s</strike>' : '%s',
                        htmlspecialchars($row->subject)),
-               showdate(array_slice(preg_split('/\D/', $row->created), 0, 3))
+               showdate(array_slice(preg_split('/\D/', $row->updated), 0, 3))
        );
        print "</li>\n";
 }
index 5e33716da32f7843e95e441c797e0ee36fb9543c..924c136e3a385d9d489d62f3cd92e155dedad69b 100644 (file)
@@ -5,6 +5,7 @@ CREATE TABLE issues (
        body       text,
        created    timestamptz          DEFAULT now(),
        closed     timestamptz          DEFAULT now(),
+       updated    timestamptz NOT NULL DEFAULT now(),
        author     text,
        id         serial      NOT NULL PRIMARY KEY
 );
index 2bc9014944c69e2388905385db548943d2a21472..abb364cc1354876b078a0c0a698fc91647b098df 100644 (file)
@@ -16,6 +16,12 @@ if ($_POST) {
                if (!$query->rowCount()) {
                        throw new Exception('Fout bij opslaan');
                }
+               if (@list ($cat, $issue) = explode('/', $Page) and ctype_digit($issue)) {
+                       $Db->query(
+                               'UPDATE issues SET updated = now() WHERE page = ? AND id = ?',
+                               [$cat, $issue]
+                       );
+               }
                $_POST['reply'] = NULL;
        }
        catch (Exception $e) {