summaryrefslogtreecommitdiffstats
path: root/web/lib/pkgbasefuncs.inc.php
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2015-06-27 22:20:48 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2015-08-08 12:59:23 +0200
commit9746a654736cba12c234f3c1b3d7b67427678ce3 (patch)
treeebf6cc553c697bb065e2c4bced5c244744d461c2 /web/lib/pkgbasefuncs.inc.php
parentd8142abbbee6a44693bd303838777fb93013b5c2 (diff)
downloadaur-9746a654736cba12c234f3c1b3d7b67427678ce3.tar.gz
aur-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/pkgbasefuncs.inc.php')
-rw-r--r--web/lib/pkgbasefuncs.inc.php106
1 files changed, 10 insertions, 96 deletions
diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php
index 92202bf8..5d191ebf 100644
--- a/web/lib/pkgbasefuncs.inc.php
+++ b/web/lib/pkgbasefuncs.inc.php
@@ -97,37 +97,7 @@ function pkgbase_add_comment($base_id, $uid, $comment) {
$bcc = array();
if ($result) {
- while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
- array_push($bcc, $row['Email']);
- }
-
- $q = "SELECT Name FROM PackageBases WHERE ID = ";
- $q.= intval($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.
- */
- $body = 'from ' . get_pkgbase_uri($row['Name'], true) . "\n"
- . username_from_sid($_COOKIE['AURSID']) . " wrote:\n\n"
- . $comment
- . "\n\n---\nIf you no longer wish to receive notifications about this package, please go the the above package page and click the UnNotify button.";
- $body = wordwrap($body, 70);
- $bcc = implode(', ', $bcc);
- $thread_id = "<pkg-notifications-" . $row['Name'] . "@aur.archlinux.org>";
- $headers = "MIME-Version: 1.0\r\n" .
- "Content-type: text/plain; charset=UTF-8\r\n" .
- "Bcc: $bcc\r\n" .
- "Reply-to: noreply@aur.archlinux.org\r\n" .
- "From: notify@aur.archlinux.org\r\n" .
- "In-Reply-To: $thread_id\r\n" .
- "References: $thread_id\r\n" .
- "X-Mailer: AUR";
- @mail('undisclosed-recipients: ;', "AUR Comment for " . $row['Name'], $body, $headers);
+ notify(array('comment', $uid, $base_id), $comment);
}
}
@@ -355,33 +325,11 @@ function pkgbase_flag($base_ids) {
$q.= " OutOfDateTS = UNIX_TIMESTAMP()";
$q.= " WHERE ID IN (" . implode(",", $base_ids) . ")";
$q.= " AND OutOfDateTS IS NULL";
+ $dbh->exec($q);
- $affected_pkgs = $dbh->exec($q);
-
- if ($affected_pkgs > 0) {
- /* Notify of flagging by e-mail. */
- $f_name = username_from_sid($_COOKIE['AURSID']);
- $f_email = email_from_sid($_COOKIE['AURSID']);
- $f_uid = uid_from_sid($_COOKIE['AURSID']);
- $q = "SELECT PackageBases.Name, Users.Email ";
- $q.= "FROM PackageBases, Users ";
- $q.= "WHERE PackageBases.ID IN (" . implode(",", $base_ids) .") ";
- $q.= "AND Users.ID = PackageBases.MaintainerUID ";
- $q.= "AND Users.ID != " . $f_uid;
- $result = $dbh->query($q);
- if ($result) {
- while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
- $body = "Your package " . $row['Name'] . " has been flagged out of date by " . $f_name . " [1]. You may view your package at:\n" . get_pkgbase_uri($row['Name'], true) . "\n\n[1] - " . get_user_uri($f_name, true);
- $body = wordwrap($body, 70);
- $headers = "MIME-Version: 1.0\r\n" .
- "Content-type: text/plain; charset=UTF-8\r\n" .
- "Reply-to: noreply@aur.archlinux.org\r\n" .
- "From: notify@aur.archlinux.org\r\n" .
- "X-Mailer: PHP\r\n" .
- "X-MimeOLE: Produced By AUR";
- @mail($row['Email'], "AUR Out-of-date Notification for ".$row['Name'], $body, $headers);
- }
- }
+ $uid = uid_from_sid($_COOKIE['AURSID']);
+ foreach ($base_ids as $base_id) {
+ notify(array('flag', $uid, $base_id));
}
return array(true, __("The selected packages have been flagged out-of-date."));
@@ -449,46 +397,12 @@ function pkgbase_delete ($base_ids, $merge_base_id, $via, $grant=false) {
$merge_base_name = pkgbase_name_from_id($merge_base_id);
}
- /* Send e-mail notifications. */
+ $uid = uid_from_sid($_COOKIE['AURSID']);
foreach ($base_ids as $base_id) {
- $q = "SELECT CommentNotify.*, Users.Email ";
- $q.= "FROM CommentNotify, Users ";
- $q.= "WHERE Users.ID = CommentNotify.UserID ";
- $q.= "AND CommentNotify.UserID != " . uid_from_sid($_COOKIE['AURSID']) . " ";
- $q.= "AND CommentNotify.PackageBaseID = " . $base_id;
- $result = $dbh->query($q);
- $bcc = array();
-
- while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
- array_push($bcc, $row['Email']);
- }
- if (!empty($bcc)) {
- $pkgbase_name = pkgbase_name_from_id($base_id);
-
- /*
- * 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.
- */
- $body = "";
- if ($merge_base_id) {
- $body .= username_from_sid($_COOKIE['AURSID']) . " merged \"".$pkgbase_name."\" into \"$merge_base_name\".\n\n";
- $body .= "You will no longer receive notifications about this package, please go to https://aur.archlinux.org" . get_pkgbase_uri($merge_base_name) . " and click the Notify button if you wish to recieve them again.";
- } else {
- $body .= username_from_sid($_COOKIE['AURSID']) . " deleted \"".$pkgbase_name."\".\n\n";
- $body .= "You will no longer receive notifications about this package.";
- }
- $body = wordwrap($body, 70);
- $bcc = implode(', ', $bcc);
- $headers = "MIME-Version: 1.0\r\n" .
- "Content-type: text/plain; charset=UTF-8\r\n" .
- "Bcc: $bcc\r\n" .
- "Reply-to: noreply@aur.archlinux.org\r\n" .
- "From: notify@aur.archlinux.org\r\n" .
- "X-Mailer: AUR";
- @mail('undisclosed-recipients: ;', "AUR Package deleted: " . $pkgbase_name, $body, $headers);
+ if ($merge_base_id) {
+ notify(array('delete', $uid, $base_id, $merge_base_id));
+ } else {
+ notify(array('delete', $uid, $base_id));
}
}