summaryrefslogtreecommitdiffstats
path: root/web/lib/pkgreqfuncs.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'web/lib/pkgreqfuncs.inc.php')
-rw-r--r--web/lib/pkgreqfuncs.inc.php115
1 files changed, 8 insertions, 107 deletions
diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php
index c056d681..3ea46926 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."));
}