diff --git a/adminer/elastic.php b/adminer/elastic.php new file mode 100644 index 00000000..ccfc5975 --- /dev/null +++ b/adminer/elastic.php @@ -0,0 +1,13 @@ +_conn->rootQuery($query, $data); if ($print) { - echo $adminer->selectQuery("$query: " . json_encode($data), $start, !$search); + echo adminer()->selectQuery("$query: " . json_encode($data), $start, !$search); } if (empty($search)) { return false; @@ -274,11 +272,9 @@ if (isset($_GET["elastic7"])) { } function connect() { - global $adminer; - $connection = new Min_DB; - list($server, $username, $password) = $adminer->credentials(); + list($server, $username, $password) = adminer()->credentials(); if ($password != "" && $connection->connect($server, $username, "")) { return lang('Database does not support password.'); } @@ -295,9 +291,7 @@ if (isset($_GET["elastic7"])) { } function logged_user() { - global $adminer; - - $credentials = $adminer->credentials(); + $credentials = adminer()->credentials(); return $credentials[1]; } @@ -323,9 +317,7 @@ if (isset($_GET["elastic7"])) { } function count_tables($databases) { - global $connection; - - $return = $connection->rootQuery('_aliases'); + $return = connection()->rootQuery('_aliases'); if (empty($return)) { return array( ELASTIC_DB_NAME => 0 @@ -338,9 +330,7 @@ if (isset($_GET["elastic7"])) { } function tables_list() { - global $connection; - - $aliases = $connection->rootQuery('_aliases'); + $aliases = connection()->rootQuery('_aliases'); if (empty($aliases)) { return array(); } @@ -359,10 +349,8 @@ if (isset($_GET["elastic7"])) { } function table_status($name = "", $fast = false) { - global $connection; - - $stats = $connection->rootQuery('_stats'); - $aliases = $connection->rootQuery('_aliases'); + $stats = connection()->rootQuery('_stats'); + $aliases = connection()->rootQuery('_aliases'); if (empty($stats) || empty($aliases)) { return array(); @@ -427,9 +415,7 @@ if (isset($_GET["elastic7"])) { } function error() { - global $connection; - - return h($connection->error); + return h(connection()->error); } function information_schema() { @@ -443,13 +429,11 @@ if (isset($_GET["elastic7"])) { } function fields($table) { - global $connection; - $mappings = array(); - $mapping = $connection->rootQuery("_mapping"); + $mapping = connection()->rootQuery("_mapping"); if (!isset($mapping[$table])) { - $aliases = $connection->rootQuery('_aliases'); + $aliases = connection()->rootQuery('_aliases'); foreach ($aliases as $index_name => $index) { foreach ($index["aliases"] as $alias_name => $alias) { @@ -530,9 +514,7 @@ if (isset($_GET["elastic7"])) { * @return mixed */ function create_database($db) { - global $connection; - - return $connection->rootQuery(urlencode($db), null, 'PUT'); + return connection()->rootQuery(urlencode($db), null, 'PUT'); } /** Remove index @@ -540,9 +522,7 @@ if (isset($_GET["elastic7"])) { * @return mixed */ function drop_databases($databases) { - global $connection; - - return $connection->rootQuery(urlencode(implode(',', $databases)), null, 'DELETE'); + return connection()->rootQuery(urlencode(implode(',', $databases)), null, 'DELETE'); } /** Alter type @@ -550,8 +530,6 @@ if (isset($_GET["elastic7"])) { * @return mixed */ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) { - global $connection; - $properties = array(); foreach ($fields as $f) { $field_name = trim($f[1][0]); @@ -565,7 +543,7 @@ if (isset($_GET["elastic7"])) { $properties = array('properties' => $properties); } - return $connection->query("_mapping/{$name}", $properties, 'PUT'); + return connection()->query("_mapping/{$name}", $properties, 'PUT'); } /** Drop types @@ -573,20 +551,16 @@ if (isset($_GET["elastic7"])) { * @return bool */ function drop_tables($tables) { - global $connection; - $return = true; foreach ($tables as $table) { //! convert to bulk api - $return = $return && $connection->query(urlencode($table), null, 'DELETE'); + $return = $return && connection()->query(urlencode($table), null, 'DELETE'); } return $return; } function last_id() { - global $connection; - - return $connection->last_id; + return connection()->last_id; } function driver_config() { diff --git a/adminer/drivers/elastic.inc.php b/plugins/drivers/elastic5.php similarity index 88% rename from adminer/drivers/elastic.inc.php rename to plugins/drivers/elastic5.php index fa25d45a..62283226 100644 --- a/adminer/drivers/elastic.inc.php +++ b/plugins/drivers/elastic5.php @@ -1,10 +1,10 @@ _conn->query($query, $data); if ($print) { - echo $adminer->selectQuery("$query: " . json_encode($data), $start, !$search); + echo adminer()->selectQuery("$query: " . json_encode($data), $start, !$search); } if (!$search) { return false; @@ -265,11 +263,9 @@ if (isset($_GET["elastic"])) { } function connect() { - global $adminer; - $connection = new Min_DB; - list($server, $username, $password) = $adminer->credentials(); + list($server, $username, $password) = adminer()->credentials(); if ($password != "" && $connection->connect($server, $username, "")) { return lang('Database does not support password.'); } @@ -286,17 +282,13 @@ if (isset($_GET["elastic"])) { } function logged_user() { - global $adminer; - - $credentials = $adminer->credentials(); + $credentials = adminer()->credentials(); return $credentials[1]; } function get_databases() { - global $connection; - - $return = $connection->rootQuery('_aliases'); + $return = connection()->rootQuery('_aliases'); if ($return) { $return = array_keys($return); sort($return, SORT_STRING); @@ -322,11 +314,9 @@ if (isset($_GET["elastic"])) { } function count_tables($databases) { - global $connection; - - $result = $connection->query('_stats'); - $return = array(); + + $result = connection()->query('_stats'); if ($result && $result['indices']) { $indices = $result['indices']; foreach ($indices as $indice => $stats) { @@ -339,24 +329,20 @@ if (isset($_GET["elastic"])) { } function tables_list() { - global $connection; - if (min_version(7)) { return array('_doc' => 'table'); } - $return = $connection->query('_mapping'); + $return = connection()->query('_mapping'); if ($return) { - $return = array_fill_keys(array_keys($return[$connection->_db]["mappings"]), 'table'); + $return = array_fill_keys(array_keys($return[connection()->_db]["mappings"]), 'table'); } return $return; } function table_status($name = "", $fast = false) { - global $connection; - - $search = $connection->query("_search", array( + $search = connection()->query("_search", array( "size" => 0, "aggregations" => array( "count_by_type" => array( @@ -389,9 +375,7 @@ if (isset($_GET["elastic"])) { } function error() { - global $connection; - - return h($connection->error); + return h(connection()->error); } function information_schema() { @@ -407,21 +391,19 @@ if (isset($_GET["elastic"])) { } function fields($table) { - global $connection; - $mappings = array(); if (min_version(7)) { - $result = $connection->query("_mapping"); + $result = connection()->query("_mapping"); if ($result) { - $mappings = $result[$connection->_db]['mappings']['properties']; + $mappings = $result[connection()->_db]['mappings']['properties']; } } else { - $result = $connection->query("$table/_mapping"); + $result = connection()->query("$table/_mapping"); if ($result) { $mappings = $result[$table]['properties']; if (!$mappings) { - $mappings = $result[$connection->_db]['mappings'][$table]['properties']; + $mappings = $result[connection()->_db]['mappings'][$table]['properties']; } } } @@ -490,9 +472,7 @@ if (isset($_GET["elastic"])) { * @return mixed */ function create_database($db) { - global $connection; - - return $connection->rootQuery(urlencode($db), null, 'PUT'); + return connection()->rootQuery(urlencode($db), null, 'PUT'); } /** Remove index @@ -500,9 +480,7 @@ if (isset($_GET["elastic"])) { * @return mixed */ function drop_databases($databases) { - global $connection; - - return $connection->rootQuery(urlencode(implode(',', $databases)), null, 'DELETE'); + return connection()->rootQuery(urlencode(implode(',', $databases)), null, 'DELETE'); } /** Alter type @@ -510,8 +488,6 @@ if (isset($_GET["elastic"])) { * @return mixed */ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) { - global $connection; - $properties = array(); foreach ($fields as $f) { $field_name = trim($f[1][0]); @@ -524,8 +500,7 @@ if (isset($_GET["elastic"])) { if (!empty($properties)) { $properties = array('properties' => $properties); } - - return $connection->query("_mapping/{$name}", $properties, 'PUT'); + return connection()->query("_mapping/{$name}", $properties, 'PUT'); } /** Drop types @@ -533,20 +508,16 @@ if (isset($_GET["elastic"])) { * @return bool */ function drop_tables($tables) { - global $connection; - $return = true; foreach ($tables as $table) { //! convert to bulk api - $return = $return && $connection->query(urlencode($table), null, 'DELETE'); + $return = $return && connection()->query(urlencode($table), null, 'DELETE'); } return $return; } function last_id() { - global $connection; - - return $connection->last_id; + return connection()->last_id; } function driver_config() {