Add more fields to RPC info replies

This patch adds the following fields to info and multiinfo replies:

* Depends
* MakeDepends
* CheckDepends
* OptDepends
* Conflicts
* Provides
* Replaces
* Groups
* License

Each of these fields is an array.

Note that since collecting all these fields is CPU-intensive, they are
not included in replies to search queries.

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2014-04-28 00:07:07 +02:00
parent b384f32fec
commit eb6cf1fad0

View file

@ -118,6 +118,55 @@ class AurJSON {
return json_encode( array('type' => $type, 'resultcount' => $count, 'results' => $data) ); return json_encode( array('type' => $type, 'resultcount' => $count, 'results' => $data) );
} }
private function get_extended_fields($pkgid) {
$query = "SELECT DependencyTypes.Name AS Type, " .
"PackageDepends.DepName AS Name, " .
"PackageDepends.DepCondition AS Cond " .
"FROM PackageDepends " .
"LEFT JOIN DependencyTypes " .
"ON DependencyTypes.ID = PackageDepends.DepTypeID " .
"WHERE PackageDepends.PackageID = " . $pkgid . " " .
"UNION SELECT RelationTypes.Name AS Type, " .
"PackageRelations.RelName AS Name, " .
"PackageRelations.RelCondition AS Cond " .
"FROM PackageRelations " .
"LEFT JOIN RelationTypes " .
"ON RelationTypes.ID = PackageRelations.RelTypeID " .
"WHERE PackageRelations.PackageID = " . $pkgid . " " .
"UNION SELECT 'groups' AS Type, Groups.Name, '' AS Cond " .
"FROM Groups INNER JOIN PackageGroups " .
"ON PackageGroups.PackageID = " . $pkgid . " " .
"AND PackageGroups.GroupID = Groups.ID " .
"UNION SELECT 'license' AS Type, Licenses.Name, '' AS Cond " .
"FROM Licenses INNER JOIN PackageLicenses " .
"ON PackageLicenses.PackageID = " . $pkgid . " " .
"AND PackageLicenses.LicenseID = Licenses.ID";
$result = $this->dbh->query($query);
if (!$result) {
return null;
}
$type_map = array(
'depends' => 'Depends',
'makedepends' => 'MakeDepends',
'checkdepends' => 'CheckDepends',
'optdepends' => 'OptDepends',
'conflicts' => 'Conflicts',
'provides' => 'Provides',
'replaces' => 'Replaces',
'groups' => 'Groups',
'license' => 'License',
);
$data = array();
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$type = $type_map[$row['Type']];
$data[$type][] = $row['Name'] . $row['Cond'];
}
return $data;
}
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);
@ -144,6 +193,10 @@ class AurJSON {
$row[$field] = intval($row[$field]); $row[$field] = intval($row[$field]);
} }
if ($type == 'info' || $type == 'multiinfo') {
$row = array_merge($row, $this->get_extended_fields($row['ID']));
}
if ($type == 'info') { if ($type == 'info') {
$search_data = $row; $search_data = $row;
break; break;