From patchwork Thu Oct 25 19:44:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Panteleev X-Patchwork-Id: 823 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id D89D77D430D2 for ; Thu, 25 Oct 2018 19:45:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on apollo X-Spam-Level: X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00=-1, MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3 autolearn=ham autolearn_force=no version=3.4.2 X-Spam-BL-Results: [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Thu, 25 Oct 2018 19:45:44 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id E4783E62D19C0; Thu, 25 Oct 2018 19:45:43 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS; Thu, 25 Oct 2018 19:45:43 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 8DA4028898; Thu, 25 Oct 2018 19:45:43 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=none Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 5570A28884 for ; Thu, 25 Oct 2018 19:45:39 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by luna.archlinux.org (Postfix) with ESMTPS for ; Thu, 25 Oct 2018 19:45:39 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id AA953E62D19B8 for ; Thu, 25 Oct 2018 19:45:33 +0000 (UTC) Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS for ; Thu, 25 Oct 2018 19:45:33 +0000 (UTC) Received: by mail-wm1-f68.google.com with SMTP id 143-v6so2685925wmf.1 for ; Thu, 25 Oct 2018 12:45:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VhtmK0GHWiAxSzjX3/sMFYSQgZfZLmyKbG1PbWkLIbE=; b=fmRvjGUnnMHKWZjGB/mJ2nG+Hr4MrcelC/RcGfEElJZDqSM2P868ikW8r+CK1UK+fm I+3svwgKVz527UxhKYvx+8HVMwKGK5qYSTezTm7IW5MmVqoTsPvDO5WAIBMBGZOU5h0a BpIU9nUcaMJ7ZYB4LAcy004MYdT7azCQs9u1ZUvITrtg3elMcvkqaXu3s2A599ujGHJk uP5jiGRWp/Ug4fCcFZsh5Nwuc0NYQpAfb5xwm6dPrcma5NVNh6DGahdj2Vck950aQO4y OA00/IUFCfSOgGSSxXlFBwEUUoeww4vhuH2dSguNymkfn/Kwfqd6isLOimdUeUJqxLVT 2KNA== X-Gm-Message-State: AGRZ1gLqOYgjVSSpB1itEqfpe05Q5GpPXgU29nZENBB64EB44MEbjCe7 SbznR3m2NWxQYTjA2I6m4NdzaVDY X-Google-Smtp-Source: AJdET5fIB/rBv6/DiTSMIR2bTbyzqzzvoRyQKVEWLl4eIbYvU1qzKPmufYWen3wNjWZqQoawWfJudw== X-Received: by 2002:a1c:1183:: with SMTP id 125-v6mr3164419wmr.103.1540496732697; Thu, 25 Oct 2018 12:45:32 -0700 (PDT) Received: from home.thecybershadow.net ([89.28.117.31]) by smtp.gmail.com with ESMTPSA id 2-v6sm9246163wro.96.2018.10.25.12.45.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Oct 2018 12:45:31 -0700 (PDT) From: Vladimir Panteleev To: aur-dev@archlinux.org, Guillaume Benoit Subject: [PATCH] aurjson: Allow searching package relations Date: Thu, 25 Oct 2018 19:44:46 +0000 Message-Id: <20181025194446.13278-1-archlinux@thecybershadow.net> X-Mailer: git-send-email 2.19.1 In-Reply-To: <1bdf2270-c7da-255e-bef3-c4786e01dd65@manjaro.org> References: <1bdf2270-c7da-255e-bef3-c4786e01dd65@manjaro.org> MIME-Version: 1.0 X-BeenThere: aur-dev@archlinux.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Arch User Repository \(AUR\) Development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: aur-dev-bounces@archlinux.org Sender: "aur-dev" --- On Thu, Oct 25, 2018 at 3:26 PM Guillaume Benoit 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(-) 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);