]> git.joonet.de Git - adminer.git/commitdiff
Elasticsearch: rootQuery() method for ES driver
authorTomas Lang <tomas.lang@gmail.com>
Sun, 12 Jan 2014 11:29:51 +0000 (12:29 +0100)
committerJakub Vrana <jakub@vrana.cz>
Mon, 13 Jan 2014 05:58:06 +0000 (21:58 -0800)
adminer/drivers/elastic.inc.php

index 72b4a0f29eec49e7b0f6855e3d3099a67325eb8b..f406ed3f9e6eb595363e29ba3ca4a70ab9c8ac58 100644 (file)
@@ -9,9 +9,15 @@ if (isset($_GET["elastic"])) {
                class Min_DB {
                        var $extension = "JSON", $server_info, $errno, $error, $_url;
 
-                       function query($path, $content = array(), $method = 'GET') {
+                       /** Performs query
+                        * @param string
+                        * @param array
+                        * @param string
+                        * @return mixed
+                        */
+                       function rootQuery($path, $content = array(), $method = 'GET') {
                                @ini_set('track_errors', 1); // @ - may be disabled
-                               $file = @file_get_contents($this->_url . ($this->_db != "" ? "$this->_db/" : "") . $path, false, stream_context_create(array('http' => array(
+                               $file = @file_get_contents($this->_url  . '/' . ltrim($path, '/'), false, stream_context_create(array('http' => array(
                                        'method' => $method,
                                        'content' => json_encode($content),
                                        'ignore_errors' => 1, // available since PHP 5.2.10
@@ -42,6 +48,16 @@ if (isset($_GET["elastic"])) {
                                return $return;
                        }
 
+                       /** Performs query relative to actual selected DB
+                        * @param string
+                        * @param array
+                        * @param string
+                        * @return mixed
+                        */
+                       function query($path, $content = array(), $method = 'GET') {
+                               return $this->rootQuery(($this->_db != "" ? "$this->_db/" : "/") . ltrim($path, '/'), $content, $method);
+                       }
+
                        function connect($server, $username, $password) {
                                $this->_url = "http://$username:$password@$server/";
                                $return = $this->query('');
@@ -174,7 +190,7 @@ if (isset($_GET["elastic"])) {
 
        function get_databases() {
                global $connection;
-               $return = $connection->query('_aliases');
+               $return = $connection->rootQuery('_aliases');
                if ($return) {
                        $return = array_keys($return);
                }
@@ -285,7 +301,7 @@ if (isset($_GET["elastic"])) {
        */
        function create_database($db) {
                global $connection;
-               return $connection->query(urlencode($db), array(), 'PUT');
+               return $connection->rootQuery(urlencode($db), array(), 'PUT');
        }
 
        /** Drop databases
@@ -294,7 +310,7 @@ if (isset($_GET["elastic"])) {
        */
        function drop_databases($databases) {
                global $connection;
-               return $connection->query(urlencode(implode(',', $databases)), array(), 'DELETE');
+               return $connection->rootQuery(urlencode(implode(',', $databases)), array(), 'DELETE');
        }
 
        /** Drop tables