diff mbox

aurjson: Allow searching package relations

Message ID 20181025194446.13278-1-archlinux@thecybershadow.net
State New
Headers show

Commit Message

Vladimir Panteleev Oct. 25, 2018, 7:44 p.m. UTC
---
On Thu, Oct 25, 2018 at 3:26 PM Guillaume Benoit <guillaume@manjaro.org> wrote:
> If you point me to the relevant code, I can try to provide a patch.

Not an aurweb developer, but since I looked at it recently and it was
fresh on my mind, here's a draft, only-cursorily-tested patch.

 web/lib/aurjson.class.php | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Comments

Lukas Fleischer Oct. 26, 2018, 4:48 a.m. UTC | #1
On Thu, 25 Oct 2018 at 21:44:46, Vladimir Panteleev wrote:
> ---
> On Thu, Oct 25, 2018 at 3:26 PM Guillaume Benoit <guillaume@manjaro.org> wrote:
> > If you point me to the relevant code, I can try to provide a patch.
> 
> Not an aurweb developer, but since I looked at it recently and it was
> fresh on my mind, here's a draft, only-cursorily-tested patch.

There is another patch [1] with a slightly different approach that still
needs to be reviewed and merged.

[1] https://lists.archlinux.org/pipermail/aur-dev/2018-June/004544.html
Guillaume Benoit Oct. 26, 2018, 12:28 p.m. UTC | #2
Le 26/10/2018 à 06:48, Lukas Fleischer a écrit :

> On Thu, 25 Oct 2018 at 21:44:46, Vladimir Panteleev wrote:
>> ---
>> On Thu, Oct 25, 2018 at 3:26 PM Guillaume Benoit <guillaume@manjaro.org> wrote:
>>> If you point me to the relevant code, I can try to provide a patch.
>> Not an aurweb developer, but since I looked at it recently and it was
>> fresh on my mind, here's a draft, only-cursorily-tested patch.
> There is another patch [1] with a slightly different approach that still
> needs to be reviewed and merged.
>
> [1] https://lists.archlinux.org/pipermail/aur-dev/2018-June/004544.html

The patch from Li-Yu Yu is more consequent than Vladimir Panteleev one but both seem fine.
diff mbox

Patch

diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index c51e9c2..5de6533 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -18,11 +18,15 @@  class AurJSON {
 	);
 	private static $exposed_fields = array(
 		'name', 'name-desc', 'maintainer',
-		'depends', 'makedepends', 'checkdepends', 'optdepends'
+		'depends', 'makedepends', 'checkdepends', 'optdepends',
+		'conflicts', 'provides', 'replaces'
 	);
 	private static $exposed_depfields = array(
 		'depends', 'makedepends', 'checkdepends', 'optdepends'
 	);
+	private static $exposed_relfields = array(
+		'conflicts', 'provides', 'replaces'
+	);
 	private static $fields_v1 = array(
 		'Packages.ID', 'Packages.Name',
 		'PackageBases.ID AS PackageBaseID',
@@ -510,6 +514,19 @@  class AurJSON {
 				$subquery .= "AND DependencyTypes.Name = $search_by";
 				$where_condition = "$keyword_string IN ($subquery)";
 			}
+		} else if (in_array($search_by, self::$exposed_relfields)) {
+			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 PackageRelations.RelName FROM PackageRelations ";
+				$subquery .= "LEFT JOIN RelationTypes ";
+				$subquery .= "ON PackageRelations.RelTypeID = RelationTypes.ID ";
+				$subquery .= "WHERE PackageRelations.PackageID = Packages.ID ";
+				$subquery .= "AND RelationTypes.Name = $search_by";
+				$where_condition = "$keyword_string IN ($subquery)";
+			}
 		}
 
 		return $this->process_query('search', $where_condition);