summaryrefslogtreecommitdiffstats
path: root/web/lib
diff options
context:
space:
mode:
authorCallan Barrett <wizzomafizzo@gmail.com>2008-10-04 20:13:35 +0200
committerLoui Chang <louipc.ist@gmail.com>2008-10-28 01:40:37 +0100
commit5d4303d0b6afacb2b3a8731bdb9fdbd6c40f5c0e (patch)
treef25ed15b4c67bb66b6418b18fe73f684c0d083b0 /web/lib
parenta447281d4f5ce2071ebc81b375c70ae44231b046 (diff)
downloadaur-5d4303d0b6afacb2b3a8731bdb9fdbd6c40f5c0e.tar.gz
aur-5d4303d0b6afacb2b3a8731bdb9fdbd6c40f5c0e.tar.xz
Convert package adoption/disowning to a function
Signed-off-by: Callan Barrett <wizzomafizzo@gmail.com> Signed-off-by: Loui Chang <louipc.ist@gmail.com>
Diffstat (limited to 'web/lib')
-rw-r--r--web/lib/pkgfuncs.inc58
1 files changed, 58 insertions, 0 deletions
diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc
index c952b85d..415f3e71 100644
--- a/web/lib/pkgfuncs.inc
+++ b/web/lib/pkgfuncs.inc
@@ -1131,3 +1131,61 @@ function pkg_delete ($atype, $ids) {
return __("The selected packages have been deleted.");
}
+
+function pkg_adopt ($atype, $ids, $action = True) {
+ if (!$atype) {
+ if ($action) {
+ return __("You must be logged in before you can adopt packages.");
+ } else {
+ return __("You must be logged in before you can disown packages.");
+ }
+ }
+
+ if (empty($ids)) {
+ if ($action) {
+ return __("You did not select any packages to adopt.");
+ } else {
+ return __("You did not select any packages to disown.");
+ }
+ }
+
+ $dbh = db_connect();
+
+ $first = 1;
+ foreach ($ids as $pid => $v) {
+ if ($first) {
+ $first = 0;
+ $pkg = $pid;
+ } else {
+ $pkg .= ", ".$pid;
+ }
+ }
+
+ $field = "MaintainerUID";
+ $q = "UPDATE Packages ";
+
+ if ($action) {
+ $user = uid_from_sid($_COOKIE["AURSID"]);
+ } else {
+ $user = 0;
+ }
+
+ $q.= "SET $field = $user ";
+ $q.= "WHERE ID IN ($pkg) ";
+
+ if ($action && $atype == "User") {
+ # Regular users may only adopt orphan packages from unsupported
+ $q.= "AND $field = 0 ";
+ $q.= "AND LocationID = 2 ";
+ } else if ($atype == "User") {
+ $q.= "AND $field = " . uid_from_sid($_COOKIE["AURSID"]);
+ }
+
+ db_query($q, $dbh);
+
+ if ($action) {
+ return __("The selected packages have been adopted.");
+ } else {
+ return __("The selected packages have been disowned.");
+ }
+}