]> git.joonet.de Git - adminer.git/commitdiff
Elasticsearch: Make it work with Elasticsearch 8
authorJakub Vrana <jakub@vrana.cz>
Fri, 28 Mar 2025 15:17:41 +0000 (16:17 +0100)
committerJakub Vrana <jakub@vrana.cz>
Fri, 28 Mar 2025 16:43:11 +0000 (17:43 +0100)
CHANGELOG.md
adminer/include/functions.inc.php
plugins/drivers/elastic.php
tests/elastic.html [new file with mode: 0644]
tests/generate-pdo.php

index ef8f4e775e23abdf36bcd20f7c9f50bc876e1998..290c1f86c1c2d74300ebcc0ef38902aedd76746e 100644 (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)
index 58db6475f5013a3dedb5b91385b6aa4bf9b93dfb..947d0775a885493f432d18209f9ea99399f54a18 100644 (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);
index 859256c7326141ca0db3679bdea5bc49a92f7ae9..b1ed0f84727655861cbcfc613b684f947be1529f 100644 (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(
-                                       '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,
-                               ))));
+                               $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) {
-                       $field_name = trim($f[1][0]);
-                       $field_type = trim($f[1][1] ?: "text");
-                       $properties[$field_name] = array(
-                               'type' => $field_type
-                       );
+                       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
diff --git a/tests/elastic.html b/tests/elastic.html
new file mode 100644 (file)
index 0000000..f0cf393
--- /dev/null
@@ -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>
index 5811301cfa91ff0dd79a68d96173c33dcba5fea6..4f65d308bd19ff0537279d49197ce24a715b1371 100755 (executable)
@@ -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;" : "");