diff options
author | Dan McGee <dan@archlinux.org> | 2011-03-31 03:48:07 +0200 |
---|---|---|
committer | Lukas Fleischer <archlinux@cryptocrack.de> | 2011-04-03 22:59:31 +0200 |
commit | 1128489bd0e89694dd4d88ff69bab7c8d45d972a (patch) | |
tree | 52a47450b2dbbd80cd7e4a7b26b42a6a83c4dd88 | |
parent | a427bd72a7e3d2c74fbe66317c88e44df4b7bc3a (diff) | |
download | aur-1128489bd0e89694dd4d88ff69bab7c8d45d972a.tar.gz aur-1128489bd0e89694dd4d88ff69bab7c8d45d972a.tar.xz |
Submission process code refactor
We had a ton of duplicate code shared between the insert and update
cases. Do a refactor so we can pull this stuff out below the if/else
block and only need it there once, saving some headaches.
Signed-off-by: Dan McGee <dan@archlinux.org>
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
-rw-r--r-- | web/html/pkgsubmit.php | 96 |
1 files changed, 35 insertions, 61 deletions
diff --git a/web/html/pkgsubmit.php b/web/html/pkgsubmit.php index 05cc8666..131bf37a 100644 --- a/web/html/pkgsubmit.php +++ b/web/html/pkgsubmit.php @@ -303,11 +303,12 @@ if ($_COOKIE["AURSID"]): # This is an overwrite of an existing package, the database ID # needs to be preserved so that any votes are retained. However, # PackageDepends and PackageSources can be purged. + $packageID = $pdata["ID"]; # Flush out old data that will be replaced with new data - $q = "DELETE FROM PackageDepends WHERE PackageID = " . $pdata["ID"]; + $q = "DELETE FROM PackageDepends WHERE PackageID = " . $packageID; db_query($q, $dbh); - $q = "DELETE FROM PackageSources WHERE PackageID = " . $pdata["ID"]; + $q = "DELETE FROM PackageSources WHERE PackageID = " . $packageID; db_query($q, $dbh); # If the package was a dummy, undummy it @@ -315,7 +316,7 @@ if ($_COOKIE["AURSID"]): $q = sprintf( "UPDATE Packages SET DummyPkg = 0, SubmitterUID = %d, MaintainerUID = %d, SubmittedTS = UNIX_TIMESTAMP() WHERE ID = %d", $uid, $uid, - $pdata["ID"]); + $packageID); db_query($q, $dbh); } @@ -324,7 +325,7 @@ if ($_COOKIE["AURSID"]): if ($_POST['category'] > 1) { $q = sprintf( "UPDATE Packages SET CategoryID = %d WHERE ID = %d", mysql_real_escape_string($_REQUEST['category']), - $pdata["ID"]); + $packageID); db_query($q, $dbh); } @@ -338,41 +339,10 @@ if ($_COOKIE["AURSID"]): mysql_real_escape_string($new_pkgbuild['pkgdesc']), mysql_real_escape_string($new_pkgbuild['url']), uid_from_sid($_COOKIE["AURSID"]), - $pdata["ID"]); + $packageID); db_query($q, $dbh); - # Update package depends - $depends = explode(" ", $new_pkgbuild['depends']); - foreach ($depends as $dep) { - $q = "INSERT INTO PackageDepends (PackageID, DepPkgID, DepCondition) VALUES ("; - $deppkgname = preg_replace("/(<|<=|=|>=|>).*/", "", $dep); - $depcondition = str_replace($deppkgname, "", $dep); - - if ($deppkgname == "#") { - break; - } - - $deppkgid = create_dummy($deppkgname, $_COOKIE['AURSID']); - $q .= $pdata["ID"] . ", " . $deppkgid . ", '" . mysql_real_escape_string($depcondition) . "')"; - - db_query($q, $dbh); - } - - # Insert sources - $sources = explode(" ", $new_pkgbuild['source']); - foreach ($sources as $src) { - if ($src != "" ) { - $q = "INSERT INTO PackageSources (PackageID, Source) VALUES ("; - $q .= $pdata["ID"] . ", '" . mysql_real_escape_string($src) . "')"; - db_query($q, $dbh); - } - } - - if ($pdata["MaintainerUID"] === NULL) pkg_notify(account_from_sid($_COOKIE["AURSID"]), array($pdata["ID"])); - - header('Location: packages.php?ID=' . $pdata['ID']); - } else { $uid = uid_from_sid($_COOKIE["AURSID"]); @@ -388,41 +358,45 @@ if ($_COOKIE["AURSID"]): $uid, $uid); - $result = db_query($q, $dbh); + db_query($q, $dbh); $packageID = mysql_insert_id($dbh); - # Update package depends - $depends = explode(" ", $new_pkgbuild['depends']); - foreach ($depends as $dep) { - $q = "INSERT INTO PackageDepends (PackageID, DepPkgID, DepCondition) VALUES ("; - $deppkgname = preg_replace("/(<|<=|=|>=|>).*/", "", $dep); - $depcondition = str_replace($deppkgname, "", $dep); - - if ($deppkgname == "#") { - break; - } + } - $deppkgid = create_dummy($deppkgname, $_COOKIE['AURSID']); - $q .= $packageID . ", " . $deppkgid . ", '" . mysql_real_escape_string($depcondition) . "')"; + # Update package depends + $depends = explode(" ", $new_pkgbuild['depends']); + foreach ($depends as $dep) { + $q = "INSERT INTO PackageDepends (PackageID, DepPkgID, DepCondition) VALUES ("; + $deppkgname = preg_replace("/(<|<=|=|>=|>).*/", "", $dep); + $depcondition = str_replace($deppkgname, "", $dep); - db_query($q, $dbh); + if ($deppkgname == "#") { + break; } - # Insert sources - $sources = explode(" ", $new_pkgbuild['source']); - foreach ($sources as $src) { - if ($src != "" ) { - $q = "INSERT INTO PackageSources (PackageID, Source) VALUES ("; - $q .= $packageID . ", '" . mysql_real_escape_string($src) . "')"; - db_query($q, $dbh); - } - } + $deppkgid = create_dummy($deppkgname, $_COOKIE['AURSID']); + $q .= $packageID . ", " . $deppkgid . ", '" . mysql_real_escape_string($depcondition) . "')"; - pkg_notify(account_from_sid($_COOKIE["AURSID"]), array($packageID)); + db_query($q, $dbh); + } - header('Location: packages.php?ID=' . $packageID); + # Insert sources + $sources = explode(" ", $new_pkgbuild['source']); + foreach ($sources as $src) { + if ($src != "" ) { + $q = "INSERT INTO PackageSources (PackageID, Source) VALUES ("; + $q .= $packageID . ", '" . mysql_real_escape_string($src) . "')"; + db_query($q, $dbh); + } + } + # If we just created this package, or it was an orphan and we + # auto-adopted, add submitting user to the notification list. + if (!$pdata || $pdata["MaintainerUID"] === NULL) { + pkg_notify(account_from_sid($_COOKIE["AURSID"]), array($packageID)); } + + header('Location: packages.php?ID=' . $packageID); } chdir($cwd); |