Commit 01bfae82 authored by Lukas Fleischer's avatar Lukas Fleischer
Browse files

Make the type parameter of pkgreq_by_pkgbase() optional



This simplifies the code a bit, improves maintainability and reduces the
number of SQL queries when deleting a package.

Signed-off-by: Lukas Fleischer's avatarLukas Fleischer <lfleischer@archlinux.org>
parent c3614c4f
...@@ -513,10 +513,7 @@ function pkgbase_delete ($base_ids, $merge_base_id, $via, $grant=false) { ...@@ -513,10 +513,7 @@ function pkgbase_delete ($base_ids, $merge_base_id, $via, $grant=false) {
if (!$action) { if (!$action) {
$username = username_from_sid($_COOKIE['AURSID']); $username = username_from_sid($_COOKIE['AURSID']);
foreach ($base_ids as $base_id) { foreach ($base_ids as $base_id) {
$pkgreq_ids = array_merge( $pkgreq_ids = array_merge(pkgreq_by_pkgbase($base_id));
pkgreq_by_pkgbase($base_id, 'deletion'),
pkgreq_by_pkgbase($base_id, 'merge'),
pkgreq_by_pkgbase($base_id, 'orphan'));
foreach ($pkgreq_ids as $pkgreq_id) { foreach ($pkgreq_ids as $pkgreq_id) {
pkgreq_close(intval($pkgreq_id), 'accepted', pkgreq_close(intval($pkgreq_id), 'accepted',
'The user ' . $username . 'The user ' . $username .
......
...@@ -49,15 +49,18 @@ function pkgreq_list($offset, $limit) { ...@@ -49,15 +49,18 @@ function pkgreq_list($offset, $limit) {
* *
* @return array List of package request IDs * @return array List of package request IDs
*/ */
function pkgreq_by_pkgbase($baseid, $type) { function pkgreq_by_pkgbase($baseid, $type=false) {
$dbh = DB::connect(); $dbh = DB::connect();
$q = "SELECT PackageRequests.ID "; $q = "SELECT PackageRequests.ID ";
$q.= "FROM PackageRequests INNER JOIN RequestTypes ON "; $q.= "FROM PackageRequests INNER JOIN RequestTypes ON ";
$q.= "RequestTypes.ID = PackageRequests.ReqTypeID "; $q.= "RequestTypes.ID = PackageRequests.ReqTypeID ";
$q.= "WHERE PackageRequests.Status = 0 "; $q.= "WHERE PackageRequests.Status = 0 ";
$q.= "AND PackageRequests.PackageBaseID = " . intval($baseid) . " "; $q.= "AND PackageRequests.PackageBaseID = " . intval($baseid);
$q.= "AND RequestTypes.Name = " . $dbh->quote($type);
if ($type) {
$q .= " AND RequestTypes.Name = " . $dbh->quote($type);
}
return $dbh->query($q)->fetchAll(PDO::FETCH_COLUMN, 0); return $dbh->query($q)->fetchAll(PDO::FETCH_COLUMN, 0);
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment