From eb6cf1fad0558d381dbd8af2483410eecd50d7c2 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Mon, 28 Apr 2014 00:07:07 +0200 Subject: 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 --- web/lib/aurjson.class.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'web') diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php index 38cdd65..ab8ebbc 100644 --- a/web/lib/aurjson.class.php +++ b/web/lib/aurjson.class.php @@ -118,6 +118,55 @@ class AurJSON { 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) { global $MAX_RPC_RESULTS; $fields = implode(',', self::$fields); @@ -144,6 +193,10 @@ class AurJSON { $row[$field] = intval($row[$field]); } + if ($type == 'info' || $type == 'multiinfo') { + $row = array_merge($row, $this->get_extended_fields($row['ID'])); + } + if ($type == 'info') { $search_data = $row; break; -- cgit v1.2.3-54-g00ecf