[aur-dev] [PATCH 2/3] Add function pkg_propose_deletion to web/lib/pkgfuncs.inc, which manages whether or not a package is currently proposed for deletion and emails the maintainer and aur-general when a deletion is proposed.
--- web/lib/pkgfuncs.inc | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 95 insertions(+), 0 deletions(-) diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index 5605daa..386662c 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -678,6 +678,101 @@ function pkg_flag ($atype, $ids, $action = True) { } /** + * Propose packages for deletion and cancel proposals + * + * @param string $atype Account type, output of account_from_sid + * @param array $ids Array of package IDs to propose / cancel proposals for + * @param boolean $action True proposes deletion, false cancels proposal. + * Proposes by default. + * + * @return string Translated success or error messages + */ +function pkg_propose_deletion ($atype, $ids, $action = True) { + if (!$atype) { + if ($action) { + return __("You must be logged in before you can propose packages for deletion."); + } else { + return __("You must be logged in before you can cancel deletion proposals."); + } + } + + if (empty($ids)) { + if ($action) { + return __("You did not select any packages to propose."); + } else { + return __("You did not select any packages to cancel proposals for."); + } + } + + foreach ($ids as $pid) { + if (!is_numeric($pid)) { + if ($action) { + return __("You did not select any packages to propose."); + } else { + return __("You did not select any packages to cancel proposals for."); + } + } + } + + $dbh = db_connect(); + + $first = 1; + foreach ($ids as $pid) { + if ($first) { + $first = 0; + $propose = $pid; + } else { + $propose .= ", " . $pid; + } + } + + $ood = $action ? 1 : 0; + $q = "UPDATE Packages SET DeletionProposed = " . $ood; + $q.= " WHERE ID IN (" . $propose . ")"; + + db_query($q, $dbh); + + if ($action) { + # Notify maintainer and aur-general of proposal by email + $f_name = username_from_sid($_COOKIE['AURSID']); + $f_email = email_from_sid($_COOKIE['AURSID']); + $f_uid = uid_from_sid($_COOKIE['AURSID']); + $q = "SELECT Packages.Name, Users.Email, Packages.ID "; + $q.= "FROM Packages, Users "; + $q.= "WHERE Packages.ID IN (" . $propose .") "; + $q.= "AND Users.ID = Packages.MaintainerUID "; + $q.= "AND Users.ID != " . $f_uid; + $result = db_query($q, $dbh); + if (mysql_num_rows($result)) { + while ($row = mysql_fetch_assoc($result)) { + # construct email - maintainer + $body = "Your package " . $row['Name'] . " has been proposed for deletion by " . $f_name . " [1]. You may view your package at:\nhttp://aur.archlinux.org/packages.php?ID=" . $row['ID'] . "\n\n[1] - http://aur.archlinux.org/account.php?Action=AccountInfo&ID=" . $f_uid; + $body = wordwrap($body, 70); + $headers = "Reply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR\n"; + @mail($row['Email'], "AUR Package Deletion Proposal for ".$row['Name'], $body, $headers); + + # construct email - aur-general + $body = "The AUR package " . $row['Name'] . " has been proposed for deletion by " . $f_name . " [1]. You may view the package at:\nhttp://aur.archlinux.org/packages.php?ID=" . $row['ID'] . "\n\n[1] - http://aur.archlinux.org/account.php?Action=AccountInfo&ID=" . $f_uid; + $body = wordwrap($body, 70); + $headers = "Reply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR\n"; + @mail('aur-general@archlinux.org', "AUR Package Deletion Proposal for ".$row['Name'], $body, $headers); + + } + } + } + + if ($action) { + return __("The selected packages have been proposed for deletion."); + } else { + return __("The deletion proposals have been cancelled for the selection packages."); + } +} + +/** * Delete packages * * @param string $atype Account type, output of account_from_sid -- 1.7.2.3
participants (1)
-
Peter Lewis