Commit 2422fb02 authored by Lukas Fleischer's avatar Lukas Fleischer
Browse files

Store timestamp and user ID when closing requests


Signed-off-by: Lukas Fleischer's avatarLukas Fleischer <lfleischer@archlinux.org>
parent 4b97789b
......@@ -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()
......
......@@ -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);
......
......@@ -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
'
......
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;
----
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment