Skip to content

Commit

Permalink
elastic7 driver as a plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpp committed Sep 18, 2021
1 parent 1e51869 commit c28db77
Showing 1 changed file with 29 additions and 55 deletions.
84 changes: 29 additions & 55 deletions adminer/drivers/elastic7.inc.php → plugins/drivers/elastic7.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
$drivers["elastic7"] = "Elasticsearch 7 (beta)";
add_driver("elastic7", "Elasticsearch 7 (beta)");

if (isset($_GET["elastic7"])) {
define("DRIVER", "elastic7");

if (function_exists('json_decode') && ini_bool('allow_url_fopen')) {
if (ini_bool('allow_url_fopen')) {
define("ELASTIC_DB_NAME", "elastic");

class Min_DB {
Expand Down Expand Up @@ -132,8 +132,6 @@ function fetch_row() {
class Min_Driver extends Min_SQL {

function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
global $adminer;

$data = array();
if ($select != array("*")) {
$data["fields"] = $select;
Expand Down Expand Up @@ -188,7 +186,7 @@ function select($table, $select, $where, $group, $order = array(), $limit = 1, $
$search = $this->_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;
Expand Down Expand Up @@ -275,11 +273,9 @@ function convertOperator($operator) {
}

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.');
}
Expand All @@ -296,9 +292,7 @@ function support($feature) {
}

function logged_user() {
global $adminer;

$credentials = $adminer->credentials();
$credentials = adminer()->credentials();

return $credentials[1];
}
Expand All @@ -324,9 +318,7 @@ function engines() {
}

function count_tables($databases) {
global $connection;

$return = $connection->rootQuery('_aliases');
$return = connection()->rootQuery('_aliases');
if (empty($return)) {
return array(
ELASTIC_DB_NAME => 0
Expand All @@ -339,9 +331,7 @@ function count_tables($databases) {
}

function tables_list() {
global $connection;

$aliases = $connection->rootQuery('_aliases');
$aliases = connection()->rootQuery('_aliases');
if (empty($aliases)) {
return array();
}
Expand All @@ -360,10 +350,8 @@ function tables_list() {
}

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();
Expand Down Expand Up @@ -428,9 +416,7 @@ function is_view($table_status) {
}

function error() {
global $connection;

return h($connection->error);
return h(connection()->error);
}

function information_schema() {
Expand All @@ -444,13 +430,11 @@ function indexes($table, $connection2 = null) {
}

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) {
Expand Down Expand Up @@ -527,32 +511,26 @@ function found_rows($table_status, $where) {
}

/** Create index
* @param string
* @return mixed
*/
* @param string
* @return mixed
*/
function create_database($db) {
global $connection;

return $connection->rootQuery(urlencode($db), null, 'PUT');
return connection()->rootQuery(urlencode($db), null, 'PUT');
}

/** Remove index
* @param array
* @return mixed
*/
* @param array
* @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
* @param array
* @return mixed
*/
* @param array
* @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]);
Expand All @@ -566,28 +544,24 @@ function alter_table($table, $name, $fields, $foreign, $comment, $engine, $colla
$properties = array('properties' => $properties);
}

return $connection->query("_mapping/{$name}", $properties, 'PUT');
return connection()->query("_mapping/{$name}", $properties, 'PUT');
}

/** Drop types
* @param array
* @return bool
*/
* @param array
* @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() {
Expand Down

0 comments on commit c28db77

Please sign in to comment.