summaryrefslogtreecommitdiffstats
path: root/web/lib/aurjson.class.php
diff options
context:
space:
mode:
authorBaptiste Jonglez <git@bitsofnetworks.org>2018-01-31 20:54:14 +0100
committerLukas Fleischer <lfleischer@archlinux.org>2018-02-24 14:57:31 +0100
commit1ff409874eda74dfc8c875e9fc1d0d512127746e (patch)
treea7f7bc71a3fb1e2d59f72eb90a21128ed0e0bfa2 /web/lib/aurjson.class.php
parentf15c700ad2ed2f5512a5574ab29f85c4848039e4 (diff)
downloadaur-1ff409874eda74dfc8c875e9fc1d0d512127746e.tar.gz
aur-1ff409874eda74dfc8c875e9fc1d0d512127746e.tar.xz
RPC: Allow to search packages by "*depends" fields
It is now possible to search for packages that depend on a given package, for instance: /rpc/?v=5&type=search&by=depends&arg=ocaml It is similarly possible to match on "makedepends", "checkdepends" and "optdepends". Signed-off-by: Baptiste Jonglez <git@bitsofnetworks.org> Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'web/lib/aurjson.class.php')
-rw-r--r--web/lib/aurjson.class.php21
1 files changed, 19 insertions, 2 deletions
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index b4cced04..c51e9c26 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -17,7 +17,11 @@ class AurJSON {
'suggest-pkgbase', 'get-comment-form'
);
private static $exposed_fields = array(
- 'name', 'name-desc', 'maintainer'
+ 'name', 'name-desc', 'maintainer',
+ 'depends', 'makedepends', 'checkdepends', 'optdepends'
+ );
+ private static $exposed_depfields = array(
+ 'depends', 'makedepends', 'checkdepends', 'optdepends'
);
private static $fields_v1 = array(
'Packages.ID', 'Packages.Name',
@@ -329,7 +333,7 @@ class AurJSON {
/*
* Retrieve package information (used in info, multiinfo, search and
- * msearch requests).
+ * depends requests).
*
* @param $type The request type.
* @param $where_condition An SQL WHERE-condition to filter packages.
@@ -493,6 +497,19 @@ class AurJSON {
$keyword_string = $this->dbh->quote($keyword_string);
$where_condition = "Users.Username = $keyword_string ";
}
+ } else if (in_array($search_by, self::$exposed_depfields)) {
+ if (empty($keyword_string)) {
+ return $this->json_error('Query arg is empty.');
+ } else {
+ $keyword_string = $this->dbh->quote($keyword_string);
+ $search_by = $this->dbh->quote($search_by);
+ $subquery = "SELECT PackageDepends.DepName FROM PackageDepends ";
+ $subquery .= "LEFT JOIN DependencyTypes ";
+ $subquery .= "ON PackageDepends.DepTypeID = DependencyTypes.ID ";
+ $subquery .= "WHERE PackageDepends.PackageID = Packages.ID ";
+ $subquery .= "AND DependencyTypes.Name = $search_by";
+ $where_condition = "$keyword_string IN ($subquery)";
+ }
}
return $this->process_query('search', $where_condition);