Hey all! 
Loui Chang pointed me here since I prepared a patch to get all packages from 
AUR via the rpc-Interface...
The reason why I need to get all packages is to build a list of available 
packages (which gets cached then...), the user can search in it then... (or 
just dig a bit in it...). This all is for the AUR-Intergration into Shaman2 
(you might probably already know the 1.x version which is in community...)...

Now the patch is attached, it's not tested at all and I don't have much 
knowledge of php/sql/json at all, so it's mostly a copy-over from the other 
methods...

Lukas
diff --git a/web/html/rpc.php b/web/html/rpc.php
index 033cba5..d58a487 100644
--- a/web/html/rpc.php
+++ b/web/html/rpc.php
@@ -19,6 +19,7 @@ if ( $_SERVER['REQUEST_METHOD'] == 'GET' ) {
         echo '<ul>';
         echo '<li>search</li>';
         echo '<li>info</li>';
+        echo '<li>all_packages</li>';
         echo '</ul><br />';
         echo 'Each method requires the following HTTP GET syntax:<br />';
         echo '&nbsp;&nbsp; type=<i>methodname</i>&arg=<i>data</i> <br /><br />';
diff --git a/web/lib/aurjson.class.php b/web/lib/aurjson.class.php
index 81c0831..c30eeef 100644
--- a/web/lib/aurjson.class.php
+++ b/web/lib/aurjson.class.php
@@ -21,7 +21,7 @@ if (!extension_loaded('json'))
  **/
 class AurJSON {
     private $dbh = false;
-    private $exposed_methods = array('search','info');
+    private $exposed_methods = array('search','info','all_packages');
     private $fields = array('ID','Name','Version','CategoryID','Description',
         'URL','URLPath','License','NumVotes','OutOfDate');
 
@@ -147,5 +147,28 @@ class AurJSON {
             return $this->json_error('No result found');
         }
     }
+
+    /**
+     * Returns all packages
+     */
+    private function all_packages() {
+        $query = "SELECT " . implode(',', $this->fields) .
+            " FROM Packages WHERE DummyPkg=0 ";
+
+        $result = db_query($query, $this->dbh);
+
+        if ( $result && (mysql_num_rows($result) > 0) ) {
+            $search_data = array();
+            while ( $row = mysql_fetch_assoc($result) ) {
+                array_push($search_data, $row);
+	    }
+
+            mysql_free_result($result);
+            return $this->json_results('all_packages', $search_data);
+        }
+        else {
+            return $this->json_error('No results found');
+        }
+    }
 }
 

Reply via email to