summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2015-10-17 12:13:22 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2015-10-17 17:33:07 +0200
commit2f6471b0b1c039e653a8787e5faeaa13dabb2e46 (patch)
tree8a5562e3d8fc181e14310006f0c94608d7ec29db /web
parentfd6ba76431c428679f964fef8f82912efad680f5 (diff)
downloadaur-2f6471b0b1c039e653a8787e5faeaa13dabb2e46.tar.gz
aur-2f6471b0b1c039e653a8787e5faeaa13dabb2e46.tar.xz
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>
Diffstat (limited to 'web')
-rw-r--r--web/lib/pkgbasefuncs.inc.php26
1 files changed, 20 insertions, 6 deletions
diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php
index cb756f61..bb9d2415 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."));
}