summaryrefslogtreecommitdiffstats
path: root/web/lib/aurjson.class.php
diff options
context:
space:
mode:
authorLukas Fleischer <archlinux@cryptocrack.de>2014-04-28 00:07:07 +0200
committerLukas Fleischer <archlinux@cryptocrack.de>2014-04-28 00:10:42 +0200
commiteb6cf1fad0558d381dbd8af2483410eecd50d7c2 (patch)
tree88d2d144ebbcc245017a5f9a87a4206443c0e9ef /web/lib/aurjson.class.php
parentb384f32fec78d221fe1dff949f17e98b8cb4272d (diff)
downloadaurweb-eb6cf1fad0558d381dbd8af2483410eecd50d7c2.tar.xz
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>
Diffstat (limited to 'web/lib/aurjson.class.php')
-rw-r--r--web/lib/aurjson.class.php53
1 files changed, 53 insertions, 0 deletions
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;