2021-04-03 12:35:58 +02:00
|
|
|
<?php
|
2021-09-19 00:41:09 +02:00
|
|
|
add_driver("elastic", "Elasticsearch 7 (beta)");
|
2021-04-03 12:35:58 +02:00
|
|
|
|
2021-09-19 00:41:09 +02:00
|
|
|
if (isset($_GET["elastic"])) {
|
|
|
|
|
define("DRIVER", "elastic");
|
2021-04-03 12:35:58 +02:00
|
|
|
|
2021-09-19 00:41:09 +02:00
|
|
|
if (ini_bool('allow_url_fopen')) {
|
2021-04-03 23:40:45 +02:00
|
|
|
define("ELASTIC_DB_NAME", "elastic");
|
|
|
|
|
|
2021-04-03 12:35:58 +02:00
|
|
|
class Min_DB {
|
2021-04-03 23:40:45 +02:00
|
|
|
var $extension = "JSON", $server_info, $errno, $error, $_url;
|
2021-04-03 12:35:58 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $path
|
|
|
|
|
* @param array|null $content
|
|
|
|
|
* @param string $method
|
|
|
|
|
* @return array|false
|
|
|
|
|
*/
|
|
|
|
|
function rootQuery($path, array $content = null, $method = 'GET') {
|
|
|
|
|
$file = @file_get_contents("$this->_url/" . ltrim($path, '/'), false, stream_context_create(array('http' => array(
|
|
|
|
|
'method' => $method,
|
|
|
|
|
'content' => $content !== null ? json_encode($content) : null,
|
2025-02-17 15:48:23 +01:00
|
|
|
'header' => $content !== null ? 'Content-Type: application/json' : array(),
|
2021-04-03 12:35:58 +02:00
|
|
|
'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'];
|
2021-04-03 23:40:45 +02:00
|
|
|
} elseif (isset($return['status']) && isset($return['error']) && is_string($return['error'])) {
|
|
|
|
|
$this->error = $return['error'];
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
2021-04-03 23:40:45 +02:00
|
|
|
|
2021-04-03 12:35:58 +02:00
|
|
|
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)) {
|
2025-02-19 13:14:35 +01:00
|
|
|
$driver = get_driver();
|
2021-04-03 12:35:58 +02:00
|
|
|
|
|
|
|
|
$where = explode(" AND ", $matches[2]);
|
|
|
|
|
|
|
|
|
|
return $driver->select($matches[1], array("*"), $where, null, array(), $matches[3]);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
return $this->rootQuery($path, $content, $method);
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $server
|
|
|
|
|
* @param string $username
|
|
|
|
|
* @param string $password
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function connect($server, $username, $password) {
|
2025-02-18 07:58:27 +01:00
|
|
|
preg_match('~^(https?://)?(.*)~', $server, $match);
|
|
|
|
|
$this->_url = ($match[1] ? $match[1] : "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]";
|
2021-04-03 12:35:58 +02:00
|
|
|
$return = $this->query('');
|
2025-02-18 07:58:27 +01:00
|
|
|
if ($return) {
|
|
|
|
|
$this->server_info = $return['version']['number'];
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
2025-02-18 07:58:27 +01:00
|
|
|
return (bool) $return;
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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("*")) {
|
2024-08-25 22:14:35 +02:00
|
|
|
$data["fields"] = array_values($select);
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-28 14:32:23 +01:00
|
|
|
$fields = null;
|
2021-04-03 12:35:58 +02:00
|
|
|
foreach ($where as $val) {
|
|
|
|
|
if (preg_match('~^\((.+ OR .+)\)$~', $val, $matches)) {
|
|
|
|
|
$parts = explode(" OR ", $matches[1]);
|
|
|
|
|
$terms = array();
|
2025-02-28 14:32:23 +01:00
|
|
|
|
|
|
|
|
if ($fields === null) {
|
|
|
|
|
$fields = fields($table);
|
|
|
|
|
}
|
2021-04-03 12:35:58 +02:00
|
|
|
foreach ($parts as $part) {
|
|
|
|
|
list($col, $op, $val) = explode(" ", $part, 3);
|
|
|
|
|
$term = array($col => $val);
|
2025-02-28 14:32:23 +01:00
|
|
|
if (isset($fields[$col]) && $fields[$col]['full_type'] == 'boolean'
|
|
|
|
|
&& $val !== 'true' && $val !== 'false'
|
|
|
|
|
) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-04-03 12:35:58 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
$query = "$table/_search";
|
2021-04-03 12:35:58 +02:00
|
|
|
$start = microtime(true);
|
2021-04-03 23:40:45 +02:00
|
|
|
$search = $this->_conn->rootQuery($query, $data);
|
2021-04-03 12:35:58 +02:00
|
|
|
|
|
|
|
|
if ($print) {
|
2021-09-19 00:41:09 +02:00
|
|
|
echo adminer()->selectQuery("$query: " . json_encode($data), $start, !$search);
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
2021-04-03 23:40:45 +02:00
|
|
|
if (empty($search)) {
|
2021-04-03 12:35:58 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$return = array();
|
2021-04-03 23:40:45 +02:00
|
|
|
foreach ($search["hits"]["hits"] as $hit) {
|
2021-04-03 12:35:58 +02:00
|
|
|
$row = array();
|
|
|
|
|
if ($select == array("*")) {
|
|
|
|
|
$row["_id"] = $hit["_id"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($select != array("*")) {
|
|
|
|
|
$fields = array();
|
|
|
|
|
foreach ($select as $key) {
|
2021-04-03 23:40:45 +02:00
|
|
|
$fields[$key] = $key == "_id" ? $hit["_id"] : $hit["_source"][$key];
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
2021-04-03 23:40:45 +02:00
|
|
|
} else {
|
|
|
|
|
$fields = $hit["_source"];
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
foreach ($fields as $key => $val) {
|
2021-04-03 23:40:45 +02:00
|
|
|
$row[$key] = (is_array($val) ? json_encode($val) : $val);
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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'];
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
function delete($table, $queryWhere, $limit = 0) {
|
2021-04-03 12:35:58 +02:00
|
|
|
//! 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) {
|
2021-04-03 23:40:45 +02:00
|
|
|
$query = "$table/_doc/$id";
|
2021-04-03 12:35:58 +02:00
|
|
|
$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;
|
|
|
|
|
|
2021-09-19 00:41:09 +02:00
|
|
|
list($server, $username, $password) = adminer()->credentials();
|
2025-02-18 07:58:27 +01:00
|
|
|
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
|
|
|
|
|
return lang('Invalid server.');
|
|
|
|
|
}
|
2021-04-03 12:35:58 +02:00
|
|
|
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) {
|
2021-04-03 23:40:45 +02:00
|
|
|
return preg_match("~table|columns~", $feature);
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function logged_user() {
|
2021-09-19 00:41:09 +02:00
|
|
|
$credentials = adminer()->credentials();
|
2021-04-03 12:35:58 +02:00
|
|
|
|
|
|
|
|
return $credentials[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_databases() {
|
2021-04-03 23:40:45 +02:00
|
|
|
return array(ELASTIC_DB_NAME);
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
2021-09-19 00:41:09 +02:00
|
|
|
$return = connection()->rootQuery('_aliases');
|
2021-04-03 23:40:45 +02:00
|
|
|
if (empty($return)) {
|
|
|
|
|
return array(
|
|
|
|
|
ELASTIC_DB_NAME => 0
|
|
|
|
|
);
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
return array(
|
|
|
|
|
ELASTIC_DB_NAME => count($return)
|
|
|
|
|
);
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tables_list() {
|
2021-09-19 00:41:09 +02:00
|
|
|
$aliases = connection()->rootQuery('_aliases');
|
2021-04-03 23:40:45 +02:00
|
|
|
if (empty($aliases)) {
|
|
|
|
|
return array();
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
ksort($aliases);
|
|
|
|
|
|
|
|
|
|
$tables = array();
|
|
|
|
|
foreach ($aliases as $name => $index) {
|
|
|
|
|
$tables[$name] = "table";
|
|
|
|
|
|
|
|
|
|
ksort($index["aliases"]);
|
|
|
|
|
$tables += array_fill_keys(array_keys($index["aliases"]), "view");
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
return $tables;
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function table_status($name = "", $fast = false) {
|
2021-09-19 00:41:09 +02:00
|
|
|
$stats = connection()->rootQuery('_stats');
|
|
|
|
|
$aliases = connection()->rootQuery('_aliases');
|
2021-04-03 23:40:45 +02:00
|
|
|
|
|
|
|
|
if (empty($stats) || empty($aliases)) {
|
|
|
|
|
return array();
|
|
|
|
|
}
|
2021-04-03 12:35:58 +02:00
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
$result = array();
|
|
|
|
|
|
|
|
|
|
if ($name != "") {
|
|
|
|
|
if (isset($stats["indices"][$name])) {
|
|
|
|
|
return format_index_status($name, $stats["indices"][$name]);
|
2025-03-05 09:14:49 +01:00
|
|
|
} 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]);
|
|
|
|
|
}
|
2021-04-03 23:40:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-03 12:35:58 +02:00
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
ksort($stats["indices"]);
|
|
|
|
|
foreach ($stats["indices"] as $name => $index) {
|
|
|
|
|
if ($name[0] == ".") {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-04-03 12:35:58 +02:00
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
$result[$name] = format_index_status($name, $index);
|
2021-04-03 12:35:58 +02:00
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
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]);
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
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";
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function error() {
|
2021-09-19 00:41:09 +02:00
|
|
|
return h(connection()->error);
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function information_schema() {
|
2021-04-03 23:40:45 +02:00
|
|
|
//
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function indexes($table, $connection2 = null) {
|
|
|
|
|
return array(
|
|
|
|
|
array("type" => "PRIMARY", "columns" => array("_id")),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fields($table) {
|
|
|
|
|
$mappings = array();
|
2021-09-19 00:41:09 +02:00
|
|
|
$mapping = connection()->rootQuery("_mapping");
|
2021-04-03 12:35:58 +02:00
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
if (!isset($mapping[$table])) {
|
2021-09-19 00:41:09 +02:00
|
|
|
$aliases = connection()->rootQuery('_aliases');
|
2021-04-03 23:40:45 +02:00
|
|
|
|
|
|
|
|
foreach ($aliases as $index_name => $index) {
|
|
|
|
|
foreach ($index["aliases"] as $alias_name => $alias) {
|
|
|
|
|
if ($alias_name == $table) {
|
|
|
|
|
$table = $index_name;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
if (!empty($mapping)) {
|
|
|
|
|
$mappings = $mapping[$table]["mappings"]["properties"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = array(
|
2021-04-03 12:35:58 +02:00
|
|
|
"_id" => array(
|
|
|
|
|
"field" => "_id",
|
|
|
|
|
"full_type" => "text",
|
|
|
|
|
"type" => "text",
|
|
|
|
|
"privileges" => array("insert" => 1, "select" => 1, "where" => 1, "order" => 1),
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
foreach ($mappings as $name => $field) {
|
2021-04-03 23:40:45 +02:00
|
|
|
$has_index = !isset($field["index"]) || $field["index"];
|
|
|
|
|
|
|
|
|
|
// TODO: privileges: where => $has_index
|
|
|
|
|
// TODO: privileges: sort => $field["type"] != "text"
|
2021-04-03 12:35:58 +02:00
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
$result[$name] = array(
|
2021-04-03 12:35:58 +02:00
|
|
|
"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
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 23:40:45 +02:00
|
|
|
return $result;
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-21 10:57:11 +01:00
|
|
|
return connection()->query("_mapping/$name", $properties, 'PUT');
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Drop types
|
|
|
|
|
* @param array
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
function drop_tables($tables) {
|
|
|
|
|
$return = true;
|
|
|
|
|
foreach ($tables as $table) { //! convert to bulk api
|
2021-09-19 00:41:09 +02:00
|
|
|
$return = $return && connection()->query(urlencode($table), null, 'DELETE');
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function last_id() {
|
2021-09-19 00:41:09 +02:00
|
|
|
return connection()->last_id;
|
2021-04-03 12:35:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|