diff options
Diffstat (limited to 'web/lib/pkgbasefuncs.inc.php')
-rw-r--r-- | web/lib/pkgbasefuncs.inc.php | 87 |
1 files changed, 56 insertions, 31 deletions
diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index 708f861f..5741b019 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -915,55 +915,80 @@ function pkgbase_change_category($base_id) { } /** - * Add package base information to the database + * Change the category a package base belongs to * - * @param string $name Name of the new package base - * @param int $category_id Category for the new package base - * @param int $uid User ID of the package uploader + * @param int $base_id The package base ID to change the category for + * @param int $category_id The new category ID for the package * - * @return int ID of the new package base + * @return void */ -function pkgbase_create($name, $category_id, $uid) { +function pkgbase_update_category($base_id, $category_id) { $dbh = DB::connect(); - $q = sprintf("INSERT INTO PackageBases (Name, CategoryID, " . - "SubmittedTS, ModifiedTS, SubmitterUID, MaintainerUID, " . - "PackagerUID) VALUES (%s, %d, UNIX_TIMESTAMP(), " . - "UNIX_TIMESTAMP(), %d, %d, %d)", - $dbh->quote($name), $category_id, $uid, $uid, $uid); + $q = sprintf("UPDATE PackageBases SET CategoryID = %d WHERE ID = %d", + $category_id, $base_id); $dbh->exec($q); - return $dbh->lastInsertId(); } /** - * Update package base information for a specific package base + * Get a list of package base co-maintainers * - * @param string $name Name of the updated package base - * @param int $base_id The package base ID of the affected package - * @param int $uid User ID of the package uploader + * @param int $base_id The package base ID to retrieve the co-maintainers for * - * @return void + * @return array An array of co-maintainer user names */ -function pkgbase_update($base_id, $name, $uid) { +function pkgbase_get_comaintainers($base_id) { $dbh = DB::connect(); - $q = sprintf("UPDATE PackageBases SET " . - "Name = %s, ModifiedTS = UNIX_TIMESTAMP(), " . - "MaintainerUID = %d, PackagerUID = %d, OutOfDateTS = NULL " . - "WHERE ID = %d", - $dbh->quote($name), $uid, $uid, $base_id); - $dbh->exec($q); + $q = "SELECT UserName FROM PackageComaintainers "; + $q .= "INNER JOIN Users ON Users.ID = PackageComaintainers.UsersID "; + $q .= "WHERE PackageComaintainers.PackageBaseID = " . intval($base_id); + $result = $dbh->query($q); + + if ($result) { + return $result->fetchAll(PDO::FETCH_COLUMN, 0); + } else { + return array(); + } } /** - * Change the category a package base belongs to + * Update the list of co-maintainers of a package base * - * @param int $base_id The package base ID to change the category for - * @param int $category_id The new category ID for the package + * @param int $base_id The package base ID to update the co-maintainers of + * @param array $users Array of co-maintainer user names * - * @return void + * @return array Tuple of success/failure indicator and error message */ -function pkgbase_update_category($base_id, $category_id) { +function pkgbase_set_comaintainers($base_id, $users) { + if (!has_credential(CRED_PKGBASE_EDIT_COMAINTAINERS, array(pkgbase_maintainer_uid($base_id)))) { + return array(false, __("You are not allowed to manage co-maintainers of this package base.")); + } + + /* Remove empty and duplicate user names. */ + $users = array_unique(array_filter(array_map('trim', $users))); + $dbh = DB::connect(); - $q = sprintf("UPDATE PackageBases SET CategoryID = %d WHERE ID = %d", - $category_id, $base_id); + + $uids = array(); + foreach($users as $user) { + $q = "SELECT ID FROM Users "; + $q .= "WHERE UserName = " . $dbh->quote($user); + $result = $dbh->query($q); + $uid = $result->fetchColumn(0); + + if (!$uid) { + return array(false, __("Invalid user name: %s", $user)); + } + + $uids[] = $uid; + } + + $q = sprintf("DELETE FROM PackageComaintainers WHERE PackageBaseID = %d", $base_id); $dbh->exec($q); + + foreach ($uids as $uid) { + $q = sprintf("INSERT INTO PackageComaintainers (PackageBaseID, UsersID) VALUES (%d, %d)", $base_id, $uid); + $dbh->exec($q); + } + + return array(true, __("The package base co-maintainers have been updated.")); } |