Prepare Elasticsearch
This commit is contained in:
parent
fc427f4f3a
commit
b788a9e69b
247
adminer/drivers/elastic.inc.php
Normal file
247
adminer/drivers/elastic.inc.php
Normal file
|
@ -0,0 +1,247 @@
|
||||||
|
<?php
|
||||||
|
$drivers["elastic"] = "Elasticsearch";
|
||||||
|
|
||||||
|
if (isset($_GET["elastic"])) {
|
||||||
|
$possible_drivers = array("json");
|
||||||
|
define("DRIVER", "elastic");
|
||||||
|
|
||||||
|
if (function_exists('json_decode')) {
|
||||||
|
class Min_DB {
|
||||||
|
var $extension = "JSON", $server_info, $errno, $error, $_url;
|
||||||
|
|
||||||
|
function query($path) {
|
||||||
|
$file = @file_get_contents($this->_url . ($this->_db != "" ? "$this->_db/" : "") . $path, false, stream_context_create(array('http' => array(
|
||||||
|
'ignore_errors' => 1, // available since PHP 5.2.10
|
||||||
|
))));
|
||||||
|
@ini_set('track_errors', 1); // @ - may be disabled
|
||||||
|
if (!$file) {
|
||||||
|
$this->error = $php_errormsg;
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
if (!eregi('^HTTP/[0-9.]+ 2', $http_response_header[0])) {
|
||||||
|
$this->error = $file;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$return = json_decode($file, true);
|
||||||
|
if (!$return) {
|
||||||
|
$this->errno = json_last_error();
|
||||||
|
if (function_exists('json_last_error_msg')) {
|
||||||
|
$this->error = json_last_error_msg();
|
||||||
|
} else {
|
||||||
|
$constants = get_defined_constants(true);
|
||||||
|
foreach ($constants['json'] as $name => $value) {
|
||||||
|
if ($value == $this->errno && ereg('^JSON_ERROR_', $name)) {
|
||||||
|
$this->error = $name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function connect($server, $username, $password) {
|
||||||
|
$this->_url = "http://$username:$password@$server/";
|
||||||
|
$return = $this->query('');
|
||||||
|
if ($return) {
|
||||||
|
$this->server_info = $return['version']['number'];
|
||||||
|
}
|
||||||
|
return (bool) $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function select_db($database) {
|
||||||
|
$this->_db = $database;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function quote($string) {
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Min_Result {
|
||||||
|
var $_rows;
|
||||||
|
|
||||||
|
function Min_Result($rows) {
|
||||||
|
$this->_rows = $rows;
|
||||||
|
reset($this->_rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetch_assoc() {
|
||||||
|
$return = current($this->_rows);
|
||||||
|
next($this->_rows);
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetch_row() {
|
||||||
|
return array_values($this->fetch_assoc());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Min_Driver extends Min_SQL {
|
||||||
|
|
||||||
|
function select($table, $select, $where, $group, $order, $limit, $page) {
|
||||||
|
global $adminer;
|
||||||
|
$query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
|
||||||
|
if (!$query) {
|
||||||
|
$query = "$table/_search";
|
||||||
|
}
|
||||||
|
$search = $this->_conn->query($query);
|
||||||
|
if (!$search) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$return = array();
|
||||||
|
foreach ($search['hits']['hits'] as $hit) {
|
||||||
|
$row = array();
|
||||||
|
foreach ($hit['_source'] as $key => $val) {
|
||||||
|
$row[$key] = (is_array($val) ? implode(", ", $val) : $val);
|
||||||
|
}
|
||||||
|
$return[] = $row;
|
||||||
|
}
|
||||||
|
echo $adminer->selectQuery($query);
|
||||||
|
return new Min_Result($return);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function connect() {
|
||||||
|
global $adminer;
|
||||||
|
$connection = new Min_DB;
|
||||||
|
$credentials = $adminer->credentials();
|
||||||
|
if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
|
||||||
|
return $connection;
|
||||||
|
}
|
||||||
|
return $connection->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
function support($feature) {
|
||||||
|
return ereg("database|table", $feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
function logged_user() {
|
||||||
|
global $adminer;
|
||||||
|
$credentials = $adminer->credentials();
|
||||||
|
return $credentials[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_databases() {
|
||||||
|
global $connection;
|
||||||
|
$return = $connection->query('_aliases');
|
||||||
|
if ($return) {
|
||||||
|
$return = array_keys($return);
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function collations() {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
function db_collation($db, $collations) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function count_tables($databases) {
|
||||||
|
global $connection;
|
||||||
|
$return = $connection->query('_mapping');
|
||||||
|
if ($return) {
|
||||||
|
$return = array_map('count', $return);
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function tables_list() {
|
||||||
|
global $connection;
|
||||||
|
$return = $connection->query('_mapping');
|
||||||
|
if ($return) {
|
||||||
|
$return = array_fill_keys(array_keys(reset($return)), 'table');
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function table_status($name = "", $fast = false) {
|
||||||
|
$return = tables_list();
|
||||||
|
if ($return) {
|
||||||
|
foreach ($return as $key => $type) { // _stats have just info about database
|
||||||
|
$return[$key] = array("Name" => $key, "Engine" => $type);
|
||||||
|
if ($name != "") {
|
||||||
|
return $return[$name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function error() {
|
||||||
|
global $connection;
|
||||||
|
return h($connection->error);
|
||||||
|
}
|
||||||
|
|
||||||
|
function information_schema() {
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_view($table_status) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function indexes($table, $connection2 = null) {
|
||||||
|
return array(
|
||||||
|
array("type" => "PRIMARY", "columns" => array("_id")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fields($table) {
|
||||||
|
global $connection;
|
||||||
|
$mapping = $connection->query("$table/_mapping");
|
||||||
|
$return = array();
|
||||||
|
if ($mapping) {
|
||||||
|
foreach ($mapping[$table]['properties'] as $name => $field) {
|
||||||
|
$return[$name] = array(
|
||||||
|
"field" => $name,
|
||||||
|
"full_type" => $field["type"],
|
||||||
|
"type" => $field["type"],
|
||||||
|
"privileges" => array("insert" => 1, "select" => 1, "update" => 1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function foreign_keys($table) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
function table($idf) {
|
||||||
|
return $idf;
|
||||||
|
}
|
||||||
|
|
||||||
|
function idf_escape($idf) {
|
||||||
|
return $idf;
|
||||||
|
}
|
||||||
|
|
||||||
|
function convert_field($field) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function unconvert_field($field, $return) {
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fk_support($table_status) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function found_rows($table_status, $where) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$jush = "elastic";
|
||||||
|
$operators = array("=");
|
||||||
|
$functions = array();
|
||||||
|
$grouping = array();
|
||||||
|
$edit_functions = array();
|
||||||
|
}
|
|
@ -607,7 +607,7 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)
|
||||||
}
|
}
|
||||||
|
|
||||||
function support($feature) {
|
function support($feature) {
|
||||||
return ereg('^(database|table|scheme|trigger|view|drop_col)$', $feature); //! routine|
|
return ereg('^(database|table|sql|indexes|scheme|trigger|view|drop_col)$', $feature); //! routine|
|
||||||
}
|
}
|
||||||
|
|
||||||
$jush = "mssql";
|
$jush = "mssql";
|
||||||
|
|
|
@ -376,7 +376,7 @@ ORDER BY PROCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
function support($feature) {
|
function support($feature) {
|
||||||
return ereg("database|table|view|scheme|processlist|drop_col|variables|status", $feature); //!
|
return ereg('^(database|table|sql|indexes|view|scheme|processlist|drop_col|variables|status)$', $feature); //!
|
||||||
}
|
}
|
||||||
|
|
||||||
$jush = "oracle";
|
$jush = "oracle";
|
||||||
|
|
|
@ -613,7 +613,7 @@ AND typelem = 0"
|
||||||
}
|
}
|
||||||
|
|
||||||
function support($feature) {
|
function support($feature) {
|
||||||
return ereg('^(database|table|comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$', $feature); //! routine|
|
return ereg('^(database|table|sql|indexes|comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$', $feature); //! routine|
|
||||||
}
|
}
|
||||||
|
|
||||||
$jush = "pgsql";
|
$jush = "pgsql";
|
||||||
|
|
|
@ -119,7 +119,7 @@ if (isset($_GET["simpledb"])) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Min_Driver {
|
class Min_Driver extends Min_SQL {
|
||||||
|
|
||||||
function _chunkRequest($ids, $action, $params, $expand = array()) {
|
function _chunkRequest($ids, $action, $params, $expand = array()) {
|
||||||
global $connection;
|
global $connection;
|
||||||
|
@ -151,6 +151,14 @@ if (isset($_GET["simpledb"])) {
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function select($table, $select, $where, $group, $order, $limit, $page) {
|
||||||
|
global $connection;
|
||||||
|
$connection->next = $_GET["next"];
|
||||||
|
$return = parent::select($table, $select, $where, $group, $order, $limit, $page);
|
||||||
|
$connection->next = 0;
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
function delete($table, $queryWhere, $limit = 0) {
|
function delete($table, $queryWhere, $limit = 0) {
|
||||||
return $this->_chunkRequest(
|
return $this->_chunkRequest(
|
||||||
$this->_extractIds($table, $queryWhere, $limit),
|
$this->_extractIds($table, $queryWhere, $limit),
|
||||||
|
@ -231,7 +239,7 @@ if (isset($_GET["simpledb"])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function support($feature) {
|
function support($feature) {
|
||||||
return false;
|
return ereg('sql', $feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
function logged_user() {
|
function logged_user() {
|
||||||
|
|
|
@ -680,7 +680,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function support($feature) {
|
function support($feature) {
|
||||||
return ereg('^(database|table|view|trigger|variables|status|dump|move_col|drop_col)$', $feature);
|
return ereg('^(database|table|sql|indexes|view|trigger|variables|status|dump|move_col|drop_col)$', $feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
$jush = "sqlite";
|
$jush = "sqlite";
|
||||||
|
|
|
@ -769,7 +769,7 @@ username.form['auth[driver]'].onchange();
|
||||||
} else {
|
} else {
|
||||||
$this->databasesPrint($missing);
|
$this->databasesPrint($missing);
|
||||||
if (DB == "" || !$missing) {
|
if (DB == "" || !$missing) {
|
||||||
echo "<p class='links'><a href='" . h(ME) . "sql='" . bold(isset($_GET["sql"])) . ">" . lang('SQL command') . "/" . lang('Import') . "</a><br>\n";
|
echo "<p class='links'>" . (support("sql") ? "<a href='" . h(ME) . "sql='" . bold(isset($_GET["sql"])) . ">" . lang('SQL command') . "/" . lang('Import') . "</a><br>\n" : "") . "";
|
||||||
if (support("dump")) {
|
if (support("dump")) {
|
||||||
echo "<a href='" . h(ME) . "dump=" . urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]) . "' id='dump'" . bold(isset($_GET["dump"])) . ">" . lang('Dump') . "</a><br>\n";
|
echo "<a href='" . h(ME) . "dump=" . urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]) . "' id='dump'" . bold(isset($_GET["dump"])) . ">" . lang('Dump') . "</a><br>\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,7 @@ include "../adminer/drivers/sqlite.inc.php";
|
||||||
include "../adminer/drivers/pgsql.inc.php";
|
include "../adminer/drivers/pgsql.inc.php";
|
||||||
include "../adminer/drivers/oracle.inc.php";
|
include "../adminer/drivers/oracle.inc.php";
|
||||||
include "../adminer/drivers/mssql.inc.php";
|
include "../adminer/drivers/mssql.inc.php";
|
||||||
|
include "../adminer/drivers/elastic.inc.php";
|
||||||
include "../adminer/drivers/simpledb.inc.php";
|
include "../adminer/drivers/simpledb.inc.php";
|
||||||
include "../adminer/drivers/mysql.inc.php"; // must be included as last driver
|
include "../adminer/drivers/mysql.inc.php"; // must be included as last driver
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,33 @@
|
||||||
$this->_conn = $connection;
|
$this->_conn = $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Select data from table
|
||||||
|
* @param string
|
||||||
|
* @param array result of $adminer->selectColumnsProcess()[0]
|
||||||
|
* @param array result of $adminer->selectSearchProcess()
|
||||||
|
* @param array result of $adminer->selectColumnsProcess()[1]
|
||||||
|
* @param array result of $adminer->selectOrderProcess()
|
||||||
|
* @param int result of $adminer->selectLimitProcess()
|
||||||
|
* @param int index of page starting at zero
|
||||||
|
* @return Min_Result
|
||||||
|
*/
|
||||||
|
function select($table, $select, $where, $group, $order, $limit, $page) {
|
||||||
|
global $adminer, $jush;
|
||||||
|
$is_group = (count($group) < count($select));
|
||||||
|
$query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
|
||||||
|
if (!$query) {
|
||||||
|
$query = "SELECT" . limit(
|
||||||
|
($_GET["page"] != "last" && +$limit && $group && $is_group && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) . "\nFROM " . table($table),
|
||||||
|
($where ? "\nWHERE " . implode(" AND ", $where) : "") . ($group && $is_group ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : ""),
|
||||||
|
($limit != "" ? +$limit : null),
|
||||||
|
($page ? $limit * $page : 0),
|
||||||
|
"\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
echo $adminer->selectQuery($query);
|
||||||
|
return $this->_conn->query($query);
|
||||||
|
}
|
||||||
|
|
||||||
/** Delete data from table
|
/** Delete data from table
|
||||||
* @param string
|
* @param string
|
||||||
* @param string " WHERE ..."
|
* @param string " WHERE ..."
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
<?php
|
<?php
|
||||||
$VERSION = "3.7.2-dev";
|
$VERSION = "4.0.0-dev";
|
||||||
|
|
|
@ -245,21 +245,19 @@ if (!$columns && support("table")) {
|
||||||
$page = floor(max(0, $found_rows - 1) / $limit);
|
$page = floor(max(0, $found_rows - 1) / $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
|
$select2 = $select;
|
||||||
if (!$query) {
|
if (!$select2) {
|
||||||
$query = "SELECT" . limit(
|
$select2[] = "*";
|
||||||
($_GET["page"] != "last" && +$limit && $group && $is_group && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . $from,
|
if ($oid) {
|
||||||
($where ? "\nWHERE " . implode(" AND ", $where) : "") . $group_by,
|
$select2[] = $oid;
|
||||||
($limit != "" ? +$limit : null),
|
}
|
||||||
($page ? $limit * $page : 0),
|
|
||||||
"\n"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
echo $adminer->selectQuery($query);
|
$convert_fields = convert_fields($columns, $fields, $select);
|
||||||
|
if ($convert_fields) {
|
||||||
|
$select2[] = substr($convert_fields, 2);
|
||||||
|
}
|
||||||
|
$result = $driver->select($TABLE, $select2, $where, $group, $order, $limit, $page);
|
||||||
|
|
||||||
$connection->next = $_GET["next"];
|
|
||||||
$result = $connection->query($query);
|
|
||||||
$connection->next = 0;
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
echo "<p class='error'>" . error() . "\n";
|
echo "<p class='error'>" . error() . "\n";
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -27,24 +27,26 @@ if ($fields) {
|
||||||
echo "</table>\n";
|
echo "</table>\n";
|
||||||
|
|
||||||
if (!is_view($table_status)) {
|
if (!is_view($table_status)) {
|
||||||
echo "<h3 id='indexes'>" . lang('Indexes') . "</h3>\n";
|
if (support("indexes")) {
|
||||||
$indexes = indexes($TABLE);
|
echo "<h3 id='indexes'>" . lang('Indexes') . "</h3>\n";
|
||||||
if ($indexes) {
|
$indexes = indexes($TABLE);
|
||||||
echo "<table cellspacing='0'>\n";
|
if ($indexes) {
|
||||||
foreach ($indexes as $name => $index) {
|
echo "<table cellspacing='0'>\n";
|
||||||
ksort($index["columns"]); // enforce correct columns order
|
foreach ($indexes as $name => $index) {
|
||||||
$print = array();
|
ksort($index["columns"]); // enforce correct columns order
|
||||||
foreach ($index["columns"] as $key => $val) {
|
$print = array();
|
||||||
$print[] = "<i>" . h($val) . "</i>"
|
foreach ($index["columns"] as $key => $val) {
|
||||||
. ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "")
|
$print[] = "<i>" . h($val) . "</i>"
|
||||||
. ($index["descs"][$key] ? " DESC" : "")
|
. ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "")
|
||||||
;
|
. ($index["descs"][$key] ? " DESC" : "")
|
||||||
|
;
|
||||||
|
}
|
||||||
|
echo "<tr title='" . h($name) . "'><th>$index[type]<td>" . implode(", ", $print) . "\n";
|
||||||
}
|
}
|
||||||
echo "<tr title='" . h($name) . "'><th>$index[type]<td>" . implode(", ", $print) . "\n";
|
echo "</table>\n";
|
||||||
}
|
}
|
||||||
echo "</table>\n";
|
echo '<p class="links"><a href="' . h(ME) . 'indexes=' . urlencode($TABLE) . '">' . lang('Alter indexes') . "</a>\n";
|
||||||
}
|
}
|
||||||
echo '<p class="links"><a href="' . h(ME) . 'indexes=' . urlencode($TABLE) . '">' . lang('Alter indexes') . "</a>\n";
|
|
||||||
|
|
||||||
if (fk_support($table_status)) {
|
if (fk_support($table_status)) {
|
||||||
echo "<h3 id='foreign-keys'>" . lang('Foreign keys') . "</h3>\n";
|
echo "<h3 id='foreign-keys'>" . lang('Foreign keys') . "</h3>\n";
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Adminer 4.0.0-dev:
|
Adminer 4.0.0-dev:
|
||||||
Driver for SimpleDB
|
Driver for SimpleDB and Elasticsearch
|
||||||
Save and continue edit by AJAX
|
Save and continue edit by AJAX
|
||||||
Add a new column in alter table on key press
|
Add a new column in alter table on key press
|
||||||
Mark length as required for strings
|
Mark length as required for strings
|
||||||
|
|
Loading…
Reference in a new issue