[aur-dev] [PATCH 1/2] Remove legacy code
In 74edb6f (Use Git repositories to store packages, 2014-06-06), package creation was moved to the Python backend. Remove several PHP functions that are no longer needed. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/lib/pkgfuncs.inc.php | 189 ----------------------------------------------- 1 file changed, 189 deletions(-) diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index b00b22d..d3cad12 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -516,23 +516,6 @@ function pkg_name_from_id($pkgids) { } /** - * Determine if a package name is on the database blacklist - * - * @param string $name The package name to check - * - * @return bool True if the name is blacklisted, otherwise false - */ -function pkg_name_is_blacklisted($name) { - $dbh = DB::connect(); - $q = "SELECT COUNT(*) FROM PackageBlacklist "; - $q.= "WHERE Name = " . $dbh->quote($name); - $result = $dbh->query($q); - - if (!$result) return false; - return ($result->fetchColumn() > 0); -} - -/** * Get the package details * * @param string $id The package ID to get description for @@ -913,178 +896,6 @@ function sanitize_ids($ids) { } /** - * Add package information to the database for a specific package - * - * @param int $base_id ID of the package base - * @param string $pkgname Name of the new package - * @param string $pkgver Version of the new package - * @param string $pkgdesc Description of the new package - * @param string $pkgurl Upstream URL for the new package - * - * @return int ID of the new package - */ -function pkg_create($base_id, $pkgname, $pkgver, $pkgdesc, $pkgurl) { - $dbh = DB::connect(); - $q = sprintf("INSERT INTO Packages (PackageBaseID, Name, Version, " . - "Description, URL) VALUES (%d, %s, %s, %s, %s)", - $base_id, $dbh->quote($pkgname), $dbh->quote($pkgver), - $dbh->quote($pkgdesc), $dbh->quote($pkgurl)); - $dbh->exec($q); - return $dbh->lastInsertId(); -} - -/** - * Add a dependency for a specific package to the database - * - * @param int $pkgid The package ID to add the dependency for - * @param string $type The type of dependency to add - * @param string $depname The name of the dependency to add - * @param string $depcondition The type of dependency for the package - * @param string $deparch The architecture of the dependency to add - * - * @return void - */ -function pkg_add_dep($pkgid, $type, $depname, $depcondition, $deparch) { - $dbh = DB::connect(); - $q = sprintf("INSERT INTO PackageDepends (PackageID, DepTypeID, DepName, DepCondition, DepArch) VALUES (%d, %d, %s, %s, %s)", - $pkgid, - pkg_dependency_type_id_from_name($type), - $dbh->quote($depname), - $dbh->quote($depcondition), - $deparch ? $dbh->quote($deparch) : 'NULL' - ); - $dbh->exec($q); -} - -/** - * Add a relation for a specific package to the database - * - * @param int $pkgid The package ID to add the relation for - * @param string $type The type of relation to add - * @param string $relname The name of the relation to add - * @param string $relcondition The version requirement of the relation - * @param string $relarch The architecture of the relation to add - * - * @return void - */ -function pkg_add_rel($pkgid, $type, $relname, $relcondition, $relarch) { - $dbh = DB::connect(); - $q = sprintf("INSERT INTO PackageRelations (PackageID, RelTypeID, RelName, RelCondition, RelArch) VALUES (%d, %d, %s, %s, %s)", - $pkgid, - pkg_relation_type_id_from_name($type), - $dbh->quote($relname), - $dbh->quote($relcondition), - $relarch ? $dbh->quote($relarch) : 'NULL' - ); - $dbh->exec($q); -} - -/** - * Add a source for a specific package to the database - * - * @param int $pkgid The package ID to add the source for - * @param string $pkgsrc The package source to add to the database - * @param string $srcarch The architecture of the source to add - * - * @return void - */ -function pkg_add_src($pkgid, $pkgsrc, $srcarch) { - $dbh = DB::connect(); - $q = sprintf("INSERT INTO PackageSources (PackageID, Source, SourceArch) VALUES (%d, %s, %s)", - $pkgid, - $dbh->quote($pkgsrc), - $srcarch ? $dbh->quote($srcarch) : 'NULL' - ); - $dbh->exec($q); -} - -/** - * Creates a new group and returns its ID - * - * If the groups already exists, the ID of the already existing group is - * returned. - * - * @param string $name The name of the group to create - * - * @return int The ID of the group - */ -function pkg_create_group($name) { - $dbh = DB::connect(); - $q = sprintf("SELECT ID FROM Groups WHERE Name = %s", $dbh->quote($name)); - $result = $dbh->query($q); - if ($result) { - $grpid = $result->fetch(PDO::FETCH_COLUMN, 0); - if ($grpid > 0) { - return $grpid; - } - } - - $q = sprintf("INSERT INTO Groups (Name) VALUES (%s)", $dbh->quote($name)); - $dbh->exec($q); - return $dbh->lastInsertId(); -} - -/** - * Add a package to a group - * - * @param int $pkgid The package ID of the package to add - * @param int $grpid The group ID of the group to add the package to - * - * @return void - */ -function pkg_add_grp($pkgid, $grpid) { - $dbh = DB::connect(); - $q = sprintf("INSERT INTO PackageGroups (PackageID, GroupID) VALUES (%d, %d)", - $pkgid, - $grpid - ); - $dbh->exec($q); -} - -/** - * Creates a new license and returns its ID - * - * If the license already exists, the ID of the already existing license is - * returned. - * - * @param string $name The name of the license to create - * - * @return int The ID of the license - */ -function pkg_create_license($name) { - $dbh = DB::connect(); - $q = sprintf("SELECT ID FROM Licenses WHERE Name = %s", $dbh->quote($name)); - $result = $dbh->query($q); - if ($result) { - $licid = $result->fetch(PDO::FETCH_COLUMN, 0); - if ($licid > 0) { - return $licid; - } - } - - $q = sprintf("INSERT INTO Licenses (Name) VALUES (%s)", $dbh->quote($name)); - $dbh->exec($q); - return $dbh->lastInsertId(); -} - -/** - * Add a license to a package - * - * @param int $pkgid The package ID of the package - * @param int $grpid The ID of the license to add - * - * @return void - */ -function pkg_add_lic($pkgid, $licid) { - $dbh = DB::connect(); - $q = sprintf("INSERT INTO PackageLicenses (PackageID, LicenseID) VALUES (%d, %d)", - $pkgid, - $licid - ); - $dbh->exec($q); -} - -/** * Determine package information for latest package * * @param int $numpkgs Number of packages to get information on -- 2.5.2
When requesting package details, instead of performing another SQL query to obtain the package name, extract the name from the result of the package details query. Also, drop pkg_name_from_id() which is no longer needed after this optimization. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- web/html/packages.php | 27 ++++++++++++++------------- web/lib/pkgfuncs.inc.php | 36 ------------------------------------ 2 files changed, 14 insertions(+), 49 deletions(-) diff --git a/web/html/packages.php b/web/html/packages.php index bf3daf8..38a2e29 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -11,19 +11,25 @@ check_sid(); # see if they're still logged in if (!isset($pkgid) || !isset($pkgname)) { if (isset($_GET['ID'])) { $pkgid = intval($_GET['ID']); - $pkgname = pkg_name_from_id($_GET['ID']); } else if (isset($_GET['N'])) { $pkgid = pkg_from_name($_GET['N']); - $pkgname = $_GET['N']; } else { - unset($pkgid, $pkgname); + unset($pkgid); } +} - if (isset($pkgid) && ($pkgid == 0 || $pkgid == NULL || $pkgname == NULL)) { - header("HTTP/1.0 404 Not Found"); - include "./404.php"; - return; - } +$details = array(); +if (isset($pkgid)) { + $details = pkg_get_details($pkgid); + $pkgname = $details['Name']; +} else { + unset($pkgname); +} + +if (isset($pkgid) && ($pkgid == 0 || $pkgid == NULL || $pkgname == NULL)) { + header("HTTP/1.0 404 Not Found"); + include "./404.php"; + return; } # Set the title to the current query or package name @@ -35,11 +41,6 @@ if (isset($pkgname)) { $title = __("Packages"); } -$details = array(); -if (isset($pkgname)) { - $details = pkg_get_details($pkgid); -} - html_header($title, $details); ?> diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index d3cad12..62bea65 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -480,42 +480,6 @@ function pkg_sources($pkgid) { } /** - * Determine package names from package IDs - * - * @param string|array $pkgids The package IDs to get names for - * - * @return array|string All names if multiple package IDs, otherwise package name - */ -function pkg_name_from_id($pkgids) { - if (is_array($pkgids)) { - $pkgids = sanitize_ids($pkgids); - $names = array(); - $dbh = DB::connect(); - $q = "SELECT Name FROM Packages WHERE ID IN ("; - $q.= implode(",", $pkgids) . ")"; - $result = $dbh->query($q); - if ($result) { - while ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $names[] = $row['Name']; - } - } - return $names; - } - elseif ($pkgids > 0) { - $dbh = DB::connect(); - $q = "SELECT Name FROM Packages WHERE ID = " . $pkgids; - $result = $dbh->query($q); - if ($result) { - $name = $result->fetch(PDO::FETCH_NUM); - } - return $name[0]; - } - else { - return NULL; - } -} - -/** * Get the package details * * @param string $id The package ID to get description for -- 2.5.2
participants (1)
-
Lukas Fleischer