Skip to content

Commit

Permalink
Move Elastic drivers to plugins, driver for Elastic 7+ is the default
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpp committed Mar 17, 2024
1 parent 78faa45 commit 58d1c91
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 96 deletions.
13 changes: 13 additions & 0 deletions adminer/elastic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
function adminer_object() {
include_once "../plugins/plugin.php";
include_once "../plugins/login-password-less.php";
include_once "../plugins/drivers/elastic.php";
include_once "../plugins/drivers/elastic5.php";
return new AdminerPlugin([
// TODO: inline the result of password_hash() so that the password is not visible in source codes
new AdminerLoginPasswordLess(password_hash("YOUR_PASSWORD_HERE", PASSWORD_DEFAULT)),
]);
}

include "./index.php";
1 change: 0 additions & 1 deletion adminer/include/bootstrap.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ function adminer_errors($errno, $errstr) {
include "../adminer/drivers/oracle.inc.php";
include "../adminer/drivers/mssql.inc.php";
include "../adminer/drivers/mongo.inc.php";
include "../adminer/drivers/elastic.inc.php";
include "./include/adminer.inc.php";
$adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);
include "../adminer/drivers/mysql.inc.php"; // must be included as last driver
Expand Down
88 changes: 31 additions & 57 deletions adminer/drivers/elastic7.inc.php → plugins/drivers/elastic.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
$drivers["elastic7"] = "Elasticsearch 7 (beta)";
add_driver("elastic", "Elasticsearch 7 (beta)");

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

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 @@ -129,8 +129,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 @@ -185,7 +183,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 @@ -272,11 +270,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 @@ -293,9 +289,7 @@ function support($feature) {
}

function logged_user() {
global $adminer;

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

return $credentials[1];
}
Expand All @@ -321,9 +315,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 @@ -336,9 +328,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 @@ -357,10 +347,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 @@ -425,9 +413,7 @@ function is_view($table_status) {
}

function error() {
global $connection;

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

function information_schema() {
Expand All @@ -441,13 +427,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 @@ -524,32 +508,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 @@ -563,28 +541,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
Loading

0 comments on commit 58d1c91

Please sign in to comment.