mirror of
https://github.com/vrana/adminer.git
synced 2025-08-10 00:28:34 +02:00
Improve code readability by using of empty lines
This commit is contained in:
@@ -16,6 +16,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
*/
|
*/
|
||||||
function rootQuery($path, $content = array(), $method = 'GET') {
|
function rootQuery($path, $content = array(), $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 ? $content : json_encode($content),
|
'content' => $content === null ? $content : json_encode($content),
|
||||||
@@ -65,6 +66,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
|
|
||||||
return $driver->select($matches[1], array("*"), $where, null, array(), $matches[3]);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,13 +82,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 {
|
||||||
@@ -95,12 +97,14 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,22 +113,19 @@ if (isset($_GET["elastic"])) {
|
|||||||
|
|
||||||
return $row ? array_values($row) : false;
|
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;
|
global $adminer;
|
||||||
|
|
||||||
$data = array();
|
$data = array();
|
||||||
$query = (min_version(7) ? "" : "$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) {
|
||||||
@@ -133,12 +134,14 @@ 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) {
|
||||||
if (preg_match('~^\((.+ OR .+)\)$~', $val, $matches)) {
|
if (preg_match('~^\((.+ OR .+)\)$~', $val, $matches)) {
|
||||||
$parts = explode(" OR ", $matches[1]);
|
$parts = explode(" OR ", $matches[1]);
|
||||||
@@ -166,20 +169,25 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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();
|
||||||
@@ -187,14 +195,17 @@ if (isset($_GET["elastic"])) {
|
|||||||
$fields[$key] = $key == "_id" ? [$hit["_id"]] : $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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,8 +215,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,6 +227,7 @@ 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'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,7 +245,9 @@ 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, null, 'DELETE');
|
$response = $this->_conn->query($query, null, 'DELETE');
|
||||||
@@ -239,6 +255,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
$this->_conn->affected_rows++;
|
$this->_conn->affected_rows++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_conn->affected_rows;
|
return $this->_conn->affected_rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,18 +264,20 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
global $adminer;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,17 +287,21 @@ if (isset($_GET["elastic"])) {
|
|||||||
|
|
||||||
function logged_user() {
|
function logged_user() {
|
||||||
global $adminer;
|
global $adminer;
|
||||||
|
|
||||||
$credentials = $adminer->credentials();
|
$credentials = $adminer->credentials();
|
||||||
|
|
||||||
return $credentials[1];
|
return $credentials[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_databases() {
|
function get_databases() {
|
||||||
global $connection;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,6 +314,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function db_collation($db, $collations) {
|
function db_collation($db, $collations) {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
function engines() {
|
function engines() {
|
||||||
@@ -299,8 +323,10 @@ if (isset($_GET["elastic"])) {
|
|||||||
|
|
||||||
function count_tables($databases) {
|
function count_tables($databases) {
|
||||||
global $connection;
|
global $connection;
|
||||||
$return = array();
|
|
||||||
$result = $connection->query('_stats');
|
$result = $connection->query('_stats');
|
||||||
|
|
||||||
|
$return = array();
|
||||||
if ($result && $result['indices']) {
|
if ($result && $result['indices']) {
|
||||||
$indices = $result['indices'];
|
$indices = $result['indices'];
|
||||||
foreach ($indices as $indice => $stats) {
|
foreach ($indices as $indice => $stats) {
|
||||||
@@ -308,6 +334,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
$return[$indice] = $indexing['index_total'];
|
$return[$indice] = $indexing['index_total'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,11 +349,13 @@ if (isset($_GET["elastic"])) {
|
|||||||
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;
|
global $connection;
|
||||||
|
|
||||||
$search = $connection->query("_search", array(
|
$search = $connection->query("_search", array(
|
||||||
"size" => 0,
|
"size" => 0,
|
||||||
"aggregations" => array(
|
"aggregations" => array(
|
||||||
@@ -337,25 +366,31 @@ 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;
|
global $connection;
|
||||||
|
|
||||||
return h($connection->error);
|
return h($connection->error);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,6 +410,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
global $connection;
|
global $connection;
|
||||||
|
|
||||||
$mappings = array();
|
$mappings = array();
|
||||||
|
|
||||||
if (min_version(7)) {
|
if (min_version(7)) {
|
||||||
$result = $connection->query("_mapping");
|
$result = $connection->query("_mapping");
|
||||||
if ($result) {
|
if ($result) {
|
||||||
@@ -417,6 +453,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,6 +470,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function convert_field($field) {
|
function convert_field($field) {
|
||||||
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
function unconvert_field($field, $return) {
|
function unconvert_field($field, $return) {
|
||||||
@@ -440,6 +478,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) {
|
||||||
@@ -452,6 +491,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
*/
|
*/
|
||||||
function create_database($db) {
|
function create_database($db) {
|
||||||
global $connection;
|
global $connection;
|
||||||
|
|
||||||
return $connection->rootQuery(urlencode($db), null, 'PUT');
|
return $connection->rootQuery(urlencode($db), null, 'PUT');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,6 +501,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
*/
|
*/
|
||||||
function drop_databases($databases) {
|
function drop_databases($databases) {
|
||||||
global $connection;
|
global $connection;
|
||||||
|
|
||||||
return $connection->rootQuery(urlencode(implode(',', $databases)), null, 'DELETE');
|
return $connection->rootQuery(urlencode(implode(',', $databases)), null, 'DELETE');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,6 +511,7 @@ if (isset($_GET["elastic"])) {
|
|||||||
*/
|
*/
|
||||||
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;
|
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]);
|
||||||
@@ -478,9 +520,11 @@ 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');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -490,21 +534,25 @@ if (isset($_GET["elastic"])) {
|
|||||||
*/
|
*/
|
||||||
function drop_tables($tables) {
|
function drop_tables($tables) {
|
||||||
global $connection;
|
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), null, 'DELETE');
|
$return = $return && $connection->query(urlencode($table), null, 'DELETE');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function last_id() {
|
function last_id() {
|
||||||
global $connection;
|
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),
|
||||||
@@ -514,6 +562,7 @@ 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",
|
||||||
|
Reference in New Issue
Block a user