diff options
author | Lukas Fleischer <lfleischer@archlinux.org> | 2015-06-27 22:20:48 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@archlinux.org> | 2015-08-08 12:59:23 +0200 |
commit | 9746a654736cba12c234f3c1b3d7b67427678ce3 (patch) | |
tree | ebf6cc553c697bb065e2c4bced5c244744d461c2 /web/lib/pkgreqfuncs.inc.php | |
parent | d8142abbbee6a44693bd303838777fb93013b5c2 (diff) | |
download | aurweb-9746a654736cba12c234f3c1b3d7b67427678ce3.tar.xz |
Port notification routines to Python
Use a Python script for sending notification emails. The notification
action and additional parameters are passed via command line arguments.
For comment and package request notifications, the text is passed via
stdin.
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'web/lib/pkgreqfuncs.inc.php')
-rw-r--r-- | web/lib/pkgreqfuncs.inc.php | 115 |
1 files changed, 8 insertions, 107 deletions
diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php index c056d68..3ea4692 100644 --- a/web/lib/pkgreqfuncs.inc.php +++ b/web/lib/pkgreqfuncs.inc.php @@ -153,59 +153,12 @@ function pkgreq_file($ids, $type, $merge_into, $comments) { $dbh->exec($q); $request_id = $dbh->lastInsertId(); - /* - * Send e-mail notifications. - * TODO: Move notification logic to separate function where it belongs. - */ - $cc = array(pkgreq_get_creator_email($request_id)); - - $q = "SELECT Users.Email "; - $q.= "FROM Users INNER JOIN PackageBases "; - $q.= "ON PackageBases.MaintainerUID = Users.ID "; - $q.= "WHERE PackageBases.ID = " . $base_id; - $result = $dbh->query($q); - if ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $cc[] = $row['Email']; - } - - $q = "SELECT Name FROM PackageBases WHERE ID = " . $base_id; - $result = $dbh->query($q); - $row = $result->fetch(PDO::FETCH_ASSOC); - - /* - * TODO: Add native language emails for users, based on their - * preferences. Simply making these strings translatable won't - * work, users would be getting emails in the language that the - * user who posted the comment was in. - */ - $username = username_from_sid($_COOKIE['AURSID']); - if ($type == 'merge') { - $body = - $username . " [1] filed a request to merge " . - $row['Name'] . " [2] into " . $merge_into . - " [3]:\n\n" . $comments . "\n\n" . - "[1] " . get_user_uri($username, true) . "\n" . - "[2] " . get_pkgbase_uri($row['Name'], true) . "\n" . - "[3] " . get_pkgbase_uri($merge_into, true) . "\n"; - } else { - $body = - $username . " [1] filed a " . $type . " request for " . - $row['Name'] . " [2]:\n\n" . $comments . "\n\n" . - "[1] " . get_user_uri($username, true) . "\n" . - "[2] " . get_pkgbase_uri($row['Name'], true) . "\n"; + /* Send e-mail notifications. */ + $params = array('request-open', $uid, $request_id, $type, $base_id); + if ($type === 'merge') { + $params[] = $merge_into; } - $body = wordwrap($body, 70); - $cc = array_unique($cc); - $headers = "MIME-Version: 1.0\r\n" . - "Content-type: text/plain; charset=UTF-8\r\n" . - "Cc: " . implode(', ', $cc) . "\r\n"; - $thread_id = "<pkg-request-" . $request_id . "@aur.archlinux.org>"; - $headers .= "From: notify@aur.archlinux.org\r\n" . - "Message-ID: $thread_id\r\n" . - "X-Mailer: AUR"; - $ml = config_get('options', 'aur_request_ml'); - @mail($ml, "[PRQ#" . $request_id . "] " . ucfirst($type) . - " Request for " . $row['Name'], $body, $headers); + notify($params, $comments); $auto_orphan_age = config_get('options', 'auto_orphan_age'); $auto_delete_age = config_get('options', 'auto_delete_age'); @@ -268,6 +221,7 @@ function pkgreq_close($id, $reason, $comments, $auto_close=false) { $dbh = DB::connect(); $id = intval($id); + $uid = uid_from_sid($_COOKIE["AURSID"]); if (!$auto_close && !has_credential(CRED_PKGREQ_CLOSE)) { return array(false, __("Only TUs and developers can close requests.")); @@ -277,61 +231,8 @@ function pkgreq_close($id, $reason, $comments, $auto_close=false) { $q.= "WHERE ID = " . intval($id); $dbh->exec($q); - /* - * Send e-mail notifications. - * TODO: Move notification logic to separate function where it belongs. - */ - $cc = array(pkgreq_get_creator_email($id)); - - $q = "SELECT Users.Email "; - $q.= "FROM Users INNER JOIN PackageBases "; - $q.= "ON PackageBases.MaintainerUID = Users.ID "; - $q.= "INNER JOIN PackageRequests "; - $q.= "ON PackageRequests.PackageBaseID = PackageBases.ID "; - $q.= "WHERE PackageRequests.ID = " . $id; - $result = $dbh->query($q); - if ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $cc[] = $row['Email']; - } - - /* - * TODO: Add native language emails for users, based on their - * preferences. Simply making these strings translatable won't - * work, users would be getting emails in the language that the - * user who posted the comment was in. - */ - if ($auto_close) { - $body = "Request #" . intval($id) . " has been " . $reason . - " automatically by the Arch User Repository package " . - "request system"; - } else { - $username = username_from_sid($_COOKIE['AURSID']); - $body = "Request #" . intval($id) . " has been " . $reason . - " by " . $username . " [1]"; - } - if (!empty(trim($comments))) { - $body .= ":\n\n" . $comments . "\n"; - } else { - $body .= ".\n"; - } - if (!$auto_close) { - $body .= "\n"; - $body .= "[1] " . get_user_uri($username, true); - $body .= "\n"; - } - $body = wordwrap($body, 70); - $cc = array_unique($cc); - $headers = "MIME-Version: 1.0\r\n" . - "Content-type: text/plain; charset=UTF-8\r\n" . - "Cc: " . implode(', ', $cc) . "\r\n"; - $thread_id = "<pkg-request-" . $id . "@aur.archlinux.org>"; - $headers .= "From: notify@aur.archlinux.org\r\n" . - "In-Reply-To: $thread_id\r\n" . - "References: $thread_id\r\n" . - "X-Mailer: AUR"; - $ml = config_get('options', 'aur_request_ml'); - @mail($ml, "[PRQ#" . $id . "] Request " . ucfirst($reason), - $body, $headers); + /* Send e-mail notifications. */ + notify(array('request-close', $uid, $id, $reason), $comments); return array(true, __("Request closed successfully.")); } |