[aur-dev] [PATCH 1/2] Refactor pkgbase_set_comaintainers()
This makes the code slightly more efficient and allows for easily determining the users that were added/removed to the co-maintainer list. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/lib/pkgbasefuncs.inc.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index cb756f6..bb9d241 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -1023,7 +1023,7 @@ function pkgbase_set_comaintainers($base_id, $users) { $dbh = DB::connect(); - $uids = array(); + $uids_new = array(); foreach($users as $user) { $q = "SELECT ID FROM Users "; $q .= "WHERE UserName = " . $dbh->quote($user); @@ -1034,18 +1034,32 @@ function pkgbase_set_comaintainers($base_id, $users) { return array(false, __("Invalid user name: %s", $user)); } - $uids[] = $uid; + $uids_new[] = $uid; } - $q = sprintf("DELETE FROM PackageComaintainers WHERE PackageBaseID = %d", $base_id); - $dbh->exec($q); + $q = sprintf("SELECT UsersID FROM PackageComaintainers WHERE PackageBaseID = %d", $base_id); + $result = $dbh->query($q); + $uids_old = $result->fetchAll(PDO::FETCH_COLUMN, 0); + + $uids_add = array_diff($uids_new, $uids_old); + $uids_rem = array_diff($uids_old, $uids_new); $i = 1; - foreach ($uids as $uid) { - $q = sprintf("INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (%d, %d, %d)", $base_id, $uid, $i); + foreach ($uids_new as $uid) { + if (in_array($uid, $uids_add)) { + $q = sprintf("INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (%d, %d, %d)", $base_id, $uid, $i); + } else { + $q = sprintf("UPDATE PackageComaintainers SET Priority = %d WHERE PackageBaseID = %d AND UsersID = %d", $i, $base_id, $uid); + } + $dbh->exec($q); $i++; } + foreach ($uids_rem as $uid) { + $q = sprintf("DELETE FROM PackageComaintainers WHERE PackageBaseID = %d AND UsersID = %d", $base_id, $uid); + $dbh->exec($q); + } + return array(true, __("The package base co-maintainers have been updated.")); } -- 2.6.1
Implements FS#45590. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- scripts/notify.py | 31 +++++++++++++++++++++++++++++++ web/lib/pkgbasefuncs.inc.php | 2 ++ 2 files changed, 33 insertions(+) diff --git a/scripts/notify.py b/scripts/notify.py index ab65277..4832baf 100755 --- a/scripts/notify.py +++ b/scripts/notify.py @@ -65,6 +65,10 @@ def pkgbase_from_pkgreq(cur, reqid): [reqid]) return cur.fetchone()[0] +def get_user_email(cur, uid): + cur.execute('SELECT Email FROM Users WHERE ID = %s', [uid]) + return cur.fetchone()[0] + def get_maintainer_email(cur, pkgbase_id): cur.execute('SELECT Users.Email FROM Users ' + 'INNER JOIN PackageBases ' + @@ -157,6 +161,31 @@ def flag(cur, uid, pkgbase_id): send_notification(to, subject, body, refs) +def comaintainer_add(cur, pkgbase_id, uid): + pkgbase = pkgbase_from_id(cur, pkgbase_id) + to = [get_user_email(cur, uid)] + + pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/' + + subject = 'AUR Co-Maintainer Notification for %s' % (pkgbase) + body = 'You were added to the co-maintainer list of %s [1].' % (pkgbase) + refs = '[1] ' + pkgbase_uri + '\n' + + send_notification(to, subject, body, refs) + +def comaintainer_remove(cur, pkgbase_id, uid): + pkgbase = pkgbase_from_id(cur, pkgbase_id) + to = [get_user_email(cur, uid)] + + pkgbase_uri = aur_location + '/pkgbase/' + pkgbase + '/' + + subject = 'AUR Co-Maintainer Notification for %s' % (pkgbase) + body = 'You were removed from the co-maintainer list of %s [1].' % \ + (pkgbase) + refs = '[1] ' + pkgbase_uri + '\n' + + send_notification(to, subject, body, refs) + def delete(cur, uid, old_pkgbase_id, new_pkgbase_id=None): user = username_from_id(cur, uid) old_pkgbase = pkgbase_from_id(cur, old_pkgbase_id) @@ -246,6 +275,8 @@ if __name__ == '__main__': 'welcome': welcome, 'comment': comment, 'flag': flag, + 'comaintainer-add': comaintainer_add, + 'comaintainer-remove': comaintainer_remove, 'delete': delete, 'request-open': request_open, 'request-close': request_close, diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index bb9d241..aad9d14 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -1048,6 +1048,7 @@ function pkgbase_set_comaintainers($base_id, $users) { foreach ($uids_new as $uid) { if (in_array($uid, $uids_add)) { $q = sprintf("INSERT INTO PackageComaintainers (PackageBaseID, UsersID, Priority) VALUES (%d, %d, %d)", $base_id, $uid, $i); + notify(array('comaintainer-add', $base_id, $uid)); } else { $q = sprintf("UPDATE PackageComaintainers SET Priority = %d WHERE PackageBaseID = %d AND UsersID = %d", $i, $base_id, $uid); } @@ -1059,6 +1060,7 @@ function pkgbase_set_comaintainers($base_id, $users) { foreach ($uids_rem as $uid) { $q = sprintf("DELETE FROM PackageComaintainers WHERE PackageBaseID = %d AND UsersID = %d", $base_id, $uid); $dbh->exec($q); + notify(array('comaintainer-remove', $base_id, $uid)); } return array(true, __("The package base co-maintainers have been updated.")); -- 2.6.1
participants (1)
-
Lukas Fleischer