1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-05 14:17:26 +02:00

Elasticsearch: Make it work with Elasticsearch 8

This commit is contained in:
Jakub Vrana
2025-03-28 16:17:41 +01:00
parent bd823716fc
commit 2396397b75
5 changed files with 141 additions and 20 deletions

View File

@@ -1,5 +1,6 @@
## Adminer dev
Export: Fix tar (regression from 5.0.3)
Elasticsearch: Make it work with Elasticsearch 8
CSS: Invert icons in dark mode
## Adminer 5.1.0 (released 2025-03-24)

View File

@@ -438,8 +438,10 @@ function redirect(?string $location, string $message = null): void {
}
}
/** Execute query and redirect if successful */
function query_redirect(string $query, string $location, string $message, bool $redirect = true, bool $execute = true, bool $failed = false, string $time = ""): bool {
/** Execute query and redirect if successful
* @param bool $redirect
*/
function query_redirect(string $query, string $location, string $message, $redirect = true, bool $execute = true, bool $failed = false, string $time = ""): bool {
global $connection, $error, $adminer;
if ($execute) {
$start = microtime(true);

View File

@@ -16,14 +16,17 @@ if (isset($_GET["elastic"])) {
* @return array|false
*/
function rootQuery(string $path, ?array $content = null, string $method = 'GET') {
$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(
//~ 'ssl' => array('verify_peer' => false),
'http' => array(
'method' => $method,
'content' => $content !== null ? json_encode($content) : null,
'header' => $content !== null ? 'Content-Type: application/json' : array(),
'ignore_errors' => 1,
'follow_location' => 0,
'max_redirects' => 0,
))));
),
)));
if ($file === false) {
$this->error = lang('Invalid server or credentials.');
@@ -219,9 +222,9 @@ if (isset($_GET["elastic"])) {
$parts = preg_split('~ *= *~', $queryWhere);
if (count($parts) == 2) {
$id = trim($parts[1]);
$query = "$type/$id";
return $this->conn->rootQuery($query, $record, 'POST');
$query = "$table/_update/$id";
$this->conn->affected_rows = 0;
return $this->conn->rootQuery($query, array('doc' => $set), 'POST');
}
return false;
@@ -518,18 +521,24 @@ if (isset($_GET["elastic"])) {
function alter_table(string $table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
$properties = array();
foreach ($fields as $f) {
if ($f[1]) {
$field_name = trim($f[1][0]);
$field_type = trim($f[1][1] ?: "text");
$properties[$field_name] = array(
'type' => $field_type
);
}
}
if (!empty($properties)) {
$properties = array('properties' => $properties);
}
return connection()->rootQuery("_mapping/$name", $properties, 'PUT');
if ($table != '') {
return connection()->rootQuery("$name/_mapping", $properties, 'POST');
} else {
return connection()->rootQuery($name, array('mappings' => $properties), 'PUT');
}
}
/** Drop types

109
tests/elastic.html Normal file
View File

@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<title>Katalon Elasticsearch</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead><tr><td rowspan="1" colspan="3">Login</td></tr></thead>
<tbody>
<tr><td>open</td><td>/adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200</td><td></td></tr>
<tr><td>select</td><td>name=lang</td><td>label=English</td></tr>
<tr><td>clickAndWait</td><td>css=#lang &gt; input[type="submit"]</td><td></td></tr>
<tr><td>type</td><td>id=username</td><td>ODBC</td></tr>
<tr><td>type</td><td>name=auth[password]</td><td>ODBC12</td></tr>
<tr><td>clickAndWait</td><td>//input[@value='Login']</td><td></td></tr>
<tr><td>verifyTextPresent</td><td>JSON</td><td></td></tr>
</tbody></table>
<table cellpadding="1" cellspacing="1" border="1">
<thead><tr><td rowspan="1" colspan="3">Create table</td></tr></thead>
<tbody>
<tr><td>open</td><td>/adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&amp;username=ODBC&amp;db=elastic</td><td></td></tr>
<tr><td>clickAndWait</td><td>link=Create table</td><td></td></tr>
<tr><td>type</td><td>name</td><td>interprets</td></tr>
<tr><td>type</td><td>fields[1][field]</td><td>name</td></tr>
<tr><td>select</td><td>fields[1][type]</td><td>label=text</td></tr>
<tr><td>clickAndWait</td><td>//input[@value='Save']</td><td></td></tr>
<tr><td>verifyTextPresent</td><td>Table has been created.</td><td></td></tr>
</tbody></table>
<table cellpadding="1" cellspacing="1" border="1">
<thead><tr><td rowspan="1" colspan="3">Alter table</td></tr></thead>
<tbody>
<tr><td>open</td><td>/adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&amp;username=ODBC&amp;db=elastic&amp;table=interprets</td><td></td></tr>
<tr><td>clickAndWait</td><td>link=Alter table</td><td></td></tr>
<tr><td>click</td><td>add[2]</td><td></td></tr>
<tr><td>type</td><td>fields[3][field]</td><td>albums</td></tr>
<tr><td>select</td><td>fields[3][type]</td><td>label=integer</td></tr>
<tr><td>clickAndWait</td><td>//input[@value='Save']</td><td></td></tr>
<tr><td>verifyTextPresent</td><td>Table has been altered.</td><td></td></tr>
</tbody></table>
<table cellpadding="1" cellspacing="1" border="1">
<thead><tr><td rowspan="1" colspan="3">Insert</td></tr></thead>
<tbody>
<tr><td>open</td><td>/adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&amp;username=ODBC&amp;db=elastic&amp;edit=interprets</td><td></td></tr>
<tr><td>type</td><td>fields[name]</td><td>Michael Jackson</td></tr>
<tr><td>clickAndWait</td><td>//input[@value='Save']</td><td></td></tr>
<tr><td>verifyTextPresent</td><td>has been inserted.</td><td></td></tr>
</tbody></table>
<table cellpadding="1" cellspacing="1" border="1">
<thead><tr><td rowspan="1" colspan="3">Select</td></tr></thead>
<tbody>
<tr><td>open</td><td>/adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&amp;username=ODBC&amp;db=elastic&amp;select=interprets</td><td></td></tr>
<tr><td>click</td><td>link=Search</td><td></td></tr>
<tr><td>select</td><td>name=where[0][col]</td><td>label=name</td></tr>
<tr><td>select</td><td>name=where[0][op]</td><td>label=should</td></tr>
<tr><td>type</td><td>name=where[0][val]</td><td>Jackson</td></tr>
<tr><td>click</td><td>link=Sort</td><td></td></tr>
<tr><td>select</td><td>name=order[0]</td><td>label=albums</td></tr>
<tr><td>clickAndWait</td><td>xpath=//input[@value='Select']</td><td></td></tr>
<tr><td>verifyTextPresent</td><td>1 row</td><td></td></tr>
</tbody></table>
<table cellpadding="1" cellspacing="1" border="1">
<thead><tr><td rowspan="1" colspan="3">Update</td></tr></thead>
<tbody>
<tr><td>open</td><td>/adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&amp;username=ODBC&amp;db=elastic&amp;select=interprets</td><td></td></tr>
<tr><td>clickAndWait</td><td>link=edit</td><td></td></tr>
<tr><td>type</td><td>fields[albums]</td><td>1</td></tr>
<tr><td>clickAndWait</td><td>//input[@value='Save']</td><td></td></tr>
<tr><td>verifyTextPresent</td><td>Item has been updated.</td><td></td></tr>
</tbody></table>
<table cellpadding="1" cellspacing="1" border="1">
<thead><tr><td rowspan="1" colspan="3">Delete</td></tr></thead>
<tbody>
<tr><td>open</td><td>/adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&amp;username=ODBC&amp;db=elastic&amp;select=interprets</td><td></td></tr>
<tr><td>click</td><td>name=check[]</td><td></td></tr>
<tr><td>waitForChecked</td><td>name=check[]</td><td></td></tr>
<tr><td>chooseOkOnNextConfirmation</td><td>Are you sure?</td><td></td></tr>
<tr><td>click</td><td>delete</td><td></td></tr>
<tr><td>verifyTextPresent</td><td>1 item has been affected.</td><td></td></tr>
</tbody></table>
<table cellpadding="1" cellspacing="1" border="1">
<thead><tr><td rowspan="1" colspan="3">Drop</td></tr></thead>
<tbody>
<tr><td>open</td><td>/adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&amp;username=ODBC&amp;db=elastic&amp;create=interprets</td><td></td></tr>
<tr><td>chooseOkOnNextConfirmation</td><td>Drop interprets?</td><td></td></tr>
<tr><td>click</td><td>name=drop</td><td></td></tr>
<tr><td>verifyTextPresent</td><td>No tables.</td><td></td></tr>
</tbody></table>
<table cellpadding="1" cellspacing="1" border="1">
<thead><tr><td rowspan="1" colspan="3">Logout</td></tr></thead>
<tbody>
<tr><td>open</td><td>/adminer/elastic.php?elastic=https%3A%2F%2Flocalhost:9200&amp;username=ODBC</td><td></td></tr>
<tr><td>clickAndWait</td><td>logout</td><td></td></tr>
<tr><td>verifyTextPresent</td><td>Logout successful.</td><td></td></tr>
<tr><td>open</td><td>/coverage.php</td><td></td></tr>
</tbody></table>
</body>
</html>

View File

@@ -5,7 +5,7 @@
chdir(__DIR__);
foreach (glob("*.html") as $filename) {
if (!preg_match('~^pdo-~', $filename)) {
if (!preg_match('~^pdo-|elastic~', $filename)) {
$file = file_get_contents($filename);
$file = preg_replace_callback('~/(adminer(/sqlite)?|editor/example)\.php(\??)~', function ($match) {
return "/$match[1].php?ext=pdo" . ($match[3] ? "&amp;" : "");