mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Fix the RPC interface
* Fix the SQL query to conform to the new database layout. * Remove the license field from replies. The license field is now stored in a separate table and no longer returned on search queries. * Add a "PackageBase" field that contains the name of the package base of every package in the result. * Fix the source tarball URL. The URL is now built based on the package base name instead of the package name. Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
parent
dda19c8e01
commit
b384f32fec
1 changed files with 12 additions and 10 deletions
|
@ -18,8 +18,9 @@ class AurJSON {
|
||||||
'search', 'info', 'multiinfo', 'msearch', 'suggest'
|
'search', 'info', 'multiinfo', 'msearch', 'suggest'
|
||||||
);
|
);
|
||||||
private static $fields = array(
|
private static $fields = array(
|
||||||
'Packages.ID', 'Name', 'Version', 'CategoryID', 'Description', 'URL',
|
'Packages.ID', 'Packages.Name', 'PackageBases.Name AS PackageBase',
|
||||||
'License', 'NumVotes', 'OutOfDateTS AS OutOfDate',
|
'Version', 'CategoryID', 'Description', 'URL', 'NumVotes',
|
||||||
|
'OutOfDateTS AS OutOfDate', 'Users.UserName AS Maintainer',
|
||||||
'SubmittedTS AS FirstSubmitted', 'ModifiedTS AS LastModified'
|
'SubmittedTS AS FirstSubmitted', 'ModifiedTS AS LastModified'
|
||||||
);
|
);
|
||||||
private static $numeric_fields = array(
|
private static $numeric_fields = array(
|
||||||
|
@ -120,9 +121,10 @@ class AurJSON {
|
||||||
private function process_query($type, $where_condition) {
|
private function process_query($type, $where_condition) {
|
||||||
global $MAX_RPC_RESULTS;
|
global $MAX_RPC_RESULTS;
|
||||||
$fields = implode(',', self::$fields);
|
$fields = implode(',', self::$fields);
|
||||||
$query = "SELECT Users.Username as Maintainer, {$fields} " .
|
$query = "SELECT {$fields} " .
|
||||||
"FROM Packages LEFT JOIN Users " .
|
"FROM Packages LEFT JOIN PackageBases " .
|
||||||
"ON Packages.MaintainerUID = Users.ID " .
|
"ON PackageBases.ID = Packages.PackageBaseID " .
|
||||||
|
"LEFT JOIN Users ON PackageBases.MaintainerUID = Users.ID " .
|
||||||
"WHERE ${where_condition}";
|
"WHERE ${where_condition}";
|
||||||
$result = $this->dbh->query($query);
|
$result = $this->dbh->query($query);
|
||||||
|
|
||||||
|
@ -131,8 +133,8 @@ class AurJSON {
|
||||||
$search_data = array();
|
$search_data = array();
|
||||||
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
|
||||||
$resultcount++;
|
$resultcount++;
|
||||||
$name = $row['Name'];
|
$pkgbase_name = $row['PackageBase'];
|
||||||
$row['URLPath'] = URL_DIR . substr($name, 0, 2) . "/" . $name . "/" . $name . ".tar.gz";
|
$row['URLPath'] = URL_DIR . substr($pkgbase_name, 0, 2) . "/" . $pkgbase_name . "/" . $pkgbase_name . ".tar.gz";
|
||||||
|
|
||||||
/* Unfortunately, mysql_fetch_assoc() returns all fields as
|
/* Unfortunately, mysql_fetch_assoc() returns all fields as
|
||||||
* strings. We need to coerce numeric values into integers to
|
* strings. We need to coerce numeric values into integers to
|
||||||
|
@ -204,7 +206,7 @@ class AurJSON {
|
||||||
|
|
||||||
$keyword_string = $this->dbh->quote("%" . addcslashes($keyword_string, '%_') . "%");
|
$keyword_string = $this->dbh->quote("%" . addcslashes($keyword_string, '%_') . "%");
|
||||||
|
|
||||||
$where_condition = "(Name LIKE {$keyword_string} OR ";
|
$where_condition = "(Packages.Name LIKE {$keyword_string} OR ";
|
||||||
$where_condition.= "Description LIKE {$keyword_string}) ";
|
$where_condition.= "Description LIKE {$keyword_string}) ";
|
||||||
$where_condition.= "LIMIT {$MAX_RPC_RESULTS}";
|
$where_condition.= "LIMIT {$MAX_RPC_RESULTS}";
|
||||||
|
|
||||||
|
@ -224,7 +226,7 @@ class AurJSON {
|
||||||
$where_condition = "Packages.ID={$pqdata}";
|
$where_condition = "Packages.ID={$pqdata}";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$where_condition = sprintf("Name=%s", $this->dbh->quote($pqdata));
|
$where_condition = sprintf("Packages.Name=%s", $this->dbh->quote($pqdata));
|
||||||
}
|
}
|
||||||
return $this->process_query('info', $where_condition);
|
return $this->process_query('info', $where_condition);
|
||||||
}
|
}
|
||||||
|
@ -255,7 +257,7 @@ class AurJSON {
|
||||||
if ($names) {
|
if ($names) {
|
||||||
// individual names were quoted in parse_multiinfo_args()
|
// individual names were quoted in parse_multiinfo_args()
|
||||||
$names_value = implode(',', $args['names']);
|
$names_value = implode(',', $args['names']);
|
||||||
$where_condition .= "Name IN ({$names_value}) ";
|
$where_condition .= "Packages.Name IN ({$names_value}) ";
|
||||||
}
|
}
|
||||||
|
|
||||||
$where_condition .= "LIMIT {$MAX_RPC_RESULTS}";
|
$where_condition .= "LIMIT {$MAX_RPC_RESULTS}";
|
||||||
|
|
Loading…
Add table
Reference in a new issue