[aur-dev] [PATCH 1/2] Merge user ids in CommentNotify
Fixes FS#27687. Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> --- web/lib/pkgbasefuncs.inc.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index c8c99eb..e255cb4 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -508,6 +508,24 @@ function pkgbase_delete ($base_ids, $merge_base_id, $via, $grant=false) { $q.= "WHERE PackageBaseID IN (" . implode(",", $base_ids) . ")"; $dbh->exec($q); + /* Merge comment notifications */ + $q = "SELECT UserID FROM CommentNotify "; + $q.= "WHERE PackageBaseID IN (" . implode(",", $base_ids) . ")"; + $result = $dbh->query($q); + + while ($uid = $result->fetchColumn(0)) { + /* Check if a user already gets notifications from $merge_base_id */ + $q = "SELECT COUNT(*) FROM CommentNotify WHERE "; + $q .= "UserID = $uid AND PackageBaseID = " . intval($merge_base_id); + + $result_notif = $dbh->query($q); + if ($result_notif->fetchColumn() == 0) { + $q = "INSERT INTO CommentNotify (PackageBaseID, UserID) VALUES ("; + $q.= intval($merge_base_id) . ", $uid)"; + $dbh->exec($q); + } + } + /* Merge votes */ foreach ($base_ids as $base_id) { $q = "UPDATE PackageVotes "; -- 2.4.3
Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> --- web/lib/pkgbasefuncs.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index e255cb4..0007164 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -461,7 +461,7 @@ function pkgbase_delete ($base_ids, $merge_base_id, $via, $grant=false) { $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."; + $body .= "You will no longer receive notifications about this package, but you will automatically receive notifications about \"$merge_base_name\"."; } else { $body .= username_from_sid($_COOKIE['AURSID']) . " deleted \"".$pkgbase_name."\".\n\n"; $body .= "You will no longer receive notifications about this package."; -- 2.4.3
On Wed, 17 Jun 2015 at 02:08:19, Marcel Korpel wrote:
Fixes FS#27687.
Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> --- web/lib/pkgbasefuncs.inc.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index c8c99eb..e255cb4 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -508,6 +508,24 @@ function pkgbase_delete ($base_ids, $merge_base_id, $via, $grant=false) { $q.= "WHERE PackageBaseID IN (" . implode(",", $base_ids) . ")"; $dbh->exec($q);
+ /* Merge comment notifications */ + $q = "SELECT UserID FROM CommentNotify "; + $q.= "WHERE PackageBaseID IN (" . implode(",", $base_ids) . ")"; + $result = $dbh->query($q); + + while ($uid = $result->fetchColumn(0)) { + /* Check if a user already gets notifications from $merge_base_id */ + $q = "SELECT COUNT(*) FROM CommentNotify WHERE "; + $q .= "UserID = $uid AND PackageBaseID = " . intval($merge_base_id); + + $result_notif = $dbh->query($q); + if ($result_notif->fetchColumn() == 0) { + $q = "INSERT INTO CommentNotify (PackageBaseID, UserID) VALUES ("; + $q.= intval($merge_base_id) . ", $uid)"; + $dbh->exec($q); + } + } +
Looks good at a glance. Two things come into my mind, though: 1. We could greatly reduce the number of SQL queries by using an approach similar to what we do in the AUR blacklist updater. Fetch the lists of notified users for both packages, compute the set difference, then only insert the remaining users. This applies to many other parts of the AUR code base, too. 2. Since it won't make it into 4.0.0 anyway, might this be a good candidate for being ported to Python? All the package actions (disown, delete, merge) could be implemented in a Python script that returns an exit code and prints error messages to stderr. We could invoke that script from PHP code and fetch the exit status, as well as the error message quite easily. When that works fine, it would be easy to add a command to our SSH interface that even allows for performing package actions via the command line. Opinions?
/* Merge votes */ foreach ($base_ids as $base_id) { $q = "UPDATE PackageVotes "; -- 2.4.3
participants (2)
-
Lukas Fleischer
-
Marcel Korpel