Store timestamp and user ID when closing requests

Message ID 20191123173133.11262-1-lfleischer@archlinux.org
State New
Headers show
Series
  • Store timestamp and user ID when closing requests
Related show

Commit Message

Lukas Fleischer Nov. 23, 2019, 5:31 p.m. UTC
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
---
 aurweb/git/serve.py         | 10 +++++++---
 schema/aur-schema.sql       |  5 ++++-
 test/t1200-git-serve.sh     |  4 ++--
 upgrading/4.9.0.txt         |  6 ++++++
 web/lib/pkgreqfuncs.inc.php |  2 ++
 5 files changed, 21 insertions(+), 6 deletions(-)
 create mode 100644 upgrading/4.9.0.txt

Patch

diff --git a/aurweb/git/serve.py b/aurweb/git/serve.py
index d43523c..64d51b9 100755
--- a/aurweb/git/serve.py
+++ b/aurweb/git/serve.py
@@ -207,18 +207,22 @@  def pkgreq_close(reqid, user, reason, comments, autoclose=False):
     conn = aurweb.db.Connection()
 
     if autoclose:
-        userid = 0
+        userid = None
     else:
         cur = conn.execute("SELECT ID FROM Users WHERE Username = ?", [user])
         userid = cur.fetchone()[0]
         if userid == 0:
             raise aurweb.exceptions.InvalidUserException(user)
 
-    conn.execute("UPDATE PackageRequests SET Status = ?, ClosureComment = ? " +
-                 "WHERE ID = ?", [status, comments, reqid])
+    now = int(time.time())
+    conn.execute("UPDATE PackageRequests SET Status = ?, ClosedTS = ?, " +
+                 "ClosedUID = ?, ClosureComment = ? " +
+                 "WHERE ID = ?", [status, now, userid, comments, reqid])
     conn.commit()
     conn.close()
 
+    if not userid:
+        userid = 0
     subprocess.Popen((notify_cmd, 'request-close', str(userid), str(reqid),
                       reason)).wait()
 
diff --git a/schema/aur-schema.sql b/schema/aur-schema.sql
index f05f40a..fa991ba 100644
--- a/schema/aur-schema.sql
+++ b/schema/aur-schema.sql
@@ -336,11 +336,14 @@  CREATE TABLE PackageRequests (
 	Comments TEXT NOT NULL,
 	ClosureComment TEXT NOT NULL,
 	RequestTS BIGINT UNSIGNED NOT NULL DEFAULT 0,
+	ClosedTS BIGINT UNSIGNED NULL DEFAULT NULL,
+	ClosedUID INTEGER UNSIGNED NULL DEFAULT NULL,
 	Status TINYINT UNSIGNED NOT NULL DEFAULT 0,
 	PRIMARY KEY (ID),
 	FOREIGN KEY (ReqTypeID) REFERENCES RequestTypes(ID) ON DELETE NO ACTION,
 	FOREIGN KEY (UsersID) REFERENCES Users(ID) ON DELETE SET NULL,
-	FOREIGN KEY (PackageBaseID) REFERENCES PackageBases(ID) ON DELETE SET NULL
+	FOREIGN KEY (PackageBaseID) REFERENCES PackageBases(ID) ON DELETE SET NULL,
+	FOREIGN KEY (ClosedUID) REFERENCES Users(ID) ON DELETE SET NULL
 ) ENGINE = InnoDB;
 CREATE INDEX RequestsUsersID ON PackageRequests (UsersID);
 CREATE INDEX RequestsPackageBaseID ON PackageRequests (PackageBaseID);
diff --git a/test/t1200-git-serve.sh b/test/t1200-git-serve.sh
index 473065f..e817b2c 100755
--- a/test/t1200-git-serve.sh
+++ b/test/t1200-git-serve.sh
@@ -381,9 +381,9 @@  test_expect_success "Check whether package requests are closed when disowning."
 	grep "^Subject.*PRQ" sendmail.out >sendmail.parts &&
 	test_cmp sendmail.parts expected &&
 	cat <<-EOD >expected &&
-	1|2|3|foobar||4||The user user disowned the package.|0|2
+	1|2||The user user disowned the package.
 	EOD
-	echo "SELECT * FROM PackageRequests WHERE Status = 2;" | sqlite3 aur.db >actual &&
+	echo "SELECT ID, Status, ClosedUID, ClosureComment FROM PackageRequests WHERE ClosedTS > 0;" | sqlite3 aur.db >actual &&
 	test_cmp actual expected
 '
 
diff --git a/upgrading/4.9.0.txt b/upgrading/4.9.0.txt
new file mode 100644
index 0000000..4c79283
--- /dev/null
+++ b/upgrading/4.9.0.txt
@@ -0,0 +1,6 @@ 
+1. Add new columns to store the timestamp and UID when closing requests:
+
+----
+ALTER TABLE PackageRequests ADD COLUMN ClosedTS BIGINT UNSIGNED NULL DEFAULT NULL;
+ALTER TABLE PackageRequests ADD COLUMN ClosedUID INTEGER UNSIGNED NULL DEFAULT NULL;
+----
diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php
index 079df38..7fce307 100644
--- a/web/lib/pkgreqfuncs.inc.php
+++ b/web/lib/pkgreqfuncs.inc.php
@@ -247,6 +247,8 @@  function pkgreq_close($id, $reason, $comments, $auto_close=false) {
 	}
 
 	$q = "UPDATE PackageRequests SET Status = " . intval($status) . ", ";
+	$q.= "ClosedTS = " . strval(time()) . ", ";
+	$q.= "ClosedUID = " . ($uid == 0 ? "NULL" : intval($uid)) . ", ";
 	$q.= "ClosureComment = " . $dbh->quote($comments) . " ";
 	$q.= "WHERE ID = " . intval($id);
 	$dbh->exec($q);