diff options
author | Lukas Fleischer <archlinux@cryptocrack.de> | 2015-03-04 11:59:18 +0100 |
---|---|---|
committer | Lukas Fleischer <archlinux@cryptocrack.de> | 2015-03-04 12:20:21 +0100 |
commit | a53241a2f1fe4ecafd86a97738a04e2fbfbb0b84 (patch) | |
tree | d8c5e2d153e5c118a8401fbb5808acf27ed2570a /web/lib | |
parent | 5dca715c46669a2e1ed193c13aacff03e7e237ff (diff) | |
download | aurweb-a53241a2f1fe4ecafd86a97738a04e2fbfbb0b84.tar.xz |
Automatically close requests
Close requests automatically when a package is deleted or orphaned.
Implements FS#43799.
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Diffstat (limited to 'web/lib')
-rw-r--r-- | web/lib/pkgbasefuncs.inc.php | 31 | ||||
-rw-r--r-- | web/lib/pkgreqfuncs.inc.php | 21 |
2 files changed, 51 insertions, 1 deletions
diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index 6f9ef85..3f02bc7 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -509,6 +509,22 @@ function pkgbase_delete ($base_ids, $merge_base_id, $via, $grant=false) { pkgreq_close(intval($via), 'accepted', ''); } + /* Scan through pending deletion requests and close them. */ + if (!$action) { + $username = username_from_sid($_COOKIE['AURSID']); + foreach ($base_ids as $base_id) { + $pkgreq_ids = array_merge( + pkgreq_by_pkgbase($base_id, 'deletion'), + pkgreq_by_pkgbase($base_id, 'merge'), + pkgreq_by_pkgbase($base_id, 'orphan')); + foreach ($pkgreq_ids as $pkgreq_id) { + pkgreq_close(intval($pkgreq_id), 'accepted', + 'The user ' . $username . + ' deleted the package.', true); + } + } + } + if ($merge_base_id) { /* Merge comments */ $q = "UPDATE PackageComments "; @@ -555,6 +571,8 @@ function pkgbase_delete ($base_ids, $merge_base_id, $via, $grant=false) { * @return array Tuple of success/failure indicator and error message */ function pkgbase_adopt ($base_ids, $action=true, $via) { + $dbh = DB::connect(); + $uid = uid_from_sid($_COOKIE["AURSID"]); if (!$uid) { if ($action) { @@ -583,7 +601,18 @@ function pkgbase_adopt ($base_ids, $action=true, $via) { pkgreq_close(intval($via), 'accepted', ''); } - $dbh = DB::connect(); + /* Scan through pending orphan requests and close them. */ + if (!$action) { + $username = username_from_sid($_COOKIE['AURSID']); + foreach ($base_ids as $base_id) { + $pkgreq_ids = pkgreq_by_pkgbase($base_id, 'orphan'); + foreach ($pkgreq_ids as $pkgreq_id) { + pkgreq_close(intval($pkgreq_id), 'accepted', + 'The user ' . $username . + ' disowned the package.', true); + } + } + } $q = "UPDATE PackageBases "; if ($action) { diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php index 0fab447..e4c63b5 100644 --- a/web/lib/pkgreqfuncs.inc.php +++ b/web/lib/pkgreqfuncs.inc.php @@ -42,6 +42,27 @@ function pkgreq_list($offset, $limit) { } /** + * Get a list of all open package requests belonging to a certain package base + * + * @param int $baseid The package base ID to retrieve requests for + * @param int $type The type of requests to obtain + * + * @return array List of package request IDs + */ +function pkgreq_by_pkgbase($baseid, $type) { + $dbh = DB::connect(); + + $q = "SELECT PackageRequests.ID "; + $q.= "FROM PackageRequests INNER JOIN RequestTypes ON "; + $q.= "RequestTypes.ID = PackageRequests.ReqTypeID "; + $q.= "WHERE PackageRequests.Status = 0 "; + $q.= "AND PackageRequests.PackageBaseID = " . intval($baseid) . " "; + $q.= "AND RequestTypes.Name = " . $dbh->quote($type); + + return $dbh->query($q)->fetchAll(PDO::FETCH_COLUMN, 0); +} + +/** * Obtain the package base that belongs to a package request. * * @param int $id Package request ID to retrieve the package base for |