diff --git a/.ci/test-matrix.yml b/.ci/test-matrix.yml index 218896925..f7d6c0e19 100644 --- a/.ci/test-matrix.yml +++ b/.ci/test-matrix.yml @@ -1,7 +1,7 @@ --- STACK_VERSION: - - 7.x-SNAPSHOT - + - 7.9.2 + PHP_VERSION: - 7.4-cli - 7.3-cli diff --git a/CHANGELOG.md b/CHANGELOG.md index 48823b366..57a8f292d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## Release 7.9.1 + +- Fixed using object instead of array in onFailure transport event + [#1066](https://github.com/elastic/elasticsearch-php/pull/1066) +- Fixed reset custom header after endpoint call + [#1065](https://github.com/elastic/elasticsearch-php/pull/1065) +- Show generic error messages when server returns no response + [#1056](https://github.com/elastic/elasticsearch-php/pull/1056) + ## Release 7.9.0 - Updated endpoints and namespaces for Elasticsearch 7.9 diff --git a/util/ActionTest.php b/util/ActionTest.php index 9506cb666..59a59eb73 100644 --- a/util/ActionTest.php +++ b/util/ActionTest.php @@ -47,6 +47,10 @@ class ActionTest const TEMPLATE_SET_VARIABLE = __DIR__ . '/template/test/set-variable'; const TEMPLATE_TRANSFORM_AND_SET = __DIR__ . '/template/test/transform-and-set'; const TEMPLATE_WARNINGS = __DIR__ . '/template/test/warnings'; + const TEMPLATE_GT = __DIR__ . '/template/test/gt'; + const TEMPLATE_GTE = __DIR__ . '/template/test/gte'; + const TEMPLATE_LT = __DIR__ . '/template/test/lt'; + const TEMPLATE_LTE = __DIR__ . '/template/test/lte'; const TAB14 = ' '; const SUPPORTED_FEATURES = ['xpack', 'no_xpack', 'headers', 'node_selector', 'warnings', 'catch_unauthorized', 'transform_and_set']; @@ -324,6 +328,42 @@ private function teardown(array $actions) return $this->do($actions); } + private function gt(array $actions) + { + $key = key($actions); + return YamlTests::render(self::TEMPLATE_GT, [ + ':expected' => $actions[$key], + ':value' => $this->convertResponseField($key) + ]); + } + + private function gte(array $actions) + { + $key = key($actions); + return YamlTests::render(self::TEMPLATE_GTE, [ + ':expected' => $actions[$key], + ':value' => $this->convertResponseField($key) + ]); + } + + private function lt(array $actions) + { + $key = key($actions); + return YamlTests::render(self::TEMPLATE_LT, [ + ':expected' => $actions[$key], + ':value' => $this->convertResponseField($key) + ]); + } + + private function lte(array $actions) + { + $key = key($actions); + return YamlTests::render(self::TEMPLATE_LTE, [ + ':expected' => $actions[$key], + ':value' => $this->convertResponseField($key) + ]); + } + /** * ---------- FEATURE FUNCTIONS (END) ---------- */ diff --git a/util/GenerateEndpoints.php b/util/GenerateEndpoints.php index 5a82c8593..265696d4c 100644 --- a/util/GenerateEndpoints.php +++ b/util/GenerateEndpoints.php @@ -19,40 +19,42 @@ use Elasticsearch\Util\ClientEndpoint; use Elasticsearch\Util\Endpoint; use Elasticsearch\Util\NamespaceEndpoint; +use Elasticsearch\Tests\Utility; require_once dirname(__DIR__) . '/vendor/autoload.php'; + + +removeDirectory(__DIR__ . '/../src/Elasticsearch/Endpoints', [ + __DIR__ . '/../src/Elasticsearch/Endpoints/AbstractEndpoint.php', +]); +removeDirectory(__DIR__ . '/../src/Elasticsearch/Namespaces', [ + __DIR__ . '/../src/Elasticsearch/Namespaces/AbstractNamespace.php', + __DIR__ . '/../src/Elasticsearch/Namespaces/BooleanRequestWrapper.php', + __DIR__ . '/../src/Elasticsearch/Namespaces/NamespaceBuilderInterface.php' +]); + +die(); +printf ("Generating endpoints for Elasticsearch\n"); +printf ("---\n"); + $start = microtime(true); -if (!isset($argv[1])) { - print_usage_msg(); - exit(1); -} -if ($argv[1] < '7.3.0') { - printf("Error: the version must be >= 7.4.0\n"); + +$client = Utility::getClient(); + +$serverInfo = $client->info(); +$version = $serverInfo['version']['number']; +$buildHash = $serverInfo['version']['build_hash']; + +if (version_compare($version, '7.4.0', '<')) { + printf("Error: the ES version must be >= 7.4.0\n"); exit(1); } -$ver = $argv[1]; -$version = 'v' . $ver; - $gitWrapper = new GitWrapper(); $git = $gitWrapper->workingCopy(dirname(__DIR__) . '/util/elasticsearch'); -$git->run('fetch', ['--all']); -$tags = explode("\n", $git->run('tag')); -if (!in_array($version, $tags)) { - $branches = explode("\n", $git->run('branch', ['-r'])); - array_walk($branches, function(&$value, &$key) { - $value = trim($value); - }); - $version = "origin/$ver"; - if (!in_array($version, $branches)) { - printf("Error: the version %s specified doesnot exist\n", $version); - exit(1); - } -} - -$git->run('checkout', [$version]); +$git->run('checkout', [$buildHash]); $result = $git->run( 'ls-files', [ @@ -61,7 +63,7 @@ ] ); $files = explode("\n", $result); -$outputDir = __DIR__ . "/output/$ver"; +$outputDir = __DIR__ . "/output/$version"; // Remove the output directory printf ("Removing %s folder\n", $outputDir); @@ -82,7 +84,7 @@ } printf("Generation %s...", basename($file)); - $endpoint = new Endpoint($file, $git->run('show', [':' . trim($file)]), $ver); + $endpoint = new Endpoint($file, $git->run('show', [':' . trim($file)]), $version); $dir = $endpointDir . NamespaceEndpoint::normalizeName($endpoint->namespace); if (!file_exists($dir)) { @@ -109,7 +111,7 @@ foreach ($namespaces as $name => $endpoints) { if (empty($name)) { - $clientEndpoint = new ClientEndpoint(array_keys($namespaces), $ver); + $clientEndpoint = new ClientEndpoint(array_keys($namespaces), $version); foreach ($endpoints as $ep) { $clientEndpoint->addEndpoint($ep); } @@ -120,7 +122,7 @@ $countNamespace++; continue; } - $namespace = new NamespaceEndpoint($name, $ver); + $namespace = new NamespaceEndpoint($name, $version); foreach ($endpoints as $ep) { $namespace->addEndpoint($ep); } @@ -131,9 +133,24 @@ $countNamespace++; } +# Clean $end = microtime(true); printf("\nGenerated %d endpoints and %d namespaces in %.3f seconds\n.", $countEndpoint, $countNamespace, $end - $start); +printf ("---\n"); + +printf("Backup Endpoints and Namespaces in /src"); +$file = Client::Version; + +$zip = new ZipArchive(); +$ret = $zip->open('application.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE); +if ($ret !== TRUE) { + printf('Failed with code %d', $ret); +} else { + $options = array('add_path' => 'sources/', 'remove_all_path' => TRUE); + $zip->addGlob('*.{php,txt}', GLOB_BRACE, $options); + $zip->close(); +} // End function print_usage_msg(): void @@ -143,17 +160,41 @@ function print_usage_msg(): void } // Remove directory recursively -function removeDirectory($directory) +function removeDirectory($directory, array $omit = []) { foreach(glob("{$directory}/*") as $file) { if(is_dir($file)) { - removeDirectory($file); + if (!in_array($file, $omit)) { + //removeDirectory($file); + printf("Elimino directory %s\n", $file); + } } else { - unlink($file); + if (!in_array($file, $omit)) { + //unlink($file); + printf("Elimino file %s\n", $file); + } } } - if (is_dir($directory)) { - rmdir($directory); + if (is_dir($directory) && empty($omit)) { + //rmdir($directory); + printf("Elimino directory %s\n", $directory); } -} \ No newline at end of file +} + +# Copy files and directory recursively +function copyAll(string $src, string $dst) { + $dir = opendir($src); + @mkdir($dst); + while(false !== ( $file = readdir($dir)) ) { + if (( $file != '.' ) && ( $file != '..' )) { + if ( is_dir($src . '/' . $file) ) { + copyAll($src . '/' . $file, $dst . '/' . $file); + } + else { + copy($src . '/' . $file, $dst . '/' . $file); + } + } + } + closedir($dir); +} \ No newline at end of file diff --git a/util/elasticsearch b/util/elasticsearch index a6dca577e..69e72656f 160000 --- a/util/elasticsearch +++ b/util/elasticsearch @@ -1 +1 @@ -Subproject commit a6dca577e5a021653e93fb7d4611a04bb24a3222 +Subproject commit 69e72656faa528699ba517b9c38904c3e2958d31