mirror of
https://github.com/vrana/adminer.git
synced 2025-08-30 09:39:51 +02:00
Merge branch 'elastic'
This commit is contained in:
@@ -61,7 +61,7 @@ if ($adminer->homepage()) {
|
|||||||
echo " <input type='submit' name='search' value='" . lang('Search') . "'>\n";
|
echo " <input type='submit' name='search' value='" . lang('Search') . "'>\n";
|
||||||
echo "</div></fieldset>\n";
|
echo "</div></fieldset>\n";
|
||||||
if ($_POST["search"] && $_POST["query"] != "") {
|
if ($_POST["search"] && $_POST["query"] != "") {
|
||||||
$_GET["where"][0]["op"] = "LIKE %%";
|
$_GET["where"][0]["op"] = $driver->convertOperator("LIKE %%");
|
||||||
search_tables();
|
search_tables();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
adminer/elastic.php
Normal file
13
adminer/elastic.php
Normal file
@@ -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";
|
@@ -81,7 +81,6 @@ 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/mongo.inc.php";
|
include "../adminer/drivers/mongo.inc.php";
|
||||||
include "../adminer/drivers/elastic.inc.php";
|
|
||||||
include "./include/adminer.inc.php";
|
include "./include/adminer.inc.php";
|
||||||
$adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);
|
$adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);
|
||||||
include "../adminer/drivers/mysql.inc.php"; // must be included as last driver
|
include "../adminer/drivers/mysql.inc.php"; // must be included as last driver
|
||||||
|
@@ -142,6 +142,14 @@ function add_driver($id, $name) {
|
|||||||
return $idf;
|
return $idf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Convert operator so it can be used in search
|
||||||
|
* @param string $operator
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function convertOperator($operator) {
|
||||||
|
return $operator;
|
||||||
|
}
|
||||||
|
|
||||||
/** Convert value returned by database to actual value
|
/** Convert value returned by database to actual value
|
||||||
* @param string
|
* @param string
|
||||||
* @param array
|
* @param array
|
||||||
|
@@ -3,6 +3,8 @@ Adminer 4.9.0-dev:
|
|||||||
- Validate connection to server in HTTP based drivers.
|
- Validate connection to server in HTTP based drivers.
|
||||||
- Move dependencies from submodules to Composer.
|
- Move dependencies from submodules to Composer.
|
||||||
- Update hydra and pepa-lintha-dark themes.
|
- Update hydra and pepa-lintha-dark themes.
|
||||||
|
- Elasticsearch 5: Make unusable driver usable again, move it to plugins.
|
||||||
|
- Add new Elasticsearch 7 driver.
|
||||||
|
|
||||||
Adminer 4.8.2 (released 2024-03-16):
|
Adminer 4.8.2 (released 2024-03-16):
|
||||||
Support multi-line table comments
|
Support multi-line table comments
|
||||||
|
591
plugins/drivers/elastic.php
Normal file
591
plugins/drivers/elastic.php
Normal file
@@ -0,0 +1,591 @@
|
|||||||
|
<?php
|
||||||
|
add_driver("elastic", "Elasticsearch 7 (beta)");
|
||||||
|
|
||||||
|
if (isset($_GET["elastic"])) {
|
||||||
|
define("DRIVER", "elastic");
|
||||||
|
|
||||||
|
if (ini_bool('allow_url_fopen')) {
|
||||||
|
define("ELASTIC_DB_NAME", "elastic");
|
||||||
|
|
||||||
|
class Min_DB {
|
||||||
|
var $extension = "JSON", $server_info, $errno, $error, $_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $path
|
||||||
|
* @param array|null $content
|
||||||
|
* @param string $method
|
||||||
|
* @return array|false
|
||||||
|
*/
|
||||||
|
function rootQuery($path, array $content = null, $method = 'GET') {
|
||||||
|
@ini_set('track_errors', 1); // @ - may be disabled
|
||||||
|
|
||||||
|
$file = @file_get_contents("$this->_url/" . ltrim($path, '/'), false, stream_context_create(array('http' => array(
|
||||||
|
'method' => $method,
|
||||||
|
'content' => $content !== null ? json_encode($content) : null,
|
||||||
|
'header' => $content !== null ? 'Content-Type: application/json' : [],
|
||||||
|
'ignore_errors' => 1,
|
||||||
|
'follow_location' => 0,
|
||||||
|
'max_redirects' => 0,
|
||||||
|
))));
|
||||||
|
|
||||||
|
if ($file === false) {
|
||||||
|
$this->error = lang('Invalid server or credentials.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$return = json_decode($file, true);
|
||||||
|
if ($return === null) {
|
||||||
|
$this->error = lang('Invalid server or credentials.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!preg_match('~^HTTP/[0-9.]+ 2~i', $http_response_header[0])) {
|
||||||
|
if (isset($return['error']['root_cause'][0]['type'])) {
|
||||||
|
$this->error = $return['error']['root_cause'][0]['type'] . ": " . $return['error']['root_cause'][0]['reason'];
|
||||||
|
} elseif (isset($return['status']) && isset($return['error']) && is_string($return['error'])) {
|
||||||
|
$this->error = $return['error'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Performs query relative to actual selected DB
|
||||||
|
* @param string $path
|
||||||
|
* @param array|null $content
|
||||||
|
* @param string $method
|
||||||
|
* @return array|false
|
||||||
|
*/
|
||||||
|
function query($path, array $content = null, $method = 'GET') {
|
||||||
|
// Support for global search through all tables
|
||||||
|
if ($path != "" && $path[0] == "S" && preg_match('/SELECT 1 FROM ([^ ]+) WHERE (.+) LIMIT ([0-9]+)/', $path, $matches)) {
|
||||||
|
global $driver;
|
||||||
|
|
||||||
|
$where = explode(" AND ", $matches[2]);
|
||||||
|
|
||||||
|
return $driver->select($matches[1], array("*"), $where, null, array(), $matches[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->rootQuery($path, $content, $method);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $server
|
||||||
|
* @param string $username
|
||||||
|
* @param string $password
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function connect($server, $username, $password) {
|
||||||
|
$this->_url = build_http_url($server, $username, $password, "localhost", 9200);
|
||||||
|
|
||||||
|
$return = $this->query('');
|
||||||
|
if (!$return) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($return['version']['number'])) {
|
||||||
|
$this->error = lang('Invalid server or credentials.');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->server_info = $return['version']['number'];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function select_db($database) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function quote($string) {
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Min_Result {
|
||||||
|
var $num_rows, $_rows;
|
||||||
|
|
||||||
|
function __construct($rows) {
|
||||||
|
$this->num_rows = count($rows);
|
||||||
|
$this->_rows = $rows;
|
||||||
|
|
||||||
|
reset($this->_rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetch_assoc() {
|
||||||
|
$return = current($this->_rows);
|
||||||
|
next($this->_rows);
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetch_row() {
|
||||||
|
$row = $this->fetch_assoc();
|
||||||
|
|
||||||
|
return $row ? array_values($row) : false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Min_Driver extends Min_SQL {
|
||||||
|
|
||||||
|
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
|
||||||
|
$data = array();
|
||||||
|
if ($select != array("*")) {
|
||||||
|
$data["fields"] = $select;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($order) {
|
||||||
|
$sort = array();
|
||||||
|
foreach ($order as $col) {
|
||||||
|
$col = preg_replace('~ DESC$~', '', $col, 1, $count);
|
||||||
|
$sort[] = ($count ? array($col => "desc") : $col);
|
||||||
|
}
|
||||||
|
$data["sort"] = $sort;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($limit) {
|
||||||
|
$data["size"] = +$limit;
|
||||||
|
if ($page) {
|
||||||
|
$data["from"] = ($page * $limit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($where as $val) {
|
||||||
|
if (preg_match('~^\((.+ OR .+)\)$~', $val, $matches)) {
|
||||||
|
$parts = explode(" OR ", $matches[1]);
|
||||||
|
$terms = array();
|
||||||
|
foreach ($parts as $part) {
|
||||||
|
list($col, $op, $val) = explode(" ", $part, 3);
|
||||||
|
$term = array($col => $val);
|
||||||
|
if ($op == "=") {
|
||||||
|
$terms[] = array("term" => $term);
|
||||||
|
} elseif (in_array($op, array("must", "should", "must_not"))) {
|
||||||
|
$data["query"]["bool"][$op][]["match"] = $term;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($terms)) {
|
||||||
|
$data["query"]["bool"]["filter"][]["bool"]["should"] = $terms;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
list($col, $op, $val) = explode(" ", $val, 3);
|
||||||
|
$term = array($col => $val);
|
||||||
|
if ($op == "=") {
|
||||||
|
$data["query"]["bool"]["filter"][] = array("term" => $term);
|
||||||
|
} elseif (in_array($op, array("must", "should", "must_not"))) {
|
||||||
|
$data["query"]["bool"][$op][]["match"] = $term;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = "$table/_search";
|
||||||
|
$start = microtime(true);
|
||||||
|
$search = $this->_conn->rootQuery($query, $data);
|
||||||
|
|
||||||
|
if ($print) {
|
||||||
|
echo adminer()->selectQuery("$query: " . json_encode($data), $start, !$search);
|
||||||
|
}
|
||||||
|
if (empty($search)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$return = array();
|
||||||
|
foreach ($search["hits"]["hits"] as $hit) {
|
||||||
|
$row = array();
|
||||||
|
if ($select == array("*")) {
|
||||||
|
$row["_id"] = $hit["_id"];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($select != array("*")) {
|
||||||
|
$fields = array();
|
||||||
|
foreach ($select as $key) {
|
||||||
|
$fields[$key] = $key == "_id" ? $hit["_id"] : $hit["_source"][$key];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$fields = $hit["_source"];
|
||||||
|
}
|
||||||
|
foreach ($fields as $key => $val) {
|
||||||
|
$row[$key] = (is_array($val) ? json_encode($val) : $val);
|
||||||
|
}
|
||||||
|
|
||||||
|
$return[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Min_Result($return);
|
||||||
|
}
|
||||||
|
|
||||||
|
function update($type, $record, $queryWhere, $limit = 0, $separator = "\n") {
|
||||||
|
//! use $limit
|
||||||
|
$parts = preg_split('~ *= *~', $queryWhere);
|
||||||
|
if (count($parts) == 2) {
|
||||||
|
$id = trim($parts[1]);
|
||||||
|
$query = "$type/$id";
|
||||||
|
|
||||||
|
return $this->_conn->query($query, $record, 'POST');
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function insert($type, $record) {
|
||||||
|
$id = ""; //! user should be able to inform _id
|
||||||
|
$query = "$type/$id";
|
||||||
|
$response = $this->_conn->query($query, $record, 'POST');
|
||||||
|
$this->_conn->last_id = $response['_id'];
|
||||||
|
|
||||||
|
return $response['created'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function delete($table, $queryWhere, $limit = 0) {
|
||||||
|
//! use $limit
|
||||||
|
$ids = array();
|
||||||
|
if (isset($_GET["where"]["_id"]) && $_GET["where"]["_id"]) {
|
||||||
|
$ids[] = $_GET["where"]["_id"];
|
||||||
|
}
|
||||||
|
if (isset($_POST['check'])) {
|
||||||
|
foreach ($_POST['check'] as $check) {
|
||||||
|
$parts = preg_split('~ *= *~', $check);
|
||||||
|
if (count($parts) == 2) {
|
||||||
|
$ids[] = trim($parts[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_conn->affected_rows = 0;
|
||||||
|
|
||||||
|
foreach ($ids as $id) {
|
||||||
|
$query = "$table/_doc/$id";
|
||||||
|
$response = $this->_conn->query($query, null, 'DELETE');
|
||||||
|
if (isset($response['result']) && $response['result'] == 'deleted') {
|
||||||
|
$this->_conn->affected_rows++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->_conn->affected_rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
function convertOperator($operator) {
|
||||||
|
return $operator == "LIKE %%" ? "should" : $operator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function connect() {
|
||||||
|
$connection = new Min_DB;
|
||||||
|
|
||||||
|
list($server, $username, $password) = adminer()->credentials();
|
||||||
|
if ($password != "" && $connection->connect($server, $username, "")) {
|
||||||
|
return lang('Database does not support password.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($connection->connect($server, $username, $password)) {
|
||||||
|
return $connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $connection->error;
|
||||||
|
}
|
||||||
|
|
||||||
|
function support($feature) {
|
||||||
|
return preg_match("~table|columns~", $feature);
|
||||||
|
}
|
||||||
|
|
||||||
|
function logged_user() {
|
||||||
|
$credentials = adminer()->credentials();
|
||||||
|
|
||||||
|
return $credentials[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_databases() {
|
||||||
|
return array(ELASTIC_DB_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
function limit($query, $where, $limit, $offset = 0, $separator = " ") {
|
||||||
|
return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
function collations() {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
function db_collation($db, $collations) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
function engines() {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
function count_tables($databases) {
|
||||||
|
$return = connection()->rootQuery('_aliases');
|
||||||
|
if (empty($return)) {
|
||||||
|
return array(
|
||||||
|
ELASTIC_DB_NAME => 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
ELASTIC_DB_NAME => count($return)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function tables_list() {
|
||||||
|
$aliases = connection()->rootQuery('_aliases');
|
||||||
|
if (empty($aliases)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
ksort($aliases);
|
||||||
|
|
||||||
|
$tables = array();
|
||||||
|
foreach ($aliases as $name => $index) {
|
||||||
|
$tables[$name] = "table";
|
||||||
|
|
||||||
|
ksort($index["aliases"]);
|
||||||
|
$tables += array_fill_keys(array_keys($index["aliases"]), "view");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tables;
|
||||||
|
}
|
||||||
|
|
||||||
|
function table_status($name = "", $fast = false) {
|
||||||
|
$stats = connection()->rootQuery('_stats');
|
||||||
|
$aliases = connection()->rootQuery('_aliases');
|
||||||
|
|
||||||
|
if (empty($stats) || empty($aliases)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
|
||||||
|
if ($name != "") {
|
||||||
|
if (isset($stats["indices"][$name])) {
|
||||||
|
return format_index_status($name, $stats["indices"][$name]);
|
||||||
|
} else foreach ($aliases as $index_name => $index) {
|
||||||
|
foreach ($index["aliases"] as $alias_name => $alias) {
|
||||||
|
if ($alias_name == $name) {
|
||||||
|
return format_alias_status($alias_name, $stats["indices"][$index_name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ksort($stats["indices"]);
|
||||||
|
foreach ($stats["indices"] as $name => $index) {
|
||||||
|
if ($name[0] == ".") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result[$name] = format_index_status($name, $index);
|
||||||
|
|
||||||
|
if (!empty($aliases[$name]["aliases"])) {
|
||||||
|
ksort($aliases[$name]["aliases"]);
|
||||||
|
foreach ($aliases[$name]["aliases"] as $alias_name => $alias) {
|
||||||
|
$result[$alias_name] = format_alias_status($alias_name, $stats["indices"][$name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function format_index_status($name, $index) {
|
||||||
|
return array(
|
||||||
|
"Name" => $name,
|
||||||
|
"Engine" => "Lucene",
|
||||||
|
"Oid" => $index["uuid"],
|
||||||
|
"Rows" => $index["total"]["docs"]["count"],
|
||||||
|
"Auto_increment" => 0,
|
||||||
|
"Data_length" => $index["total"]["store"]["size_in_bytes"],
|
||||||
|
"Index_length" => 0,
|
||||||
|
"Data_free" => $index["total"]["store"]["reserved_in_bytes"],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function format_alias_status($name, $index) {
|
||||||
|
return array(
|
||||||
|
"Name" => $name,
|
||||||
|
"Engine" => "view",
|
||||||
|
"Rows" => $index["total"]["docs"]["count"],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_view($table_status) {
|
||||||
|
return $table_status["Engine"] == "view";
|
||||||
|
}
|
||||||
|
|
||||||
|
function error() {
|
||||||
|
return h(connection()->error);
|
||||||
|
}
|
||||||
|
|
||||||
|
function information_schema() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
function indexes($table, $connection2 = null) {
|
||||||
|
return array(
|
||||||
|
array("type" => "PRIMARY", "columns" => array("_id")),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fields($table) {
|
||||||
|
$mappings = array();
|
||||||
|
$mapping = connection()->rootQuery("_mapping");
|
||||||
|
|
||||||
|
if (!isset($mapping[$table])) {
|
||||||
|
$aliases = connection()->rootQuery('_aliases');
|
||||||
|
|
||||||
|
foreach ($aliases as $index_name => $index) {
|
||||||
|
foreach ($index["aliases"] as $alias_name => $alias) {
|
||||||
|
if ($alias_name == $table) {
|
||||||
|
$table = $index_name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($mapping)) {
|
||||||
|
$mappings = $mapping[$table]["mappings"]["properties"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = array(
|
||||||
|
"_id" => array(
|
||||||
|
"field" => "_id",
|
||||||
|
"full_type" => "text",
|
||||||
|
"type" => "text",
|
||||||
|
"privileges" => array("insert" => 1, "select" => 1, "where" => 1, "order" => 1),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($mappings as $name => $field) {
|
||||||
|
$has_index = !isset($field["index"]) || $field["index"];
|
||||||
|
|
||||||
|
// TODO: privileges: where => $has_index
|
||||||
|
// TODO: privileges: sort => $field["type"] != "text"
|
||||||
|
|
||||||
|
$result[$name] = array(
|
||||||
|
"field" => $name,
|
||||||
|
"full_type" => $field["type"],
|
||||||
|
"type" => $field["type"],
|
||||||
|
"privileges" => array(
|
||||||
|
"insert" => 1,
|
||||||
|
"select" => 1,
|
||||||
|
"update" => 1,
|
||||||
|
"where" => !isset($field["index"]) || $field["index"] ?: null,
|
||||||
|
"order" => $field["type"] != "text" ?: null
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Create index
|
||||||
|
* @param string
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function create_database($db) {
|
||||||
|
return connection()->rootQuery(urlencode($db), null, 'PUT');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Remove index
|
||||||
|
* @param array
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function drop_databases($databases) {
|
||||||
|
return connection()->rootQuery(urlencode(implode(',', $databases)), null, 'DELETE');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Alter type
|
||||||
|
* @param array
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
|
||||||
|
$properties = array();
|
||||||
|
foreach ($fields as $f) {
|
||||||
|
$field_name = trim($f[1][0]);
|
||||||
|
$field_type = trim($f[1][1] ? $f[1][1] : "text");
|
||||||
|
$properties[$field_name] = array(
|
||||||
|
'type' => $field_type
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($properties)) {
|
||||||
|
$properties = array('properties' => $properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
return connection()->query("_mapping/{$name}", $properties, 'PUT');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Drop types
|
||||||
|
* @param array
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function drop_tables($tables) {
|
||||||
|
$return = true;
|
||||||
|
foreach ($tables as $table) { //! convert to bulk api
|
||||||
|
$return = $return && connection()->query(urlencode($table), null, 'DELETE');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
function last_id() {
|
||||||
|
return connection()->last_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function driver_config() {
|
||||||
|
$types = array();
|
||||||
|
$structured_types = array();
|
||||||
|
|
||||||
|
foreach (array(
|
||||||
|
lang('Numbers') => array("long" => 3, "integer" => 5, "short" => 8, "byte" => 10, "double" => 20, "float" => 66, "half_float" => 12, "scaled_float" => 21),
|
||||||
|
lang('Date and time') => array("date" => 10),
|
||||||
|
lang('Strings') => array("string" => 65535, "text" => 65535),
|
||||||
|
lang('Binary') => array("binary" => 255),
|
||||||
|
) as $key => $val) {
|
||||||
|
$types += $val;
|
||||||
|
$structured_types[$key] = array_keys($val);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'possible_drivers' => array("json + allow_url_fopen"),
|
||||||
|
'jush' => "elastic",
|
||||||
|
'operators' => array("=", "must", "should", "must_not"),
|
||||||
|
'functions' => array(),
|
||||||
|
'grouping' => array(),
|
||||||
|
'edit_functions' => array(array("json")),
|
||||||
|
'types' => $types,
|
||||||
|
'structured_types' => $structured_types,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
$drivers["elastic"] = "Elasticsearch (beta)";
|
add_driver("elastic5", "Elasticsearch 5 (beta)");
|
||||||
|
|
||||||
if (isset($_GET["elastic"])) {
|
if (isset($_GET["elastic5"])) {
|
||||||
define("DRIVER", "elastic");
|
define("DRIVER", "elastic5");
|
||||||
|
|
||||||
if (function_exists('json_decode') && ini_bool('allow_url_fopen')) {
|
if (ini_bool('allow_url_fopen')) {
|
||||||
class Min_DB {
|
class Min_DB {
|
||||||
var $extension = "JSON", $server_info, $errno, $error, $_url, $_db;
|
var $extension = "JSON", $server_info, $errno, $error, $_url, $_db;
|
||||||
|
|
||||||
@@ -16,6 +16,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
*/
|
*/
|
||||||
function rootQuery($path, array $content = null, $method = 'GET') {
|
function rootQuery($path, array $content = null, $method = 'GET') {
|
||||||
@ini_set('track_errors', 1); // @ - may be disabled
|
@ini_set('track_errors', 1); // @ - may be disabled
|
||||||
|
|
||||||
$file = @file_get_contents("$this->_url/" . ltrim($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,
|
'method' => $method,
|
||||||
'content' => $content !== null ? json_encode($content) : null,
|
'content' => $content !== null ? json_encode($content) : null,
|
||||||
@@ -55,6 +56,15 @@ if (isset($_GET["elastic"])) {
|
|||||||
* @return array|false
|
* @return array|false
|
||||||
*/
|
*/
|
||||||
function query($path, array $content = null, $method = 'GET') {
|
function query($path, array $content = null, $method = 'GET') {
|
||||||
|
// Support for global search through all tables
|
||||||
|
if ($path != "" && $path[0] == "S" && preg_match('/SELECT 1 FROM ([^ ]+) WHERE (.+) LIMIT ([0-9]+)/', $path, $matches)) {
|
||||||
|
global $driver;
|
||||||
|
|
||||||
|
$where = explode(" AND ", $matches[2]);
|
||||||
|
|
||||||
|
return $driver->select($matches[1], array("*"), $where, null, array(), $matches[3]);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->rootQuery(($this->_db != "" ? "$this->_db/" : "/") . ltrim($path, '/'), $content, $method);
|
return $this->rootQuery(($this->_db != "" ? "$this->_db/" : "/") . ltrim($path, '/'), $content, $method);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,13 +93,13 @@ if (isset($_GET["elastic"])) {
|
|||||||
|
|
||||||
function select_db($database) {
|
function select_db($database) {
|
||||||
$this->_db = $database;
|
$this->_db = $database;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function quote($string) {
|
function quote($string) {
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Min_Result {
|
class Min_Result {
|
||||||
@@ -98,34 +108,33 @@ if (isset($_GET["elastic"])) {
|
|||||||
function __construct($rows) {
|
function __construct($rows) {
|
||||||
$this->num_rows = count($rows);
|
$this->num_rows = count($rows);
|
||||||
$this->_rows = $rows;
|
$this->_rows = $rows;
|
||||||
|
|
||||||
reset($this->_rows);
|
reset($this->_rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetch_assoc() {
|
function fetch_assoc() {
|
||||||
$return = current($this->_rows);
|
$return = current($this->_rows);
|
||||||
next($this->_rows);
|
next($this->_rows);
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetch_row() {
|
function fetch_row() {
|
||||||
return array_values($this->fetch_assoc());
|
$row = $this->fetch_assoc();
|
||||||
|
|
||||||
|
return $row ? array_values($row) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Min_Driver extends Min_SQL {
|
class Min_Driver extends Min_SQL {
|
||||||
|
|
||||||
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
|
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
|
||||||
global $adminer;
|
|
||||||
$data = array();
|
$data = array();
|
||||||
$query = "$table/_search";
|
|
||||||
if ($select != array("*")) {
|
if ($select != array("*")) {
|
||||||
$data["fields"] = $select;
|
$data["fields"] = $select;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($order) {
|
if ($order) {
|
||||||
$sort = array();
|
$sort = array();
|
||||||
foreach ($order as $col) {
|
foreach ($order as $col) {
|
||||||
@@ -134,58 +143,78 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
$data["sort"] = $sort;
|
$data["sort"] = $sort;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($limit) {
|
if ($limit) {
|
||||||
$data["size"] = +$limit;
|
$data["size"] = +$limit;
|
||||||
if ($page) {
|
if ($page) {
|
||||||
$data["from"] = ($page * $limit);
|
$data["from"] = ($page * $limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($where as $val) {
|
foreach ($where as $val) {
|
||||||
list($col, $op, $val) = explode(" ", $val, 3);
|
if (preg_match('~^\((.+ OR .+)\)$~', $val, $matches)) {
|
||||||
if ($col == "_id") {
|
$parts = explode(" OR ", $matches[1]);
|
||||||
$data["query"]["ids"]["values"][] = $val;
|
$terms = array();
|
||||||
}
|
foreach ($parts as $part) {
|
||||||
elseif ($col . $val != "") {
|
list($col, $op, $val) = explode(" ", $part, 3);
|
||||||
$term = array("term" => array(($col != "" ? $col : "_all") => $val));
|
$term = array($col => $val);
|
||||||
|
if ($op == "=") {
|
||||||
|
$terms[] = array("term" => $term);
|
||||||
|
} elseif (in_array($op, array("must", "should", "must_not"))) {
|
||||||
|
$data["query"]["bool"][$op][]["match"] = $term;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($terms)) {
|
||||||
|
$data["query"]["bool"]["filter"][]["bool"]["should"] = $terms;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
list($col, $op, $val) = explode(" ", $val, 3);
|
||||||
|
$term = array($col => $val);
|
||||||
if ($op == "=") {
|
if ($op == "=") {
|
||||||
$data["query"]["filtered"]["filter"]["and"][] = $term;
|
$data["query"]["bool"]["filter"][] = array("term" => $term);
|
||||||
} else {
|
} elseif (in_array($op, array("must", "should", "must_not"))) {
|
||||||
$data["query"]["filtered"]["query"]["bool"]["must"][] = $term;
|
$data["query"]["bool"][$op][]["match"] = $term;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($data["query"] && !$data["query"]["filtered"]["query"] && !$data["query"]["ids"]) {
|
|
||||||
$data["query"]["filtered"]["query"] = array("match_all" => array());
|
$query = (min_version(7) ? "" : "$table/") . "_search";
|
||||||
}
|
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
$search = $this->_conn->query($query, $data);
|
$search = $this->_conn->query($query, $data);
|
||||||
|
|
||||||
if ($print) {
|
if ($print) {
|
||||||
echo $adminer->selectQuery("$query: " . json_encode($data), $start, !$search);
|
echo adminer()->selectQuery("$query: " . json_encode($data), $start, !$search);
|
||||||
}
|
}
|
||||||
if (!$search) {
|
if (!$search) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$return = array();
|
$return = array();
|
||||||
foreach ($search['hits']['hits'] as $hit) {
|
foreach ($search['hits']['hits'] as $hit) {
|
||||||
$row = array();
|
$row = array();
|
||||||
if ($select == array("*")) {
|
if ($select == array("*")) {
|
||||||
$row["_id"] = $hit["_id"];
|
$row["_id"] = $hit["_id"];
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields = $hit['_source'];
|
$fields = $hit['_source'];
|
||||||
if ($select != array("*")) {
|
if ($select != array("*")) {
|
||||||
$fields = array();
|
$fields = array();
|
||||||
foreach ($select as $key) {
|
foreach ($select as $key) {
|
||||||
$fields[$key] = $hit['fields'][$key];
|
$fields[$key] = $key == "_id" ? [$hit["_id"]] : $hit['fields'][$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($fields as $key => $val) {
|
foreach ($fields as $key => $val) {
|
||||||
if ($data["fields"]) {
|
if ($data["fields"]) {
|
||||||
$val = $val[0];
|
$val = $val[0];
|
||||||
}
|
}
|
||||||
$row[$key] = (is_array($val) ? json_encode($val) : $val); //! display JSON and others differently
|
$row[$key] = (is_array($val) ? json_encode($val) : $val); //! display JSON and others differently
|
||||||
}
|
}
|
||||||
|
|
||||||
$return[] = $row;
|
$return[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Min_Result($return);
|
return new Min_Result($return);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,8 +224,10 @@ if (isset($_GET["elastic"])) {
|
|||||||
if (count($parts) == 2) {
|
if (count($parts) == 2) {
|
||||||
$id = trim($parts[1]);
|
$id = trim($parts[1]);
|
||||||
$query = "$type/$id";
|
$query = "$type/$id";
|
||||||
|
|
||||||
return $this->_conn->query($query, $record, 'POST');
|
return $this->_conn->query($query, $record, 'POST');
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,16 +236,17 @@ if (isset($_GET["elastic"])) {
|
|||||||
$query = "$type/$id";
|
$query = "$type/$id";
|
||||||
$response = $this->_conn->query($query, $record, 'POST');
|
$response = $this->_conn->query($query, $record, 'POST');
|
||||||
$this->_conn->last_id = $response['_id'];
|
$this->_conn->last_id = $response['_id'];
|
||||||
|
|
||||||
return $response['created'];
|
return $response['created'];
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($type, $queryWhere, $limit = 0) {
|
function delete($type, $queryWhere, $limit = 0) {
|
||||||
//! use $limit
|
//! use $limit
|
||||||
$ids = array();
|
$ids = array();
|
||||||
if (is_array($_GET["where"]) && $_GET["where"]["_id"]) {
|
if (isset($_GET["where"]["_id"]) && $_GET["where"]["_id"]) {
|
||||||
$ids[] = $_GET["where"]["_id"];
|
$ids[] = $_GET["where"]["_id"];
|
||||||
}
|
}
|
||||||
if (is_array($_POST['check'])) {
|
if (isset($_POST['check'])) {
|
||||||
foreach ($_POST['check'] as $check) {
|
foreach ($_POST['check'] as $check) {
|
||||||
$parts = preg_split('~ *= *~', $check);
|
$parts = preg_split('~ *= *~', $check);
|
||||||
if (count($parts) == 2) {
|
if (count($parts) == 2) {
|
||||||
@@ -222,30 +254,37 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_conn->affected_rows = 0;
|
$this->_conn->affected_rows = 0;
|
||||||
|
|
||||||
foreach ($ids as $id) {
|
foreach ($ids as $id) {
|
||||||
$query = "{$type}/{$id}";
|
$query = "{$type}/{$id}";
|
||||||
$response = $this->_conn->query($query, '{}', 'DELETE');
|
$response = $this->_conn->query($query, null, 'DELETE');
|
||||||
if (is_array($response) && $response['found'] == true) {
|
if ((isset($response['found']) && $response['found']) || (isset($response['result']) && $response['result'] == 'deleted')) {
|
||||||
$this->_conn->affected_rows++;
|
$this->_conn->affected_rows++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_conn->affected_rows;
|
return $this->_conn->affected_rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function convertOperator($operator) {
|
||||||
|
return $operator == "LIKE %%" ? "should" : $operator;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
global $adminer;
|
|
||||||
$connection = new Min_DB;
|
$connection = new Min_DB;
|
||||||
list($server, $username, $password) = $adminer->credentials();
|
|
||||||
|
list($server, $username, $password) = adminer()->credentials();
|
||||||
if ($password != "" && $connection->connect($server, $username, "")) {
|
if ($password != "" && $connection->connect($server, $username, "")) {
|
||||||
return lang('Database does not support password.');
|
return lang('Database does not support password.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($connection->connect($server, $username, $password)) {
|
if ($connection->connect($server, $username, $password)) {
|
||||||
return $connection;
|
return $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $connection->error;
|
return $connection->error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,26 +293,31 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function logged_user() {
|
function logged_user() {
|
||||||
global $adminer;
|
$credentials = adminer()->credentials();
|
||||||
$credentials = $adminer->credentials();
|
|
||||||
return $credentials[1];
|
return $credentials[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_databases() {
|
function get_databases() {
|
||||||
global $connection;
|
$return = connection()->rootQuery('_aliases');
|
||||||
$return = $connection->rootQuery('_aliases');
|
|
||||||
if ($return) {
|
if ($return) {
|
||||||
$return = array_keys($return);
|
$return = array_keys($return);
|
||||||
sort($return, SORT_STRING);
|
sort($return, SORT_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function limit($query, $where, $limit, $offset = 0, $separator = " ") {
|
||||||
|
return " $query$where" . ($limit !== null ? $separator . "LIMIT $limit" . ($offset ? " OFFSET $offset" : "") : "");
|
||||||
|
}
|
||||||
|
|
||||||
function collations() {
|
function collations() {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
function db_collation($db, $collations) {
|
function db_collation($db, $collations) {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
function engines() {
|
function engines() {
|
||||||
@@ -281,9 +325,9 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function count_tables($databases) {
|
function count_tables($databases) {
|
||||||
global $connection;
|
|
||||||
$return = array();
|
$return = array();
|
||||||
$result = $connection->query('_stats');
|
|
||||||
|
$result = connection()->query('_stats');
|
||||||
if ($result && $result['indices']) {
|
if ($result && $result['indices']) {
|
||||||
$indices = $result['indices'];
|
$indices = $result['indices'];
|
||||||
foreach ($indices as $indice => $stats) {
|
foreach ($indices as $indice => $stats) {
|
||||||
@@ -291,26 +335,25 @@ if (isset($_GET["elastic"])) {
|
|||||||
$return[$indice] = $indexing['index_total'];
|
$return[$indice] = $indexing['index_total'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function tables_list() {
|
function tables_list() {
|
||||||
global $connection;
|
if (min_version(7)) {
|
||||||
|
|
||||||
if (min_version(6)) {
|
|
||||||
return array('_doc' => 'table');
|
return array('_doc' => 'table');
|
||||||
}
|
}
|
||||||
|
|
||||||
$return = $connection->query('_mapping');
|
$return = connection()->query('_mapping');
|
||||||
if ($return) {
|
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;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function table_status($name = "", $fast = false) {
|
function table_status($name = "", $fast = false) {
|
||||||
global $connection;
|
$search = connection()->query("_search", array(
|
||||||
$search = $connection->query("_search", array(
|
|
||||||
"size" => 0,
|
"size" => 0,
|
||||||
"aggregations" => array(
|
"aggregations" => array(
|
||||||
"count_by_type" => array(
|
"count_by_type" => array(
|
||||||
@@ -320,26 +363,30 @@ if (isset($_GET["elastic"])) {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
), "POST");
|
), "POST");
|
||||||
|
|
||||||
$return = array();
|
$return = array();
|
||||||
|
|
||||||
if ($search) {
|
if ($search) {
|
||||||
$tables = $search["aggregations"]["count_by_type"]["buckets"];
|
$tables = $search["aggregations"]["count_by_type"]["buckets"];
|
||||||
|
|
||||||
foreach ($tables as $table) {
|
foreach ($tables as $table) {
|
||||||
$return[$table["key"]] = array(
|
$return[$table["key"]] = array(
|
||||||
"Name" => $table["key"],
|
"Name" => $table["key"],
|
||||||
"Engine" => "table",
|
"Engine" => "table",
|
||||||
"Rows" => $table["doc_count"],
|
"Rows" => $table["doc_count"],
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($name != "" && $name == $table["key"]) {
|
if ($name != "" && $name == $table["key"]) {
|
||||||
return $return[$name];
|
return $return[$name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function error() {
|
function error() {
|
||||||
global $connection;
|
return h(connection()->error);
|
||||||
return h($connection->error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function information_schema() {
|
function information_schema() {
|
||||||
@@ -355,45 +402,54 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fields($table) {
|
function fields($table) {
|
||||||
global $connection;
|
|
||||||
|
|
||||||
$mappings = array();
|
$mappings = array();
|
||||||
if (min_version(6)) {
|
|
||||||
$result = $connection->query("_mapping");
|
if (min_version(7)) {
|
||||||
|
$result = connection()->query("_mapping");
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$mappings = $result[$connection->_db]['mappings']['properties'];
|
$mappings = $result[connection()->_db]['mappings']['properties'];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$result = $connection->query("$table/_mapping");
|
$result = connection()->query("$table/_mapping");
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$mappings = $result[$table]['properties'];
|
$mappings = $result[$table]['properties'];
|
||||||
if (!$mappings) {
|
if (!$mappings) {
|
||||||
$mappings = $result[$connection->_db]['mappings'][$table]['properties'];
|
$mappings = $result[connection()->_db]['mappings'][$table]['properties'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$return = array();
|
$return = array(
|
||||||
if ($mappings) {
|
"_id" => array(
|
||||||
foreach ($mappings as $name => $field) {
|
"field" => "_id",
|
||||||
$return[$name] = array(
|
"full_type" => "text",
|
||||||
"field" => $name,
|
"type" => "text",
|
||||||
"full_type" => $field["type"],
|
"privileges" => array("insert" => 1, "select" => 1, "where" => 1, "order" => 1),
|
||||||
"type" => $field["type"],
|
)
|
||||||
"privileges" => array(
|
);
|
||||||
"insert" => 1,
|
|
||||||
"select" => 1,
|
foreach ($mappings as $name => $field) {
|
||||||
"update" => 1,
|
if (isset($field["index"]) && !$field["index"]) continue;
|
||||||
"where" => !isset($field["index"]) || $field["index"] ?: null,
|
|
||||||
"order" => $field["type"] != "text" ?: null
|
$return[$name] = array(
|
||||||
),
|
"field" => $name,
|
||||||
);
|
"full_type" => $field["type"],
|
||||||
if ($field["properties"]) { // only leaf fields can be edited
|
"type" => $field["type"],
|
||||||
unset($return[$name]["privileges"]["insert"]);
|
"privileges" => array(
|
||||||
unset($return[$name]["privileges"]["update"]);
|
"insert" => 1,
|
||||||
}
|
"select" => 1,
|
||||||
|
"update" => 1,
|
||||||
|
"where" => !isset($field["index"]) || $field["index"] ?: null,
|
||||||
|
"order" => $field["type"] != "text" ?: null
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($field["properties"]) { // only leaf fields can be edited
|
||||||
|
unset($return[$name]["privileges"]["insert"]);
|
||||||
|
unset($return[$name]["privileges"]["update"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,6 +466,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function convert_field($field) {
|
function convert_field($field) {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
function unconvert_field($field, $return) {
|
function unconvert_field($field, $return) {
|
||||||
@@ -417,6 +474,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fk_support($table_status) {
|
function fk_support($table_status) {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
function found_rows($table_status, $where) {
|
function found_rows($table_status, $where) {
|
||||||
@@ -424,29 +482,26 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Create index
|
/** Create index
|
||||||
* @param string
|
* @param string
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function create_database($db) {
|
function create_database($db) {
|
||||||
global $connection;
|
return connection()->rootQuery(urlencode($db), null, 'PUT');
|
||||||
return $connection->rootQuery(urlencode($db), null, 'PUT');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove index
|
/** Remove index
|
||||||
* @param array
|
* @param array
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function drop_databases($databases) {
|
function drop_databases($databases) {
|
||||||
global $connection;
|
return connection()->rootQuery(urlencode(implode(',', $databases)), null, 'DELETE');
|
||||||
return $connection->rootQuery(urlencode(implode(',', $databases)), array(), 'DELETE');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Alter type
|
/** Alter type
|
||||||
* @param array
|
* @param array
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
|
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
|
||||||
global $connection;
|
|
||||||
$properties = array();
|
$properties = array();
|
||||||
foreach ($fields as $f) {
|
foreach ($fields as $f) {
|
||||||
$field_name = trim($f[1][0]);
|
$field_name = trim($f[1][0]);
|
||||||
@@ -455,33 +510,34 @@ if (isset($_GET["elastic"])) {
|
|||||||
'type' => $field_type
|
'type' => $field_type
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($properties)) {
|
if (!empty($properties)) {
|
||||||
$properties = array('properties' => $properties);
|
$properties = array('properties' => $properties);
|
||||||
}
|
}
|
||||||
return $connection->query("_mapping/{$name}", $properties, 'PUT');
|
return connection()->query("_mapping/{$name}", $properties, 'PUT');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Drop types
|
/** Drop types
|
||||||
* @param array
|
* @param array
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function drop_tables($tables) {
|
function drop_tables($tables) {
|
||||||
global $connection;
|
|
||||||
$return = true;
|
$return = true;
|
||||||
foreach ($tables as $table) { //! convert to bulk api
|
foreach ($tables as $table) { //! convert to bulk api
|
||||||
$return = $return && $connection->query(urlencode($table), array(), 'DELETE');
|
$return = $return && connection()->query(urlencode($table), null, 'DELETE');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function last_id() {
|
function last_id() {
|
||||||
global $connection;
|
return connection()->last_id;
|
||||||
return $connection->last_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function driver_config() {
|
function driver_config() {
|
||||||
$types = array();
|
$types = array();
|
||||||
$structured_types = array();
|
$structured_types = array();
|
||||||
|
|
||||||
foreach (array(
|
foreach (array(
|
||||||
lang('Numbers') => array("long" => 3, "integer" => 5, "short" => 8, "byte" => 10, "double" => 20, "float" => 66, "half_float" => 12, "scaled_float" => 21),
|
lang('Numbers') => array("long" => 3, "integer" => 5, "short" => 8, "byte" => 10, "double" => 20, "float" => 66, "half_float" => 12, "scaled_float" => 21),
|
||||||
lang('Date and time') => array("date" => 10),
|
lang('Date and time') => array("date" => 10),
|
||||||
@@ -491,10 +547,11 @@ if (isset($_GET["elastic"])) {
|
|||||||
$types += $val;
|
$types += $val;
|
||||||
$structured_types[$key] = array_keys($val);
|
$structured_types[$key] = array_keys($val);
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'possible_drivers' => array("json + allow_url_fopen"),
|
'possible_drivers' => array("json + allow_url_fopen"),
|
||||||
'jush' => "elastic",
|
'jush' => "elastic",
|
||||||
'operators' => array("=", "query"),
|
'operators' => array("=", "must", "should", "must_not"),
|
||||||
'functions' => array(),
|
'functions' => array(),
|
||||||
'grouping' => array(),
|
'grouping' => array(),
|
||||||
'edit_functions' => array(array("json")),
|
'edit_functions' => array(array("json")),
|
Reference in New Issue
Block a user