On Tue, Apr 12, 2011 at 01:05:28PM +0200, Tuxce wrote:
> >From d7d06859ddc9425930e586a0685f09f9798dfddc Mon Sep 17 00:00:00 2001
> From: tuxce <tuxce....@gmail.com>
> Date: Tue, 12 Apr 2011 12:42:30 +0200
> Subject: [PATCH] rpc: unify methods return.
> 
> Include maintainer in info and search method.

You should mention FS#17597 here. Just add something like "(fixes
FS#17597)" to the commit message.

> ---
>  web/lib/aurjson.class.php |   20 ++++++++------------
>  1 files changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
> index 57096d8..3283a92 100644
> --- a/web/lib/aurjson.class.php
> +++ b/web/lib/aurjson.class.php
> @@ -82,6 +82,11 @@ class AurJSON {
>      }
>  
>      private function process_query($type, $query) {
> +        $fields = implode(',', self::$fields);
> +        $query = "SELECT Users.Username as Maintainer, {$fields} " .
> +            " FROM Packages LEFT JOIN Users " .
> +            "        on Packages.MaintainerUID = Users.ID " .

Please strip leading whitespaces and use upper case for "ON".

> +            " WHERE ${query}";

We should probably think about renaming "$query" to something more
appropriate as we don't pass an entire MySQL query here anymore.

>          $result = db_query($query, $this->dbh);
>  
>          if ( $result && (mysql_num_rows($result) > 0) ) {
> @@ -140,13 +145,10 @@ class AurJSON {
>              return $this->json_error('Query arg too small');
>          }
>  
> -        $fields = implode(',', self::$fields);
>          $keyword_string = mysql_real_escape_string($keyword_string, 
> $this->dbh);
>          $keyword_string = addcslashes($keyword_string, '%_');
>  
> -        $query = "SELECT {$fields} " .
> -            " FROM Packages WHERE " .
> -            "  ( Name LIKE '%{$keyword_string}%' OR " .
> +        $query = "  ( Name LIKE '%{$keyword_string}%' OR " .
>              "    Description LIKE '%{$keyword_string}%' )";
>  
>          return $this->process_query('search', $query);
> @@ -158,7 +160,6 @@ class AurJSON {
>       * @return mixed Returns an array of value data containing the package 
> data
>       **/
>      private function info($pqdata) {
> -        $fields = implode(',', self::$fields);
>          $args = $this->parse_info_args($pqdata);
>          $ids = $args['ids'];
>          $names = $args['names'];
> @@ -167,8 +168,7 @@ class AurJSON {
>              return $this->json_error('Invalid query arguments');
>          }
>  
> -        $query = "SELECT {$fields} " .
> -            " FROM Packages WHERE ";
> +        $query = "";
>          if ($ids) {
>              $ids_value = implode(',', $args['ids']);
>              $query .= "ID IN ({$ids_value})";
> @@ -191,13 +191,9 @@ class AurJSON {
>       * @return mixed Returns an array of value data containing the package 
> data
>       **/
>      private function msearch($maintainer) {
> -        $fields = implode(',', self::$fields);
>          $maintainer = mysql_real_escape_string($maintainer, $this->dbh);
>  
> -        $query = "SELECT Users.Username as Maintainer, {$fields} " .
> -            " FROM Packages, Users WHERE " .
> -            "   Packages.MaintainerUID = Users.ID AND " .
> -            "   Users.Username = '{$maintainer}'";
> +        $query = "   Users.Username = '{$maintainer}'";
>  
>          return $this->process_query('msearch', $query);
>      }
> -- 
> 1.7.4.4
> 

Apart from that, this one looks okay to me :)

Reply via email to