[aur-dev] [PATCH 2/3] Add more fields to RPC info replies

Lukas Fleischer archlinux at cryptocrack.de
Sun Apr 27 18:27:00 EDT 2014


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 at cryptocrack.de>
---
 web/lib/aurjson.class.php | 53 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

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;
-- 
1.9.2



More information about the aur-dev mailing list