| INSTALLED
| REJECTED
-type request = { id : int, usr : int, node : int, data : string, msg : string, status : status, stamp : C.timestamp }
+type request = { id : int, usr : int, node : int, data : string, msg : string, status : status,
+ stamp : C.timestamp, cstamp : C.timestamp option }
val statusFromInt =
fn 0 => NEW
fun statusFromSql v = statusFromInt (C.intFromSql v)
fun statusToSql s = C.intToSql (statusToInt s)
-fun mkRow [id, usr, node, data, msg, status, stamp] =
+fun mkRow [id, usr, node, data, msg, status, stamp, cstamp] =
{id = C.intFromSql id, usr = C.intFromSql usr, node = C.intFromSql node,
data = C.stringFromSql data,
- msg = C.stringFromSql msg, status = statusFromSql status, stamp = C.timestampFromSql stamp}
+ msg = C.stringFromSql msg, status = statusFromSql status, stamp = C.timestampFromSql stamp,
+ cstamp = if C.isNull cstamp then NONE else SOME (C.timestampFromSql cstamp)}
| mkRow r = rowError ("APT request", r)
fun add {usr, node, data, msg} =
val db = getDb ()
val id = nextSeq (db, seq)
in
- C.dml db ($`INSERT INTO ^table (id, usr, node, data, msg, status, stamp)
+ C.dml db ($`INSERT INTO ^table (id, usr, node, data, msg, status, stamp, cstamp)
VALUES (^(C.intToSql id), ^(C.intToSql usr), ^(C.intToSql node), ^(C.stringToSql data), ^(C.stringToSql msg),
- 0, CURRENT_TIMESTAMP)`);
+ 0, CURRENT_TIMESTAMP, NULL)`);
id
end
let
val db = getDb ()
in
+ if #status req <> NEW then
+ ignore (C.dml db ($`UPDATE ^table SET cstamp = CURRENT_TIMESTAMP WHERE id = ^(C.intToSql (#id req))`))
+ else
+ ();
+
ignore (C.dml db ($`UPDATE ^table SET
usr = ^(C.intToSql (#usr req)), data = ^(C.stringToSql (#data req)),
node = ^(C.intToSql (#node req)),
ignore (C.dml (getDb ()) ($`DELETE FROM ^table WHERE id = ^(C.intToSql id)`))
fun lookup id =
- case C.oneOrNoRows (getDb ()) ($`SELECT id, usr, node, data, msg, status, stamp
+ case C.oneOrNoRows (getDb ()) ($`SELECT id, usr, node, data, msg, status, stamp, cstamp
FROM ^table
WHERE id = ^(C.intToSql id)`) of
SOME row => mkRow row
| mkRow' r = rowError ("Apt.request'", r)
fun list () =
- C.map (getDb ()) mkRow' ($`SELECT name, ^table.id, usr, node, data, msg, status, stamp
+ C.map (getDb ()) mkRow' ($`SELECT name, ^table.id, usr, node, data, msg, status, stamp, cstamp
FROM ^table JOIN WebUser ON usr = WebUser.id
ORDER BY stamp DESC`)
fun listOpen () =
- C.map (getDb ()) mkRow' ($`SELECT name, ^table.id, usr, node, data, msg, status, stamp
+ C.map (getDb ()) mkRow' ($`SELECT name, ^table.id, usr, node, data, msg, status, stamp, cstamp
FROM ^table JOIN WebUser ON usr = WebUser.id
WHERE status = 0
ORDER BY stamp DESC`)
| REJECTED => "Rejected"
fun notifyMod {old, new, changer, req} =
- notify (fn (_, mail) =>
+ if old = new then
+ notify (fn (_, mail) =>
(Mail.mwrite (mail, changer);
- Mail.mwrite (mail, " has changed the status of this request from ");
- Mail.mwrite (mail, statusToString old);
- Mail.mwrite (mail, " to ");
- Mail.mwrite (mail, statusToString new);
- Mail.mwrite (mail, ".\n\n"))) req
+ Mail.mwrite (mail, " has added a comment to this request.\n\n"))) req
+ else
+ notify (fn (_, mail) =>
+ (Mail.mwrite (mail, changer);
+ Mail.mwrite (mail, " has changed the status of this request from ");
+ Mail.mwrite (mail, statusToString old);
+ Mail.mwrite (mail, " to ");
+ Mail.mwrite (mail, statusToString new);
+ Mail.mwrite (mail, ".\n\n"))) req
end