[aur-dev] [PATCH] rpc: unify methods return.
tuxce
tuxce.net at gmail.com
Tue Apr 12 11:40:41 EDT 2011
Include maintainer in info and search method.
Fixes FS#17597
---
web/lib/aurjson.class.php | 36 ++++++++++++++++--------------------
1 files changed, 16 insertions(+), 20 deletions(-)
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index 57096d8..b2d3ec0 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -81,7 +81,12 @@ class AurJSON {
return json_encode( array('type' => $type, 'results' => $data) );
}
- private function process_query($type, $query) {
+ private function process_query($type, $where_condition) {
+ $fields = implode(',', self::$fields);
+ $query = "SELECT Users.Username as Maintainer, {$fields} " .
+ "FROM Packages LEFT JOIN Users " .
+ "ON Packages.MaintainerUID = Users.ID " .
+ "WHERE ${where_condition}";
$result = db_query($query, $this->dbh);
if ( $result && (mysql_num_rows($result) > 0) ) {
@@ -140,16 +145,13 @@ 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 " .
- " Description LIKE '%{$keyword_string}%' )";
+ $where_condition = "( Name LIKE '%{$keyword_string}%' OR " .
+ "Description LIKE '%{$keyword_string}%' )";
- return $this->process_query('search', $query);
+ return $this->process_query('search', $where_condition);
}
/**
@@ -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,22 +168,21 @@ class AurJSON {
return $this->json_error('Invalid query arguments');
}
- $query = "SELECT {$fields} " .
- " FROM Packages WHERE ";
+ $where_condition = "";
if ($ids) {
$ids_value = implode(',', $args['ids']);
- $query .= "ID IN ({$ids_value})";
+ $where_condition .= "ID IN ({$ids_value})";
}
if ($ids && $names) {
- $query .= " OR ";
+ $where_condition .= " OR ";
}
if ($names) {
// individual names were quoted in parse_info_args()
$names_value = implode(',', $args['names']);
- $query .= "Name IN ({$names_value})";
+ $where_condition .= "Name IN ({$names_value})";
}
- return $this->process_query('info', $query);
+ return $this->process_query('info', $where_condition);
}
/**
@@ -191,15 +191,11 @@ 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}'";
+ $where_condition = "Users.Username = '{$maintainer}'";
- return $this->process_query('msearch', $query);
+ return $this->process_query('msearch', $where_condition);
}
}
--
1.7.4.4
More information about the aur-dev
mailing list