From 0a0d317dafdb900cda1836ae21a6b3008f2a356c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= Date: Tue, 4 Feb 2020 18:45:32 +0200 Subject: [PATCH 01/13] add es7 support --- .travis.yml | 4 +- Annotation/Index.php | 8 --- DependencyInjection/Compiler/MappingPass.php | 1 - Mapping/DocumentParser.php | 36 +--------- Mapping/IndexSettings.php | 22 +----- Resources/doc/commands.md | 6 +- Result/AbstractResultsIterator.php | 4 +- Service/ExportService.php | 2 +- Service/IndexService.php | 16 +---- Service/Json/JsonReader.php | 3 +- Tests/Functional/Annotation/DocumentTest.php | 6 -- Tests/Functional/Annotation/PropertyTest.php | 2 +- .../Command/IndexExportCommandTest.php | 16 ----- .../Command/IndexImportCommandTest.php | 65 +++++++++--------- .../Profiler/ElasticsearchProfilerTest.php | 2 - Tests/Unit/Event/BulkEventTest.php | 2 - Tests/Unit/Event/CommitEventTest.php | 1 - Tests/Unit/Mapping/DocumentParserTest.php | 12 ++-- .../Result/AbstractResultsIteratorTest.php | 3 - Tests/Unit/Result/DocumentIteratorTest.php | 1 - Tests/Unit/Result/RawIteratorTest.php | 1 - Tests/app/data_seed/command_import_10.json | 20 +++--- Tests/app/data_seed/command_import_10.json.gz | Bin 177 -> 0 bytes Tests/app/data_seed/command_import_11.json | 22 +++--- Tests/app/data_seed/command_import_11.json.gz | Bin 180 -> 0 bytes Tests/app/data_seed/command_import_20.json | 40 +++++------ Tests/app/data_seed/command_import_9.json | 18 ++--- Tests/app/data_seed/command_import_9.json.gz | Bin 167 -> 0 bytes composer.json | 6 +- 29 files changed, 102 insertions(+), 217 deletions(-) delete mode 100644 Tests/app/data_seed/command_import_10.json.gz delete mode 100644 Tests/app/data_seed/command_import_11.json.gz delete mode 100644 Tests/app/data_seed/command_import_9.json.gz diff --git a/.travis.yml b/.travis.yml index d95df8a0..55865b55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,10 @@ php: - 7.3 env: global: - - ES_VERSION=6.2.3 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz + - ES_VERSION=7.5.2 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz matrix: - SYMFONY="~3.4" - - SYMFONY="^4.1" + - SYMFONY="^4.4" install: - wget ${ES_DOWNLOAD_URL} - tar -xzf elasticsearch-${ES_VERSION}.tar.gz diff --git a/Annotation/Index.php b/Annotation/Index.php index d57db9e2..8cf3fadf 100644 --- a/Annotation/Index.php +++ b/Annotation/Index.php @@ -37,14 +37,6 @@ final class Index extends AbstractAnnotation public $numberOfReplicas = 1; - /** - * We strongly recommend to not use this parameter in the index annotation. By default it will be set as `_doc` - * type name. Eventually it will be removed. - * - * @deprecated will be removed in v7 since there will be no more types in the indexes. - */ - public $typeName = '_doc'; - /** * You can select one of your indexes to be default. Useful for cli commands when you don't * need to define an alias name. If default is not set the first index found will be set as default one. diff --git a/DependencyInjection/Compiler/MappingPass.php b/DependencyInjection/Compiler/MappingPass.php index dc739659..e0b8ee0f 100644 --- a/DependencyInjection/Compiler/MappingPass.php +++ b/DependencyInjection/Compiler/MappingPass.php @@ -93,7 +93,6 @@ private function handleDirectoryMapping(ContainerBuilder $container, string $dir $indexMetadata, $indexesOverride[$namespace]['hosts'] ?? $document->hosts, $indexesOverride[$namespace]['default'] ?? $document->default, - $indexesOverride[$namespace]['type'] ?? $document->typeName ] ); diff --git a/Mapping/DocumentParser.php b/Mapping/DocumentParser.php index b929bce2..fa1c2d88 100644 --- a/Mapping/DocumentParser.php +++ b/Mapping/DocumentParser.php @@ -72,17 +72,6 @@ public function getIndexAnnotation(\ReflectionClass $class) return $document; } - /** - * @deprecated will be deleted in v7. Types are deleted from elasticsearch. - */ - public function getTypeName(\ReflectionClass $class): string - { - /** @var Index $document */ - $document = $this->reader->getClassAnnotation($class, Index::class); - - return $document->typeName ?? '_doc'; - } - public function getIndexMetadata(\ReflectionClass $class): array { if ($class->isTrait()) { @@ -102,34 +91,11 @@ public function getIndexMetadata(\ReflectionClass $class): array return array_filter(array_map('array_filter', [ 'settings' => $settings, 'mappings' => [ - $this->getTypeName($class) => [ - 'properties' => array_filter($this->getClassMetadata($class)) - ] + 'properties' => array_filter($this->getClassMetadata($class)) ] ])); } - public function getDocumentNamespace(string $indexAlias): ?string - { - if ($this->cache->contains(Configuration::ONGR_INDEXES)) { - $indexes = $this->cache->fetch(Configuration::ONGR_INDEXES); - - if (isset($indexes[$indexAlias])) { - return $indexes[$indexAlias]; - } - } - - return null; - } - - public function getParsedDocument(\ReflectionClass $class): Index - { - /** @var Index $document */ - $document = $this->reader->getClassAnnotation($class, Index::class); - - return $document; - } - private function getClassMetadata(\ReflectionClass $class): array { $mapping = []; diff --git a/Mapping/IndexSettings.php b/Mapping/IndexSettings.php index 96af7549..81296fc9 100644 --- a/Mapping/IndexSettings.php +++ b/Mapping/IndexSettings.php @@ -19,21 +19,13 @@ class IndexSettings private $hosts; private $defaultIndex = false; - - - /** - * @deprecated will be removed in the v7 - */ - private $type; - public function __construct( string $namespace, string $indexName, string $alias, array $indexMetadata = [], array $hosts = [], - bool $defaultIndex = false, - $type = null + bool $defaultIndex = false ) { $this->namespace = $namespace; $this->indexName = $indexName; @@ -41,7 +33,6 @@ public function __construct( $this->indexMetadata = $indexMetadata; $this->hosts = $hosts; $this->defaultIndex = $defaultIndex; - $this->type = $type; } public function getNamespace() @@ -109,15 +100,4 @@ public function setDefaultIndex(bool $defaultIndex): self $this->defaultIndex = $defaultIndex; return $this; } - - public function getType() - { - return $this->type; - } - - public function setType($type): self - { - $this->type = $type; - return $this; - } } diff --git a/Resources/doc/commands.md b/Resources/doc/commands.md index 3b5b5efb..68afa492 100644 --- a/Resources/doc/commands.md +++ b/Resources/doc/commands.md @@ -53,8 +53,8 @@ So here's a simple example how the data looks like: [ {"count":2,"date":"2015-10-25T14:46:21+0200"}, - {"_type":"content","_id":"15","_source":{"id":"15","title":"About","content":"Sample ONGR about page..","urls":[{"url":"about\/","key":""}]}}, - {"_type":"content","_id":"37","_source":{"id":"37","title":"Home Page","content":"
\r\n

Welcome to ONGR demo site!<\/h1>\r\n

Enterprise E-commerce Accelerator.<\/p><\/div>","urls":[{"url":"home-page\/","key":""}]}} + {"_id":"15","_source":{"id":"15","title":"About","content":"Sample ONGR about page..","urls":[{"url":"about\/","key":""}]}}, + {"_id":"37","_source":{"id":"37","title":"Home Page","content":"

\r\n

Welcome to ONGR demo site!<\/h1>\r\n

Enterprise E-commerce Accelerator.<\/p><\/div>","urls":[{"url":"home-page\/","key":""}]}} ] ``` @@ -62,7 +62,6 @@ So here's a simple example how the data looks like: Every line of file is `JSON` object. First line must specify `count`, how many lines are in the files except first and the file timestamp in `date`. There is one document per line. There could be different types defined in a single file, basically with a single file you can import the whole index. There are 3 required keys: -* `_type` which specifies elasticsearch type name (not an ElasticsearchBundle class document) * `_id` is optional, if not specified (provided `null`) elasticsearch will create a random id for that document. * `_source`: document array encoded to json object, where all fields are equal to the elasticsearch type field names. @@ -78,7 +77,6 @@ Exports data from Elasticsearch index in a json format. |:-----------:|:----------------------------:|:--------------------------------------------------------------------------------------:| | `--manager` | *Manager name. e.g.* `default` | Used to select manager to create index for. If not specified, default manager is used. | | `--chunk` | *Chunk size, default 500* | Specifies the size of each chunk to be received from Elasticsearch. This can be changed for performance reasons. -| `--types` | *Elasticsearch index type names* | Selected types to export, if no specified will export all index. | `--split` | *Lines number* | This option indicates how many lines can be in single exported file. > Index export generates the same `JSON` format as specified in the import chapter. diff --git a/Result/AbstractResultsIterator.php b/Result/AbstractResultsIterator.php index 39061833..f7a84520 100644 --- a/Result/AbstractResultsIterator.php +++ b/Result/AbstractResultsIterator.php @@ -52,8 +52,8 @@ public function __construct( if (isset($rawData['hits']['hits'])) { $this->documents = $rawData['hits']['hits']; } - if (isset($rawData['hits']['total'])) { - $this->count = $rawData['hits']['total']; + if (isset($rawData['hits']['total']['value'])) { + $this->count = $rawData['hits']['total']['value']; } } diff --git a/Service/ExportService.php b/Service/ExportService.php index 5b927549..fba2949f 100644 --- a/Service/ExportService.php +++ b/Service/ExportService.php @@ -79,7 +79,7 @@ public function exportIndex( $counter = 0; } - $doc = array_intersect_key($data, array_flip(['_id', '_type', '_source'])); + $doc = array_intersect_key($data, array_flip(['_id', '_source'])); $writer->push($doc); $progress->advance(); $counter++; diff --git a/Service/IndexService.php b/Service/IndexService.php index a9cc924f..83aaf6da 100644 --- a/Service/IndexService.php +++ b/Service/IndexService.php @@ -62,14 +62,6 @@ public function getNamespace(): string return $this->namespace; } - /** - * @deprecated will be removed in v7 since there will be no more types in the indexes. - */ - public function getTypeName(): string - { - return $this->indexSettings->getType(); - } - public function getIndexSettings() { return $this->indexSettings; @@ -189,7 +181,6 @@ public function find($id, $params = []) { $requestParams = [ 'index' => $this->getIndexName(), - 'type' => $this->getTypeName(), 'id' => $id, ]; @@ -319,7 +310,6 @@ public function getIndexDocumentCount(): int { $body = [ 'index' => $this->getIndexName(), - 'type' => $this->getTypeName(), 'body' => [], ]; @@ -332,7 +322,6 @@ public function remove($id, $routing = null) { $params = [ 'index' => $this->getIndexName(), - 'type' => $this->getTypeName(), 'id' => $id, ]; @@ -358,7 +347,6 @@ public function update($id, array $fields = [], $script = null, array $params = [ 'id' => $id, 'index' => $this->getIndexName(), - 'type' => $this->getTypeName(), 'body' => $body, ], $params @@ -371,7 +359,6 @@ public function search(array $query, array $params = []): array { $requestParams = [ 'index' => $this->getIndexName(), - 'type' => $this->getTypeName(), 'body' => $query, ]; @@ -397,11 +384,10 @@ public function search(array $query, array $params = []): array public function bulk(string $operation, array $data = [], $autoCommit = true): array { $bulkParams = [ - '_type' => $this->getTypeName(), '_id' => $data['_id'] ?? null, ]; - unset($data['_index'], $data['_type'], $data['_id']); + unset($data['_index'], $data['_id']); $this->eventDispatcher->dispatch( Events::BULK, diff --git a/Service/Json/JsonReader.php b/Service/Json/JsonReader.php index a31cee54..68deaef5 100644 --- a/Service/Json/JsonReader.php +++ b/Service/Json/JsonReader.php @@ -125,10 +125,9 @@ protected function readLine() protected function configureResolver(OptionsResolver $resolver) { $resolver - ->setRequired(['_id', '_type', '_source']) + ->setRequired(['_id', '_source']) ->setDefaults(['_score' => null, 'fields' => []]) ->addAllowedTypes('_id', ['integer', 'string']) - ->addAllowedTypes('_type', 'string') ->addAllowedTypes('_source', 'array') ->addAllowedTypes('fields', 'array'); } diff --git a/Tests/Functional/Annotation/DocumentTest.php b/Tests/Functional/Annotation/DocumentTest.php index 81ae51d8..78277058 100644 --- a/Tests/Functional/Annotation/DocumentTest.php +++ b/Tests/Functional/Annotation/DocumentTest.php @@ -17,12 +17,6 @@ class DocumentTest extends AbstractElasticsearchTestCase { - public function testDocumentTypeName() - { - $index = $this->getIndex(DummyDocumentInTheEntityDirectory::class, false); - $this->assertEquals('_doc', $index->getTypeName()); - } - public function testDocumentIndexName() { $index = $this->getIndex(DummyDocument::class, false); diff --git a/Tests/Functional/Annotation/PropertyTest.php b/Tests/Functional/Annotation/PropertyTest.php index d944a157..56cc8116 100644 --- a/Tests/Functional/Annotation/PropertyTest.php +++ b/Tests/Functional/Annotation/PropertyTest.php @@ -37,7 +37,7 @@ public function testPropertyTypeName() ], 'type' => 'text', ], - $meta['mappings']['_doc']['properties']['title'] + $meta['mappings']['properties']['title'] ); } } diff --git a/Tests/Functional/Command/IndexExportCommandTest.php b/Tests/Functional/Command/IndexExportCommandTest.php index 4eeb440f..c49cce28 100644 --- a/Tests/Functional/Command/IndexExportCommandTest.php +++ b/Tests/Functional/Command/IndexExportCommandTest.php @@ -103,7 +103,6 @@ private function transformDataToResult(string $class): array $id = $document['_id']; unset($document['_id']); $expectedResults[] = [ - '_type' => $index->getTypeName(), '_id' => $id, '_source' => $document, ]; @@ -148,21 +147,6 @@ private function parseResult($filePath, $expectedCount) $this->assertEquals($expectedCount, $metadata['count']); - usort( - $results, - function ($a, $b) { - if ($a['_type'] == $b['_type']) { - if ($a['_id'] == $b['_id']) { - return 0; - } - - return $a['_id'] < $b['_id'] ? -1 : 1; - } - - return $a['_type'] < $b['_type'] ? -1 : 1; - } - ); - return $results; } } diff --git a/Tests/Functional/Command/IndexImportCommandTest.php b/Tests/Functional/Command/IndexImportCommandTest.php index 31cd91e2..15c9f1ed 100644 --- a/Tests/Functional/Command/IndexImportCommandTest.php +++ b/Tests/Functional/Command/IndexImportCommandTest.php @@ -62,14 +62,13 @@ public function testIndexImport(int $bulkSize, int $realSize, string $filename) ] ); - $search = $index->createSearch()->addQuery(new MatchAllQuery())->setSize($realSize); $results = $index->findDocuments($search); $ids = []; /** @var DummyDocument $doc */ foreach ($results as $doc) { - $ids[] = substr($doc->id, 3); + $ids[] = (int)$doc->id; } sort($ids); $data = range(1, $realSize); @@ -85,37 +84,37 @@ public function testIndexImport(int $bulkSize, int $realSize, string $filename) * * @dataProvider compressedDataProvider */ - public function testIndexImportWithGzipOption($bulkSize, $realSize, $filename) - { - $index = $this->getIndex(DummyDocument::class); - - $app = new Application(); - $app->add($this->getImportCommand()); - - $command = $app->find('ongr:es:index:import'); - $commandTester = new CommandTester($command); - $commandTester->execute( - [ - 'command' => $command->getName(), - 'filename' => __DIR__ . '/../../app/data_seed/' . $filename, - '--bulk-size' => $bulkSize, - '--gzip' => null, - ] - ); - - - $search = $index->createSearch()->addQuery(new MatchAllQuery())->setSize($realSize); - $results = $index->findDocuments($search); - - $ids = []; - /** @var DummyDocument $doc */ - foreach ($results as $doc) { - $ids[] = substr($doc->id, 3); - } - sort($ids); - $data = range(1, $realSize); - $this->assertEquals($data, $ids); - } +// public function testIndexImportWithGzipOption($bulkSize, $realSize, $filename) +// { +// $index = $this->getIndex(DummyDocument::class); +// +// $app = new Application(); +// $app->add($this->getImportCommand()); +// +// $command = $app->find('ongr:es:index:import'); +// $commandTester = new CommandTester($command); +// $commandTester->execute( +// [ +// 'command' => $command->getName(), +// 'filename' => __DIR__ . '/../../app/data_seed/' . $filename, +// '--bulk-size' => $bulkSize, +// '--gzip' => null, +// ] +// ); +// +// +// $search = $index->createSearch()->addQuery(new MatchAllQuery())->setSize($realSize); +// $results = $index->findDocuments($search); +// +// $ids = []; +// /** @var DummyDocument $doc */ +// foreach ($results as $doc) { +// $ids[] = (int)$doc->id; +// } +// sort($ids); +// $data = range(1, $realSize); +// $this->assertEquals($data, $ids); +// } /** * Returns import index command with assigned container. diff --git a/Tests/Functional/Profiler/ElasticsearchProfilerTest.php b/Tests/Functional/Profiler/ElasticsearchProfilerTest.php index 646c6843..32cd27a7 100644 --- a/Tests/Functional/Profiler/ElasticsearchProfilerTest.php +++ b/Tests/Functional/Profiler/ElasticsearchProfilerTest.php @@ -90,7 +90,6 @@ public function testGetQueries() 'method' => 'GET', 'httpParameters' => [], 'scheme' => 'http', - 'port' => 9200, ], $lastQuery, 'Logged data did not match expected data.' @@ -120,7 +119,6 @@ public function testGetTermQuery() 'method' => 'POST', 'httpParameters' => [], 'scheme' => 'http', - 'port' => 9200, ], $lastQuery, 'Logged data did not match expected data.' diff --git a/Tests/Unit/Event/BulkEventTest.php b/Tests/Unit/Event/BulkEventTest.php index 7b91418a..20126b99 100644 --- a/Tests/Unit/Event/BulkEventTest.php +++ b/Tests/Unit/Event/BulkEventTest.php @@ -21,13 +21,11 @@ public function testGetters() $operation = 'create'; $header = [ '_index' => 'index', - '_type' => '_doc', '_id' => 15, ]; $expectedHeader = [ '_index' => 'index', - '_type' => '_doc', '_id' => 10, ]; diff --git a/Tests/Unit/Event/CommitEventTest.php b/Tests/Unit/Event/CommitEventTest.php index 4418bd54..d55e453b 100644 --- a/Tests/Unit/Event/CommitEventTest.php +++ b/Tests/Unit/Event/CommitEventTest.php @@ -21,7 +21,6 @@ public function testGetters() $query = [ [ '_index' => 'index', - '_type' => '_doc', '_id' => 10, ], [ diff --git a/Tests/Unit/Mapping/DocumentParserTest.php b/Tests/Unit/Mapping/DocumentParserTest.php index d6d6d501..c03767e1 100644 --- a/Tests/Unit/Mapping/DocumentParserTest.php +++ b/Tests/Unit/Mapping/DocumentParserTest.php @@ -31,11 +31,9 @@ public function testDocumentParsing() $expected = [ 'mappings' => [ - '_doc' => [ - 'properties' => [ - 'keyword_field' => [ - 'type' => 'keyword', - ] + 'properties' => [ + 'keyword_field' => [ + 'type' => 'keyword', ] ] ] @@ -51,8 +49,8 @@ public function testParsingWithMultiFieldsMapping() $indexMetadata = $parser->getIndexMetadata(new \ReflectionClass(TestDocument::class)); // Mapping definition for field "title" should be there - $this->assertNotEmpty($indexMetadata['mappings']['_doc']['properties']['title']); - $title_field_def = $indexMetadata['mappings']['_doc']['properties']['title']; + $this->assertNotEmpty($indexMetadata['mappings']['properties']['title']); + $title_field_def = $indexMetadata['mappings']['properties']['title']; // title should have `fields` sub-array $this->assertArrayHasKey('fields', $title_field_def); diff --git a/Tests/Unit/Result/AbstractResultsIteratorTest.php b/Tests/Unit/Result/AbstractResultsIteratorTest.php index 2fe363ff..591de697 100644 --- a/Tests/Unit/Result/AbstractResultsIteratorTest.php +++ b/Tests/Unit/Result/AbstractResultsIteratorTest.php @@ -51,7 +51,6 @@ public function testGetDocumentScore() 'hits' => [ [ '_index' => 'test', - '_type' => '_doc', '_id' => 'foo', '_score' => 1, '_source' => [ @@ -60,7 +59,6 @@ public function testGetDocumentScore() ], [ '_index' => 'test', - '_type' => 'product', '_id' => 'bar', '_score' => 2, '_source' => [ @@ -69,7 +67,6 @@ public function testGetDocumentScore() ], [ '_index' => 'test', - '_type' => 'product', '_id' => 'baz', '_score' => null, '_source' => [ diff --git a/Tests/Unit/Result/DocumentIteratorTest.php b/Tests/Unit/Result/DocumentIteratorTest.php index f19fde65..4ccfb975 100644 --- a/Tests/Unit/Result/DocumentIteratorTest.php +++ b/Tests/Unit/Result/DocumentIteratorTest.php @@ -42,7 +42,6 @@ public function testResultConvert() 'hits' => [ [ '_index' => 'test', - '_type' => '_doc', '_id' => 'foo', '_score' => 1, '_source' => [ diff --git a/Tests/Unit/Result/RawIteratorTest.php b/Tests/Unit/Result/RawIteratorTest.php index 4017b108..99930705 100644 --- a/Tests/Unit/Result/RawIteratorTest.php +++ b/Tests/Unit/Result/RawIteratorTest.php @@ -50,7 +50,6 @@ public function testIterator() 'hits' => [ [ '_index' => 'test', - '_type' => '_doc', '_id' => 'foo', '_score' => 1, '_source' => [ diff --git a/Tests/app/data_seed/command_import_10.json b/Tests/app/data_seed/command_import_10.json index c7025d41..9ad254fc 100644 --- a/Tests/app/data_seed/command_import_10.json +++ b/Tests/app/data_seed/command_import_10.json @@ -1,13 +1,13 @@ [ {"count":10}, - {"_type":"product","_id":"doc1","_source":{"title":"Document 1"}}, - {"_type":"product","_id":"doc2","_source":{"title":"Document 2"}}, - {"_type":"product","_id":"doc3","_source":{"title":"Document 3"}}, - {"_type":"product","_id":"doc4","_source":{"title":"Document 4"}}, - {"_type":"product","_id":"doc5","_source":{"title":"Document 5"}}, - {"_type":"product","_id":"doc6","_source":{"title":"Document 6"}}, - {"_type":"product","_id":"doc7","_source":{"title":"Document 7"}}, - {"_type":"product","_id":"doc8","_source":{"title":"Document 8"}}, - {"_type":"product","_id":"doc9","_source":{"title":"Document 9"}}, - {"_type":"product","_id":"doc10","_source":{"title":"Document 10"}} + {"_id":"1","_source":{"title":"Document 1"}}, + {"_id":"2","_source":{"title":"Document 2"}}, + {"_id":"3","_source":{"title":"Document 3"}}, + {"_id":"4","_source":{"title":"Document 4"}}, + {"_id":"5","_source":{"title":"Document 5"}}, + {"_id":"6","_source":{"title":"Document 6"}}, + {"_id":"7","_source":{"title":"Document 7"}}, + {"_id":"8","_source":{"title":"Document 8"}}, + {"_id":"9","_source":{"title":"Document 9"}}, + {"_id":"10","_source":{"title":"Document 10"}} ] diff --git a/Tests/app/data_seed/command_import_10.json.gz b/Tests/app/data_seed/command_import_10.json.gz deleted file mode 100644 index afd98cb4663f4234bf1027c9fd44c2e9fbeae4db..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 177 zcmV;i08alOiwFp=E{|3K17mM(ZDDR?UukV{Z*p{BF)%J_b8l_{jnX>~gD?<;;ohgP zwx+OoL!Dbh5yhGUDZz-W3xv3POfE26{?h2H=4q@wiDO!YM(?iT-;*5MOe1Z342gvb znwF3|MD}-lW7;_nPLf65_wo@redblHrwbz`KuQf#0i@C(H9%?&(g38Os=K#{vKVGNeqj diff --git a/Tests/app/data_seed/command_import_11.json b/Tests/app/data_seed/command_import_11.json index 65ecfffc..8d82e901 100644 --- a/Tests/app/data_seed/command_import_11.json +++ b/Tests/app/data_seed/command_import_11.json @@ -1,14 +1,14 @@ [ {"count":11}, - {"_type":"product","_id":"doc1","_source":{"title":"Document 1"}}, - {"_type":"product","_id":"doc2","_source":{"title":"Document 2"}}, - {"_type":"product","_id":"doc3","_source":{"title":"Document 3"}}, - {"_type":"product","_id":"doc4","_source":{"title":"Document 4"}}, - {"_type":"product","_id":"doc5","_source":{"title":"Document 5"}}, - {"_type":"product","_id":"doc6","_source":{"title":"Document 6"}}, - {"_type":"product","_id":"doc7","_source":{"title":"Document 7"}}, - {"_type":"product","_id":"doc8","_source":{"title":"Document 8"}}, - {"_type":"product","_id":"doc9","_source":{"title":"Document 9"}}, - {"_type":"product","_id":"doc10","_source":{"title":"Document 10"}}, - {"_type":"product","_id":"doc11","_source":{"title":"Document 11"}} + {"_id":"1","_source":{"title":"Document 1"}}, + {"_id":"2","_source":{"title":"Document 2"}}, + {"_id":"3","_source":{"title":"Document 3"}}, + {"_id":"4","_source":{"title":"Document 4"}}, + {"_id":"5","_source":{"title":"Document 5"}}, + {"_id":"6","_source":{"title":"Document 6"}}, + {"_id":"7","_source":{"title":"Document 7"}}, + {"_id":"8","_source":{"title":"Document 8"}}, + {"_id":"9","_source":{"title":"Document 9"}}, + {"_id":"10","_source":{"title":"Document 10"}}, + {"_id":"11","_source":{"title":"Document 11"}} ] \ No newline at end of file diff --git a/Tests/app/data_seed/command_import_11.json.gz b/Tests/app/data_seed/command_import_11.json.gz deleted file mode 100644 index 27864e70ec10068d296463de4e8c2e6ef42ed0a6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 180 zcmV;l089TLiwFq3E{|3K17mM(ZDDR?UukV{Z*p{BF)=P`b8l_{jnX>~gFp;~;hs~h zTvK4)Q0Ep=M6pYOlwd@>1w!0CY%VY^e`)kp^URz($xB?7M&>L3_oT-*(@5JcA$p~p zrX}1R#B++T#NFS6lXTH{T0X?b&%CN*x-e1#q_iLvKq?DT1EjVf4L}+T(gLKlARRzD i3(^Cmw;%&R1`EOkdRt*);Azuqv)2!M__&1)0{{T}KTK`_ diff --git a/Tests/app/data_seed/command_import_20.json b/Tests/app/data_seed/command_import_20.json index b6e7e639..2b6441d3 100644 --- a/Tests/app/data_seed/command_import_20.json +++ b/Tests/app/data_seed/command_import_20.json @@ -1,23 +1,23 @@ [ {"count":20}, - {"_type":"product","_id":"doc1","_source":{"title":"Document 1"}}, - {"_type":"product","_id":"doc2","_source":{"title":"Document 2"}}, - {"_type":"product","_id":"doc3","_source":{"title":"Document 3"}}, - {"_type":"product","_id":"doc4","_source":{"title":"Document 4"}}, - {"_type":"product","_id":"doc5","_source":{"title":"Document 5"}}, - {"_type":"product","_id":"doc6","_source":{"title":"Document 6"}}, - {"_type":"product","_id":"doc7","_source":{"title":"Document 7"}}, - {"_type":"product","_id":"doc8","_source":{"title":"Document 8"}}, - {"_type":"product","_id":"doc9","_source":{"title":"Document 9"}}, - {"_type":"product","_id":"doc10","_source":{"title":"Document 10"}}, - {"_type":"product","_id":"doc11","_source":{"title":"Document 11"}}, - {"_type":"product","_id":"doc12","_source":{"title":"Document 12"}}, - {"_type":"product","_id":"doc13","_source":{"title":"Document 13"}}, - {"_type":"product","_id":"doc14","_source":{"title":"Document 14"}}, - {"_type":"product","_id":"doc15","_source":{"title":"Document 15"}}, - {"_type":"product","_id":"doc16","_source":{"title":"Document 16"}}, - {"_type":"product","_id":"doc17","_source":{"title":"Document 17"}}, - {"_type":"product","_id":"doc18","_source":{"title":"Document 18"}}, - {"_type":"product","_id":"doc19","_source":{"title":"Document 19"}}, - {"_type":"product","_id":"doc20","_source":{"title":"Document 20"}} + {"_id":"1","_source":{"title":"Document 1"}}, + {"_id":"2","_source":{"title":"Document 2"}}, + {"_id":"3","_source":{"title":"Document 3"}}, + {"_id":"4","_source":{"title":"Document 4"}}, + {"_id":"5","_source":{"title":"Document 5"}}, + {"_id":"6","_source":{"title":"Document 6"}}, + {"_id":"7","_source":{"title":"Document 7"}}, + {"_id":"8","_source":{"title":"Document 8"}}, + {"_id":"9","_source":{"title":"Document 9"}}, + {"_id":"10","_source":{"title":"Document 10"}}, + {"_id":"11","_source":{"title":"Document 11"}}, + {"_id":"12","_source":{"title":"Document 12"}}, + {"_id":"13","_source":{"title":"Document 13"}}, + {"_id":"14","_source":{"title":"Document 14"}}, + {"_id":"15","_source":{"title":"Document 15"}}, + {"_id":"16","_source":{"title":"Document 16"}}, + {"_id":"17","_source":{"title":"Document 17"}}, + {"_id":"18","_source":{"title":"Document 18"}}, + {"_id":"19","_source":{"title":"Document 19"}}, + {"_id":"20","_source":{"title":"Document 20"}} ] \ No newline at end of file diff --git a/Tests/app/data_seed/command_import_9.json b/Tests/app/data_seed/command_import_9.json index 1298abaa..b0f5d5cd 100644 --- a/Tests/app/data_seed/command_import_9.json +++ b/Tests/app/data_seed/command_import_9.json @@ -1,12 +1,12 @@ [ {"count":9}, - {"_type":"product","_id":"doc1","_source":{"title":"Document 1"}}, - {"_type":"product","_id":"doc2","_source":{"title":"Document 2"}}, - {"_type":"product","_id":"doc3","_source":{"title":"Document 3"}}, - {"_type":"product","_id":"doc4","_source":{"title":"Document 4"}}, - {"_type":"product","_id":"doc5","_source":{"title":"Document 5"}}, - {"_type":"product","_id":"doc6","_source":{"title":"Document 6"}}, - {"_type":"product","_id":"doc7","_source":{"title":"Document 7"}}, - {"_type":"product","_id":"doc8","_source":{"title":"Document 8"}}, - {"_type":"product","_id":"doc9","_source":{"title":"Document 9"}} + {"_id":"1","_source":{"title":"Document 1"}}, + {"_id":"2","_source":{"title":"Document 2"}}, + {"_id":"3","_source":{"title":"Document 3"}}, + {"_id":"4","_source":{"title":"Document 4"}}, + {"_id":"5","_source":{"title":"Document 5"}}, + {"_id":"6","_source":{"title":"Document 6"}}, + {"_id":"7","_source":{"title":"Document 7"}}, + {"_id":"8","_source":{"title":"Document 8"}}, + {"_id":"9","_source":{"title":"Document 9"}} ] diff --git a/Tests/app/data_seed/command_import_9.json.gz b/Tests/app/data_seed/command_import_9.json.gz deleted file mode 100644 index a0404a0503e4e440cb5d5e53f989beb94fe4bd8f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 167 zcmV;Y09gMYiwFpq*o{^I17mM(ZDDR?UukV{Z*p{BIWB5*Z*BmM%sUQ)Fc3x2-m9>t zrs0pNvx_LA7*il63?kzKA@&}V4ZJC@bakH2`;%DGsx*eH_~)d@Hq%JkE-|rELDLd* zN8$30ucV#xaFQ Date: Tue, 4 Feb 2020 18:49:30 +0200 Subject: [PATCH 02/13] update elasticsearch download url --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 55865b55..9667ac48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ php: - 7.3 env: global: - - ES_VERSION=7.5.2 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz + - ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.2-linux-x86_64.tar.gz matrix: - SYMFONY="~3.4" - SYMFONY="^4.4" From 1fc96bf2c7154eca806b28e9dbb7dbbe86e08d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= Date: Tue, 4 Feb 2020 18:51:51 +0200 Subject: [PATCH 03/13] fix that travis could extract elastic --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9667ac48..fd8b67b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,13 +6,13 @@ php: - 7.3 env: global: - - ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.2-linux-x86_64.tar.gz + - ES_VERSION=7.5.2 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}-linux-x86_64.tar.gz matrix: - SYMFONY="~3.4" - SYMFONY="^4.4" install: - wget ${ES_DOWNLOAD_URL} - - tar -xzf elasticsearch-${ES_VERSION}.tar.gz + - tar -xzf elasticsearch-${ES_VERSION}-linux-x86_64.tar.gz - ./elasticsearch-${ES_VERSION}/bin/elasticsearch -d before_script: - composer require --no-update symfony/framework-bundle:${SYMFONY} From c49241c0643886f4d110c56b29f357b8c19b7e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= Date: Tue, 4 Feb 2020 20:58:45 +0200 Subject: [PATCH 04/13] fix incompatibilities --- Service/IndexService.php | 2 +- Tests/Functional/Command/IndexExportCommandTest.php | 10 ++++++---- Tests/Functional/Command/IndexImportCommandTest.php | 1 + Tests/Functional/Result/PersistObjectsTest.php | 4 +++- Tests/Unit/Result/AbstractResultsIteratorTest.php | 6 ++++-- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Service/IndexService.php b/Service/IndexService.php index 83aaf6da..4688d6b6 100644 --- a/Service/IndexService.php +++ b/Service/IndexService.php @@ -425,7 +425,7 @@ public function persist($document): void $this->bulk('index', $documentArray); } - public function commit($commitMode = 'flush', array $params = []): array + public function commit($commitMode = 'refresh', array $params = []): array { $bulkResponse = []; if (!empty($this->bulkQueries)) { diff --git a/Tests/Functional/Command/IndexExportCommandTest.php b/Tests/Functional/Command/IndexExportCommandTest.php index c49cce28..8788e13a 100644 --- a/Tests/Functional/Command/IndexExportCommandTest.php +++ b/Tests/Functional/Command/IndexExportCommandTest.php @@ -25,17 +25,17 @@ protected function getDataArray() return [ DummyDocument::class => [ [ - '_id' => 'doc1', + '_id' => 1, 'title' => 'Foo Product', 'number' => 5.00, ], [ - '_id' => 'doc2', + '_id' => 2, 'title' => 'Bar Product', 'number' => 8.33, ], [ - '_id' => 'doc3', + '_id' => 3, 'title' => 'Lao Product', 'number' => 1.95, ], @@ -88,6 +88,9 @@ public function testIndexExport(array $options, array $expectedResults) ); $results = $this->parseResult(vfsStream::url('tmp/test.json'), count($expectedResults)); + usort($results, function ($a, $b){ + return (int)$a['_id'] <=> (int)$b['_id']; + }); $this->assertEquals($expectedResults, $results); } @@ -97,7 +100,6 @@ public function testIndexExport(array $options, array $expectedResults) private function transformDataToResult(string $class): array { $expectedResults = []; - $index = $this->getIndex($class); foreach ($this->getDataArray()[$class] as $document) { $id = $document['_id']; diff --git a/Tests/Functional/Command/IndexImportCommandTest.php b/Tests/Functional/Command/IndexImportCommandTest.php index 15c9f1ed..cd824d22 100644 --- a/Tests/Functional/Command/IndexImportCommandTest.php +++ b/Tests/Functional/Command/IndexImportCommandTest.php @@ -62,6 +62,7 @@ public function testIndexImport(int $bulkSize, int $realSize, string $filename) ] ); +// $index->refresh(); $search = $index->createSearch()->addQuery(new MatchAllQuery())->setSize($realSize); $results = $index->findDocuments($search); diff --git a/Tests/Functional/Result/PersistObjectsTest.php b/Tests/Functional/Result/PersistObjectsTest.php index 2a4716cb..0ec90ba1 100644 --- a/Tests/Functional/Result/PersistObjectsTest.php +++ b/Tests/Functional/Result/PersistObjectsTest.php @@ -55,11 +55,13 @@ public function testAddingValuesToPrivateIdsWithoutSetters() $document = new IndexWithFieldsDataDocument(); $document->title = 'acme'; - $index->persist($document); $index->commit(); + $index->refresh(); + $document = $index->findOneBy(['private' => 'acme']); + $this->assertNotNull($document->getId()); } } diff --git a/Tests/Unit/Result/AbstractResultsIteratorTest.php b/Tests/Unit/Result/AbstractResultsIteratorTest.php index 591de697..7f8d7c85 100644 --- a/Tests/Unit/Result/AbstractResultsIteratorTest.php +++ b/Tests/Unit/Result/AbstractResultsIteratorTest.php @@ -47,7 +47,9 @@ public function testGetDocumentScore() { $rawData = [ 'hits' => [ - 'total' => 3, + 'total' => [ + 'value' => 3 + ], 'hits' => [ [ '_index' => 'test', @@ -86,7 +88,7 @@ public function testGetDocumentScore() $expectedScores = [1, 2, null]; $actualScores = []; - $this->assertEquals($rawData['hits']['total'], $results->count()); + $this->assertEquals($rawData['hits']['total']['value'], $results->count()); $this->assertEquals($rawData, $results->getRaw()); foreach ($results as $item) { From b4f30fa1c8ebbf2d94adc24e5759be164fbd8fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= Date: Wed, 5 Feb 2020 08:35:25 +0200 Subject: [PATCH 05/13] adjust the import test when gzip is used gzip --- .../Command/IndexImportCommandTest.php | 62 +++++++++--------- Tests/app/data_seed/command_import_10.json.gz | Bin 0 -> 161 bytes Tests/app/data_seed/command_import_11.json.gz | Bin 0 -> 164 bytes Tests/app/data_seed/command_import_9.json.gz | Bin 0 -> 150 bytes 4 files changed, 31 insertions(+), 31 deletions(-) create mode 100644 Tests/app/data_seed/command_import_10.json.gz create mode 100644 Tests/app/data_seed/command_import_11.json.gz create mode 100644 Tests/app/data_seed/command_import_9.json.gz diff --git a/Tests/Functional/Command/IndexImportCommandTest.php b/Tests/Functional/Command/IndexImportCommandTest.php index cd824d22..b7437419 100644 --- a/Tests/Functional/Command/IndexImportCommandTest.php +++ b/Tests/Functional/Command/IndexImportCommandTest.php @@ -85,37 +85,37 @@ public function testIndexImport(int $bulkSize, int $realSize, string $filename) * * @dataProvider compressedDataProvider */ -// public function testIndexImportWithGzipOption($bulkSize, $realSize, $filename) -// { -// $index = $this->getIndex(DummyDocument::class); -// -// $app = new Application(); -// $app->add($this->getImportCommand()); -// -// $command = $app->find('ongr:es:index:import'); -// $commandTester = new CommandTester($command); -// $commandTester->execute( -// [ -// 'command' => $command->getName(), -// 'filename' => __DIR__ . '/../../app/data_seed/' . $filename, -// '--bulk-size' => $bulkSize, -// '--gzip' => null, -// ] -// ); -// -// -// $search = $index->createSearch()->addQuery(new MatchAllQuery())->setSize($realSize); -// $results = $index->findDocuments($search); -// -// $ids = []; -// /** @var DummyDocument $doc */ -// foreach ($results as $doc) { -// $ids[] = (int)$doc->id; -// } -// sort($ids); -// $data = range(1, $realSize); -// $this->assertEquals($data, $ids); -// } + public function testIndexImportWithGzipOption($bulkSize, $realSize, $filename) + { + $index = $this->getIndex(DummyDocument::class); + + $app = new Application(); + $app->add($this->getImportCommand()); + + $command = $app->find('ongr:es:index:import'); + $commandTester = new CommandTester($command); + $commandTester->execute( + [ + 'command' => $command->getName(), + 'filename' => __DIR__ . '/../../app/data_seed/' . $filename, + '--bulk-size' => $bulkSize, + '--gzip' => null, + ] + ); + + + $search = $index->createSearch()->addQuery(new MatchAllQuery())->setSize($realSize); + $results = $index->findDocuments($search); + + $ids = []; + /** @var DummyDocument $doc */ + foreach ($results as $doc) { + $ids[] = (int)$doc->id; + } + sort($ids); + $data = range(1, $realSize); + $this->assertEquals($data, $ids); + } /** * Returns import index command with assigned container. diff --git a/Tests/app/data_seed/command_import_10.json.gz b/Tests/app/data_seed/command_import_10.json.gz new file mode 100644 index 0000000000000000000000000000000000000000..ab344b14e91872a20a9877f997bd420e657b0bb0 GIT binary patch literal 161 zcmV;S0ABweiwFqNm^oem17mM(ZDDR?UukV{Z*p{BF)%J_b8l_{h0!|>!yp&~;GI(- z&kT@|7jte=RSYykq&7$`Oi}LMC|mx;n=O5w{7_o&NV#qW!P&!HJ+3bVI2goVuHUpE z>?mt_p8<1D^|Ne6I~+IP5Z?&j65k5%iTA>H#CO8?#P`Av#1F!c#E-&H#81LI%MP>W PLOsgD?<;;hs}i zQ&X_Kam_8Fh{B;jO0bmJ72@uBbeU$lUFn(y8r+H literal 0 HcmV?d00001 From abb63426598d2f624a86107ace2dd55d875e48c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= Date: Wed, 5 Feb 2020 08:36:44 +0200 Subject: [PATCH 06/13] fix psr2 style issue --- Tests/Functional/Command/IndexExportCommandTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Functional/Command/IndexExportCommandTest.php b/Tests/Functional/Command/IndexExportCommandTest.php index 8788e13a..6bc7e3e3 100644 --- a/Tests/Functional/Command/IndexExportCommandTest.php +++ b/Tests/Functional/Command/IndexExportCommandTest.php @@ -88,7 +88,7 @@ public function testIndexExport(array $options, array $expectedResults) ); $results = $this->parseResult(vfsStream::url('tmp/test.json'), count($expectedResults)); - usort($results, function ($a, $b){ + usort($results, function ($a, $b) { return (int)$a['_id'] <=> (int)$b['_id']; }); $this->assertEquals($expectedResults, $results); From 62bf57867ef6fd7b58273649ee986b30258b2ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= Date: Wed, 5 Feb 2020 08:51:46 +0200 Subject: [PATCH 07/13] update travis to use codecov instead of coveralls --- .travis.yml | 2 +- README.md | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fd8b67b1..f88368aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,4 +23,4 @@ script: - vendor/bin/phpunit --coverage-clover=coverage.clover - vendor/bin/phpcs -p --standard=PSR2 --ignore=vendor/,Tests/app/,var/cache ./ after_script: - - travis_retry php vendor/bin/coveralls + - travis_retry bash <(curl -s https://codecov.io/bash) diff --git a/README.md b/README.md index d08a3e5a..5663b7f5 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ is the preferred and recommended way to ask questions about ONGR bundles and lib [![Build Status](https://travis-ci.org/ongr-io/ElasticsearchBundle.svg?branch=master)](https://travis-ci.org/ongr-io/ElasticsearchBundle) [![Latest Stable Version](https://poser.pugx.org/ongr/elasticsearch-bundle/v/stable)](https://packagist.org/packages/ongr/elasticsearch-bundle) +[![codecov](https://codecov.io/gh/ongr-io/ElasticsearchBundle/branch/master/graph/badge.svg)](https://codecov.io/gh/ongr-io/ElasticsearchBundle) [![Total Downloads](https://poser.pugx.org/ongr/elasticsearch-bundle/downloads)](https://packagist.org/packages/ongr/elasticsearch-bundle) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ongr-io/ElasticsearchBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ongr-io/ElasticsearchBundle/?branch=master) @@ -32,7 +33,8 @@ is the preferred and recommended way to ask questions about ONGR bundles and lib | Elasticsearch version | ElasticsearchBundle version | | --------------------- | -------------------------------- | -| >= 6.0 | ~6.x | +| >= 7.0 | ~7.x | +| >= 6.0, < 7.0 | ~6.x | | >= 5.0, < 5.0 | ~5.x, ~6.x (indexes with 1 type) | | >= 2.0, < 5.0 | >=1.0, < 5.0 | | >= 1.0, < 2.0 | >= 0.10, < 1.0 | From 083eb2299b6706ac950cd9f9e2fc4a0d9d60d183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= Date: Wed, 5 Feb 2020 18:16:20 +0200 Subject: [PATCH 08/13] add support for the symfony 5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 988b1e0a..5a798852 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,7 @@ "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "6.1-dev" + "dev-master": "6.2-dev" } } } From 05190bf2913c68d6d6b8b894625fd768d2f67632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= Date: Wed, 5 Feb 2020 18:22:32 +0200 Subject: [PATCH 09/13] support breaking changes that was introduced in the symfony 4.4 --- Command/AbstractIndexServiceAwareCommand.php | 27 +- Command/CacheClearCommand.php | 2 + Command/DocumentGenerateCommand.php | 717 ------------------ Command/IndexCreateCommand.php | 2 + Command/IndexDropCommand.php | 2 + Command/IndexExportCommand.php | 2 + Command/IndexImportCommand.php | 2 + DependencyInjection/Configuration.php | 22 +- Event/BulkEvent.php | 2 +- Event/CommitEvent.php | 2 +- Event/PostCreateClientEvent.php | 2 +- Event/PrePersistEvent.php | 2 +- Profiler/ElasticsearchProfiler.php | 2 +- Service/IndexService.php | 16 +- Test/AbstractElasticsearchTestCase.php | 6 +- .../Command/CacheClearCommandTest.php | 3 +- .../Command/CreateIndexCommandTest.php | 3 +- .../Command/DropIndexCommandTest.php | 3 +- .../Command/GenerateDocumentCommandTest.php | 42 - .../Command/IndexExportCommandTest.php | 5 +- .../Command/IndexImportCommandTest.php | 5 +- .../Profiler/ElasticsearchProfilerTest.php | 2 +- .../Result/AggregationIteratorFindTest.php | 2 +- Tests/Functional/Result/ArrayIteratorTest.php | 2 +- .../Result/DocumentIteratorTest.php | 2 +- .../DocumentWithNullObjectFieldTest.php | 2 +- .../Functional/Result/GetDocumentSortTest.php | 2 +- .../Functional/Result/ObjectIteratorTest.php | 2 +- Tests/Functional/Service/IndexServiceTest.php | 2 +- composer.json | 29 +- 30 files changed, 93 insertions(+), 821 deletions(-) delete mode 100644 Command/DocumentGenerateCommand.php delete mode 100644 Tests/Functional/Command/GenerateDocumentCommandTest.php diff --git a/Command/AbstractIndexServiceAwareCommand.php b/Command/AbstractIndexServiceAwareCommand.php index eafa9fea..c9825dd4 100644 --- a/Command/AbstractIndexServiceAwareCommand.php +++ b/Command/AbstractIndexServiceAwareCommand.php @@ -14,12 +14,22 @@ use ONGR\ElasticsearchBundle\DependencyInjection\Configuration; use ONGR\ElasticsearchBundle\Service\IndexService; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\DependencyInjection\Container; -abstract class AbstractIndexServiceAwareCommand extends ContainerAwareCommand +abstract class AbstractIndexServiceAwareCommand extends Command { + private $container; + const INDEX_OPTION = 'index'; + public function __construct(Container $container) + { + $this->container = $container; + parent::__construct(); + } + protected function configure() { $this->addOption( @@ -32,19 +42,24 @@ protected function configure() protected function getIndex($name): IndexService { - $name = $name ?? $this->getContainer()->getParameter(Configuration::ONGR_DEFAULT_INDEX); - $indexes = $this->getContainer()->getParameter(Configuration::ONGR_INDEXES); + $name = $name ?? $this->container->getParameter(Configuration::ONGR_DEFAULT_INDEX); + $indexes = $this->container->getParameter(Configuration::ONGR_INDEXES); - if (isset($indexes[$name]) && $this->getContainer()->has($indexes[$name])) { - return $this->getContainer()->get($indexes[$name]); + if (isset($indexes[$name]) && $this->container->has($indexes[$name])) { + return $this->container->get($indexes[$name]); } throw new \RuntimeException( sprintf( 'There is no index under `%s` name found. Available options: `%s`.', $name, - implode('`, `', array_keys($this->getContainer()->getParameter(Configuration::ONGR_INDEXES))) + implode('`, `', array_keys($this->container->getParameter(Configuration::ONGR_INDEXES))) ) ); } + + public function getContainer(): Container + { + return $this->container; + } } diff --git a/Command/CacheClearCommand.php b/Command/CacheClearCommand.php index 594e1e6c..956a572c 100644 --- a/Command/CacheClearCommand.php +++ b/Command/CacheClearCommand.php @@ -46,5 +46,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $index->getIndexName() ) ); + + return 0; } } diff --git a/Command/DocumentGenerateCommand.php b/Command/DocumentGenerateCommand.php deleted file mode 100644 index cf41f845..00000000 --- a/Command/DocumentGenerateCommand.php +++ /dev/null @@ -1,717 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ONGR\ElasticsearchBundle\Command; - -use Symfony\Component\Console\Helper\FormatterHelper; -use Symfony\Component\Console\Helper\QuestionHelper; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Question\ConfirmationQuestion; -use Symfony\Component\Console\Question\Question; -use Symfony\Component\HttpKernel\Kernel; - -class DocumentGenerateCommand extends AbstractIndexServiceAwareCommand -{ - const NAME = 'ongr:es:document:generate'; - - /** - * @var QuestionHelper - */ - private $questionHelper; - - /** - * @var string[] - */ - private $propertyAnnotations; - - /** - * @var string[] - */ - private $propertyVisibilities; - - /** - * {@inheritdoc} - */ - protected function configure() - { - parent::configure(); - - $this - ->setName(self::NAME) - ->setDescription('Generates a new Elasticsearch document inside a bundle'); - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - if ($input->hasParameterOption(['--no-interaction', '-n'])) { - throw $this->getException('No interaction mode is not allowed!'); - } - } - - /** - * {@inheritdoc} - */ - protected function interact(InputInterface $input, OutputInterface $output) - { - /** @var FormatterHelper $formatter */ - $formatter = $this->getHelperSet()->get('formatter'); - $this->questionHelper = new QuestionHelper(); - - $output->writeln( - [ - '', - $formatter->formatBlock('Welcome to the Elasticsearch Bundle document generator', 'bg=blue', true), - '', - 'This command helps you generate Elasticsearch documents.', - '', - 'First, you need to give the document class namespace you want to generate.', - 'You must use the shortcut notation like App\YourProjectPath\PostDocument.', - '', - ] - ); - - /** @var Kernel $kernel */ - $kernel = $this->getContainer()->get('kernel'); - $bundleNames = array_keys($kernel->getBundles()); - - while (true) { - $document = $this->questionHelper->ask( - $input, - $output, - $this->getQuestion('The Document shortcut name', null, [$this, 'validateDocumentName'], $bundleNames) - ); - - list($bundle, $document) = $this->parseShortcutNotation($document); - - if (in_array(strtolower($document), $this->getReservedKeywords())) { - $output->writeln($this->getException('"%s" is a reserved word.', [$document])->getMessage()); - continue; - } - - try { - if (!file_exists( - $kernel->getBundle($bundle)->getPath() . '/Document/' . str_replace('\\', '/', $document) . '.php' - )) { - break; - } - - $output->writeln( - $this->getException('Document "%s:%s" already exists.', [$bundle, $document])->getMessage() - ); - } catch (\Exception $e) { - $output->writeln($this->getException('Bundle "%s" does not exist.', [$bundle])->getMessage()); - } - } - - $output->writeln($this->getOptionsLabel($this->getDocumentAnnotations(), 'Available types')); - $annotation = $this->questionHelper->ask( - $input, - $output, - $this->getQuestion( - 'Document type', - 'document', - [$this, 'validateDocumentAnnotation'], - $this->getDocumentAnnotations() - ) - ); - - $this->propertyAnnotations = ['embedded', 'property']; - $documentType = lcfirst($document); - - if ($annotation == 'document') { - $this->propertyAnnotations = ['embedded', 'id', 'parentDocument', 'property', 'ttl']; - $documentType = $this->questionHelper->ask( - $input, - $output, - $this->getQuestion( - "\n" . 'Elasticsearch Document name', - lcfirst($document), - [$this, 'validateFieldName'] - ) - ); - } - - $properties = []; - $output->writeln(['', $formatter->formatBlock('New Document Property?', 'bg=blue;fg=white', true)]); - - while (true) { - $property = []; - $question = $this->getQuestion( - 'Property name [press to stop]', - false - ); - - if (!$field = $this->questionHelper->ask($input, $output, $question)) { - break; - } - - foreach ($properties as $previousProperty) { - if ($previousProperty['field_name'] == $field) { - $output->writeln($this->getException('Duplicate field name "%s"', [$field])->getMessage()); - continue(2); - } - } - - try { - $this->validateFieldName($field); - } catch (\InvalidArgumentException $e) { - $output->writeln($e->getMessage()); - continue; - } - - $this->propertyVisibilities = ['private', 'protected', 'public']; - $output->writeln($this->getOptionsLabel($this->propertyVisibilities, 'Available visibilities')); - $property['visibility'] = $this->questionHelper->ask( - $input, - $output, - $this->getQuestion( - 'Property visibility', - 'private', - [$this, 'validatePropertyVisibility'], - $this->propertyVisibilities - ) - ); - - $output->writeln($this->getOptionsLabel($this->propertyAnnotations, 'Available annotations')); - $property['annotation'] = $this->questionHelper->ask( - $input, - $output, - $this->getQuestion( - 'Property meta field', - 'property', - [$this, 'validatePropertyAnnotation'], - $this->propertyAnnotations - ) - ); - - $property['field_name'] = $property['property_name'] = $field; - - switch ($property['annotation']) { - case 'embedded': - $property['property_name'] = $this->askForPropertyName($input, $output, $property['field_name']); - $property['property_class'] = $this->askForPropertyClass($input, $output); - - $question = new ConfirmationQuestion("\nMultiple [no]: ", false); - $question->setAutocompleterValues(['yes', 'no']); - $property['property_multiple'] = $this->questionHelper->ask($input, $output, $question); - - $property['property_options'] = $this->askForPropertyOptions($input, $output); - break; - case 'parentDocument': - if (!$this->isUniqueAnnotation($properties, $property['annotation'])) { - $output->writeln( - $this - ->getException('Only one "%s" field can be added', [$property['annotation']]) - ->getMessage() - ); - continue(2); - } - $property['property_class'] = $this->askForPropertyClass($input, $output); - break; - case 'property': - $property['property_name'] = $this->askForPropertyName($input, $output, $property['field_name']); - - $output->writeln($this->getOptionsLabel($this->getPropertyTypes(), 'Available types')); - $property['property_type'] = $this->questionHelper->ask( - $input, - $output, - $this->getQuestion( - 'Property type', - 'text', - [$this, 'validatePropertyType'], - $this->getPropertyTypes() - ) - ); - - $property['property_options'] = $this->askForPropertyOptions($input, $output); - break; - case 'ttl': - if (!$this->isUniqueAnnotation($properties, $property['annotation'])) { - $output->writeln( - $this - ->getException('Only one "%s" field can be added', [$property['annotation']]) - ->getMessage() - ); - continue(2); - } - $property['property_default'] = $this->questionHelper->ask( - $input, - $output, - $this->getQuestion("\n" . 'Default time to live') - ); - break; - case 'id': - if (!$this->isUniqueAnnotation($properties, $property['annotation'])) { - $output->writeln( - $this - ->getException('Only one "%s" field can be added', [$property['annotation']]) - ->getMessage() - ); - continue(2); - } - break; - } - - $properties[] = $property; - $output->writeln(['', $formatter->formatBlock('New Document Property', 'bg=blue;fg=white', true)]); - } - - $this->getContainer()->get('es.generate')->generate( - $this->getContainer()->get('kernel')->getBundle($bundle), - $document, - $annotation, - $documentType, - $properties - ); - } - - /** - * @param array $properties - * @param string $annotation - * - * @return string - */ - private function isUniqueAnnotation($properties, $annotation) - { - foreach ($properties as $property) { - if ($property['annotation'] == $annotation) { - return false; - } - } - - return true; - } - - /** - * Asks for property name - * - * @param InputInterface $input - * @param OutputInterface $output - * @param string $default - * - * @return string - */ - private function askForPropertyName(InputInterface $input, OutputInterface $output, $default = null) - { - return $this->questionHelper->ask( - $input, - $output, - $this->getQuestion("\n" . 'Property name in Elasticsearch', $default, [$this, 'validateFieldName']) - ); - } - - /** - * Asks for property options - * - * @param InputInterface $input - * @param OutputInterface $output - * - * @return string - */ - private function askForPropertyOptions(InputInterface $input, OutputInterface $output) - { - $output->writeln( - "\n" - . 'Enter property options, for example "index"="not_analyzed"' - . ' allows mapper to index this field, so it is searchable, but value will be not analyzed.' - ); - - return $this->questionHelper->ask( - $input, - $output, - $this->getQuestion( - 'Property options [press to stop]', - false, - null, - ['"index"="not_analyzed"', '"analyzer"="standard"'] - ) - ); - } - - /** - * Asks for property class - * - * @param InputInterface $input - * @param OutputInterface $output - * - * @return string - */ - private function askForPropertyClass(InputInterface $input, OutputInterface $output) - { - return $this->questionHelper->ask( - $input, - $output, - $this->getQuestion( - "\n" . 'Property class', - null, - [$this, 'validatePropertyClass'], - array_merge($this->getDocumentClasses(), array_keys($this->getContainer()->get('kernel')->getBundles())) - ) - ); - } - - /** - * Returns available document classes - * - * @return array - */ - private function getDocumentClasses() - { -// /** @var MetadataCollector $metadataCollector */ -// $metadataCollector = $this->getContainer()->get('es.metadata_collector'); -// $classes = []; -// -// foreach ($this->getContainer()->getParameter('es.managers') as $manager) { -// $documents = $metadataCollector->getMappings($manager['mappings']); -// foreach ($documents as $document) { -// $classes[] = sprintf('%s:%s', $document['bundle'], $document['class']); -// } -// } -// return $classes; - return []; - } - - /** - * Parses shortcut notation - * - * @param string $shortcut - * - * @return string[] - * @throws \InvalidArgumentException - */ - private function parseShortcutNotation($shortcut) - { - $shortcut = str_replace('/', '\\', $shortcut); - - if (false === $pos = strpos($shortcut, ':')) { - throw $this->getException( - 'The document name isn\'t valid ("%s" given, expecting something like AcmeBundle:Post)', - [$shortcut] - ); - } - - return [substr($shortcut, 0, $pos), substr($shortcut, $pos + 1)]; - } - - /** - * Validates property class - * - * @param string $input - * - * @return string - * @throws \InvalidArgumentException - */ - public function validatePropertyClass($input) - { - list($bundle, $document) = $this->parseShortcutNotation($input); - - try { - $bundlePath = $this->getContainer()->get('kernel')->getBundle($bundle)->getPath(); - } catch (\Exception $e) { - throw $this->getException('Bundle "%s" does not exist.', [$bundle]); - } - - if (!file_exists($bundlePath . '/Document/' . str_replace('\\', '/', $document) . '.php')) { - throw $this->getException('Document "%s:%s" does not exist.', [$bundle, $document]); - } - - return $input; - } - - /** - * Performs basic checks in document name - * - * @param string $document - * - * @return string - * @throws \InvalidArgumentException - */ - public function validateDocumentName($document) - { - if (!preg_match('{^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*:[a-zA-Z0-9_\x7f-\xff\\\/]+$}', $document)) { - throw $this->getException( - 'The document name isn\'t valid ("%s" given, expecting something like AcmeBundle:Post)', - [$document] - ); - } - - return $document; - } - - /** - * Validates field name - * - * @param string $field - * - * @return string - * @throws \InvalidArgumentException - */ - public function validateFieldName($field) - { - if (!$field || $field != lcfirst(preg_replace('/[^a-zA-Z]+/', '', $field))) { - throw $this->getException( - 'The parameter isn\'t valid ("%s" given, expecting camelcase separated words)', - [$field] - ); - } - - if (in_array(strtolower($field), $this->getReservedKeywords())) { - throw $this->getException('"%s" is a reserved word.', [$field]); - } - - return $field; - } - - /** - * Validates property type - * - * @param string $type - * - * @return string - * @throws \InvalidArgumentException - */ - public function validatePropertyType($type) - { - if (!in_array($type, $this->getPropertyTypes())) { - throw $this->getException( - 'The property type isn\'t valid ("%s" given, expecting one of following: %s)', - [$type, implode(', ', $this->getPropertyTypes())] - ); - } - - return $type; - } - - /** - * Validates document annotation - * - * @param string $annotation - * - * @return string - * @throws \InvalidArgumentException - */ - public function validateDocumentAnnotation($annotation) - { - if (!in_array($annotation, $this->getDocumentAnnotations())) { - throw $this->getException( - 'The document annotation isn\'t valid ("%s" given, expecting one of following: %s)', - [$annotation, implode(', ', $this->getDocumentAnnotations())] - ); - } - - return $annotation; - } - - /** - * Validates property annotation - * - * @param string $annotation - * - * @return string - * @throws \InvalidArgumentException - */ - public function validatePropertyAnnotation($annotation) - { - if (!in_array($annotation, $this->propertyAnnotations)) { - throw $this->getException( - 'The property annotation isn\'t valid ("%s" given, expecting one of following: %s)', - [$annotation, implode(', ', $this->propertyAnnotations)] - ); - } - - return $annotation; - } - - /** - * Validates property visibility - * - * @param string $visibility - * - * @return string - * @throws \InvalidArgumentException When the visibility is not found in the list of allowed ones. - */ - public function validatePropertyVisibility($visibility) - { - if (!in_array($visibility, $this->propertyVisibilities)) { - throw $this->getException( - 'The property visibility isn\'t valid ("%s" given, expecting one of following: %s)', - [$visibility, implode(', ', $this->propertyVisibilities)] - ); - } - - return $visibility; - } - - /** - * Returns formatted question - * - * @param string $question - * @param mixed $default - * @param callable|null $validator - * @param array|null $values - * - * @return Question - */ - private function getQuestion($question, $default = null, callable $validator = null, array $values = null) - { - $question = new Question( - sprintf('%s%s: ', $question, $default ? sprintf(' [%s]', $default) : ''), - $default - ); - - $question - ->setValidator($validator) - ->setAutocompleterValues($values); - - return $question; - } - - /** - * Returns options label - * - * @param array $options - * @param string $suffix - * - * @return string[] - */ - private function getOptionsLabel(array $options, $suffix) - { - $label = sprintf('%s: ', $suffix); - - foreach ($options as &$option) { - $option = sprintf('%s', $option); - } - - return ['', $label . implode(', ', $options) . '.']; - } - - /** - * Returns formatted exception - * - * @param string $format - * @param array $args - * - * @return \InvalidArgumentException - */ - private function getException($format, $args = []) - { - /** @var FormatterHelper $formatter */ - $formatter = $this->getHelperSet()->get('formatter'); - return new \InvalidArgumentException($formatter->formatBlock(vsprintf($format, $args), 'bg=red', true)); - } - - /** - * Returns available property types - * - * @return array - */ - private function getPropertyTypes() - { - $reflection = new \ReflectionClass('ONGR\ElasticsearchBundle\Annotation\Property'); - - return $this - ->getContainer() - ->get('es.annotations.cached_reader') - ->getPropertyAnnotation($reflection->getProperty('type'), 'Doctrine\Common\Annotations\Annotation\Enum') - ->value; - } - - /** - * Returns document annotations - * - * @return string[] - */ - private function getDocumentAnnotations() - { - return ['document', 'nested', 'object']; - } - - /** - * Returns reserved keywords - * - * @return string[] - */ - private function getReservedKeywords() - { - return [ - 'abstract', - 'and', - 'array', - 'as', - 'break', - 'callable', - 'case', - 'catch', - 'class', - 'clone', - 'const', - 'continue', - 'declare', - 'default', - 'do', - 'else', - 'elseif', - 'enddeclare', - 'endfor', - 'endforeach', - 'endif', - 'endswitch', - 'endwhile', - 'extends', - 'final', - 'finally', - 'for', - 'foreach', - 'function', - 'global', - 'goto', - 'if', - 'implements', - 'interface', - 'instanceof', - 'insteadof', - 'namespace', - 'new', - 'or', - 'private', - 'protected', - 'public', - 'static', - 'switch', - 'throw', - 'trait', - 'try', - 'use', - 'var', - 'while', - 'xor', - 'yield', - 'die', - 'echo', - 'empty', - 'exit', - 'eval', - 'include', - 'include_once', - 'isset', - 'list', - 'require', - 'require_once', - 'return', - 'print', - 'unset', - ]; - } -} diff --git a/Command/IndexCreateCommand.php b/Command/IndexCreateCommand.php index b75bedd7..073b33ae 100644 --- a/Command/IndexCreateCommand.php +++ b/Command/IndexCreateCommand.php @@ -146,5 +146,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ) ); } + + return 0; } } diff --git a/Command/IndexDropCommand.php b/Command/IndexDropCommand.php index 64b3e566..909dfe46 100644 --- a/Command/IndexDropCommand.php +++ b/Command/IndexDropCommand.php @@ -56,5 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $io->text('This action should not be used in the production environment.'); $io->error('Option --force is mandatory to drop the index.'); } + + return 0; } } diff --git a/Command/IndexExportCommand.php b/Command/IndexExportCommand.php index 7517ed2d..5ae110fa 100644 --- a/Command/IndexExportCommand.php +++ b/Command/IndexExportCommand.php @@ -70,5 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ); $io->success('Data export completed!'); + + return 0; } } diff --git a/Command/IndexImportCommand.php b/Command/IndexImportCommand.php index 35d1a831..4fd78875 100644 --- a/Command/IndexImportCommand.php +++ b/Command/IndexImportCommand.php @@ -76,5 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ); $io->success('Data import completed!'); + + return 0; } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index bc2c665b..ae62e61a 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -30,8 +30,15 @@ class Configuration implements ConfigurationInterface public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder(); - $rootNode = $treeBuilder->root('ongr_elasticsearch'); + + $treeBuilder = new TreeBuilder('ongr_elasticsearch'); + + if (method_exists($treeBuilder, 'getRootNode')) { + $rootNode = $treeBuilder->getRootNode(); + } else { + // BC layer for symfony/config 4.1 and older + $rootNode = $treeBuilder->root('ongr_elasticsearch'); + } $rootNode ->children() @@ -85,8 +92,15 @@ public function getConfigTreeBuilder() private function getAnalysisNode(): NodeDefinition { - $builder = new TreeBuilder(); - $node = $builder->root('analysis'); + $builder = new TreeBuilder('analysis'); + + if (method_exists($builder, 'getRootNode')) { + $node = $builder->getRootNode(); + } else { + // BC layer for symfony/config 4.1 and older + $node = $builder->root('analysis'); + } + $node ->info('Defines analyzers, normalizers, tokenizers and filters') diff --git a/Event/BulkEvent.php b/Event/BulkEvent.php index 9243031a..865182e2 100644 --- a/Event/BulkEvent.php +++ b/Event/BulkEvent.php @@ -11,7 +11,7 @@ namespace ONGR\ElasticsearchBundle\Event; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; class BulkEvent extends Event { diff --git a/Event/CommitEvent.php b/Event/CommitEvent.php index e24f7af2..018d4663 100644 --- a/Event/CommitEvent.php +++ b/Event/CommitEvent.php @@ -11,7 +11,7 @@ namespace ONGR\ElasticsearchBundle\Event; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; class CommitEvent extends Event { diff --git a/Event/PostCreateClientEvent.php b/Event/PostCreateClientEvent.php index ed29c5fa..edf3185c 100644 --- a/Event/PostCreateClientEvent.php +++ b/Event/PostCreateClientEvent.php @@ -12,7 +12,7 @@ namespace ONGR\ElasticsearchBundle\Event; use Elasticsearch\ClientBuilder; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; class PostCreateClientEvent extends Event { diff --git a/Event/PrePersistEvent.php b/Event/PrePersistEvent.php index e0b3186e..358d694b 100644 --- a/Event/PrePersistEvent.php +++ b/Event/PrePersistEvent.php @@ -11,7 +11,7 @@ namespace ONGR\ElasticsearchBundle\Event; -use Symfony\Component\EventDispatcher\Event; +use Symfony\Contracts\EventDispatcher\Event; class PrePersistEvent extends Event { diff --git a/Profiler/ElasticsearchProfiler.php b/Profiler/ElasticsearchProfiler.php index bdbe26e2..efc30059 100644 --- a/Profiler/ElasticsearchProfiler.php +++ b/Profiler/ElasticsearchProfiler.php @@ -40,7 +40,7 @@ public function setIndexes(array $indexes): void $this->indexes = $indexes; } - public function collect(Request $request, Response $response, \Exception $exception = null) + public function collect(Request $request, Response $response, \Throwable $exception = null) { /** @var Logger $logger */ foreach ($this->loggers as $logger) { diff --git a/Service/IndexService.php b/Service/IndexService.php index a9cc924f..21a3aa10 100644 --- a/Service/IndexService.php +++ b/Service/IndexService.php @@ -90,8 +90,8 @@ public function getClient(): Client // $client->setLogger() $this->eventDispatcher->dispatch( - Events::POST_CLIENT_CREATE, - new PostCreateClientEvent($this->namespace, $client) + new PostCreateClientEvent($this->namespace, $client), + Events::POST_CLIENT_CREATE ); $this->client = $client->build(); } @@ -404,8 +404,8 @@ public function bulk(string $operation, array $data = [], $autoCommit = true): a unset($data['_index'], $data['_type'], $data['_id']); $this->eventDispatcher->dispatch( - Events::BULK, - new BulkEvent($operation, $bulkParams, $data) + new BulkEvent($operation, $bulkParams, $data), + Events::BULK ); $this->bulkQueries[] = [ $operation => $bulkParams]; @@ -444,8 +444,8 @@ public function commit($commitMode = 'flush', array $params = []): array $bulkResponse = []; if (!empty($this->bulkQueries)) { $this->eventDispatcher->dispatch( - Events::PRE_COMMIT, - new CommitEvent($commitMode, $this->bulkQueries, []) + new CommitEvent($commitMode, $this->bulkQueries, []), + Events::PRE_COMMIT ); // $this->stopwatch('start', 'bulk'); @@ -483,8 +483,8 @@ public function commit($commitMode = 'flush', array $params = []): array } $this->eventDispatcher->dispatch( - Events::POST_COMMIT, - new CommitEvent($commitMode, $this->bulkQueries, $bulkResponse) + new CommitEvent($commitMode, $this->bulkQueries, $bulkResponse), + Events::POST_COMMIT ); $this->bulkQueries = []; diff --git a/Test/AbstractElasticsearchTestCase.php b/Test/AbstractElasticsearchTestCase.php index e8f3f9e3..3c8bb523 100644 --- a/Test/AbstractElasticsearchTestCase.php +++ b/Test/AbstractElasticsearchTestCase.php @@ -53,7 +53,7 @@ protected function setUp() * * @return array */ - protected function getDataArray() + protected function getDataArray(): array { return []; } @@ -69,7 +69,7 @@ private function populateElastic(IndexService $indexService, array $documents = /** * {@inheritdoc} */ - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); @@ -85,7 +85,7 @@ protected function tearDown() protected function getContainer($reinitialize = false, $kernelOptions = []): ContainerInterface { if (!self::$cachedContainer && !$reinitialize) { - static::bootKernel($kernelOptions); +// static::bootKernel($kernelOptions); self::$cachedContainer = static::createClient(['environment' => 'test'])->getContainer(); } diff --git a/Tests/Functional/Command/CacheClearCommandTest.php b/Tests/Functional/Command/CacheClearCommandTest.php index 878dd536..9af0528b 100644 --- a/Tests/Functional/Command/CacheClearCommandTest.php +++ b/Tests/Functional/Command/CacheClearCommandTest.php @@ -70,8 +70,7 @@ public function testExecuteException() */ private function getCommand() { - $command = new CacheClearCommand(); - $command->setContainer($this->getContainer()); + $command = new CacheClearCommand($this->getContainer(true)); return $command; } diff --git a/Tests/Functional/Command/CreateIndexCommandTest.php b/Tests/Functional/Command/CreateIndexCommandTest.php index e185d24e..39de4c60 100644 --- a/Tests/Functional/Command/CreateIndexCommandTest.php +++ b/Tests/Functional/Command/CreateIndexCommandTest.php @@ -170,8 +170,7 @@ public function testIndexMappingDump() */ private function getCommandTester() { - $indexCreateCommand = new IndexCreateCommand(); - $indexCreateCommand->setContainer($this->getContainer()); + $indexCreateCommand = new IndexCreateCommand($this->getContainer()); $app = new Application(); $app->add($indexCreateCommand); diff --git a/Tests/Functional/Command/DropIndexCommandTest.php b/Tests/Functional/Command/DropIndexCommandTest.php index 2d040ec1..8c09859f 100644 --- a/Tests/Functional/Command/DropIndexCommandTest.php +++ b/Tests/Functional/Command/DropIndexCommandTest.php @@ -24,8 +24,7 @@ public function testExecute() $index = $this->getIndex(DummyDocument::class); $index->dropAndCreateIndex(); - $command = new IndexDropCommand(); - $command->setContainer($this->getContainer()); + $command = new IndexDropCommand($this->getContainer()); $app = new Application(); $app->add($command); diff --git a/Tests/Functional/Command/GenerateDocumentCommandTest.php b/Tests/Functional/Command/GenerateDocumentCommandTest.php deleted file mode 100644 index 48f163df..00000000 --- a/Tests/Functional/Command/GenerateDocumentCommandTest.php +++ /dev/null @@ -1,42 +0,0 @@ -markTestSkipped('Document generator will be implemented later.'); - -// $app = new Application(); -// $app->add($this->getCommand()); -// -// $command = $app->find('ongr:es:document:generate'); -// -// $tester = new CommandTester($command); -// $tester->execute(['command' => $command->getName()], ['interactive' => false]); -// $tester->execute( -// ['command' => $command->getName(), '--no-interaction' => true], -// ['interactive' => false] -// ); - } - - /** - * @return DocumentGenerateCommand - */ - private function getCommand() - { - $command = new DocumentGenerateCommand(); - $command->setContainer(self::createClient()->getContainer()); - - return $command; - } -} diff --git a/Tests/Functional/Command/IndexExportCommandTest.php b/Tests/Functional/Command/IndexExportCommandTest.php index 4eeb440f..e27c890e 100644 --- a/Tests/Functional/Command/IndexExportCommandTest.php +++ b/Tests/Functional/Command/IndexExportCommandTest.php @@ -20,7 +20,7 @@ class IndexExportCommandTest extends AbstractElasticsearchTestCase { - protected function getDataArray() + protected function getDataArray(): array { return [ DummyDocument::class => [ @@ -119,8 +119,7 @@ private function transformDataToResult(string $class): array */ private function getCommandTester() { - $indexExportCommand = new IndexExportCommand(); - $indexExportCommand->setContainer($this->getContainer()); + $indexExportCommand = new IndexExportCommand($this->getContainer()); $app = new Application(); $app->add($indexExportCommand); diff --git a/Tests/Functional/Command/IndexImportCommandTest.php b/Tests/Functional/Command/IndexImportCommandTest.php index 31cd91e2..0da96863 100644 --- a/Tests/Functional/Command/IndexImportCommandTest.php +++ b/Tests/Functional/Command/IndexImportCommandTest.php @@ -124,9 +124,6 @@ public function testIndexImportWithGzipOption($bulkSize, $realSize, $filename) */ private function getImportCommand() { - $command = new IndexImportCommand(); - $command->setContainer($this->getContainer()); - - return $command; + return new IndexImportCommand($this->getContainer()); } } diff --git a/Tests/Functional/Profiler/ElasticsearchProfilerTest.php b/Tests/Functional/Profiler/ElasticsearchProfilerTest.php index 646c6843..dc64e3ad 100644 --- a/Tests/Functional/Profiler/ElasticsearchProfilerTest.php +++ b/Tests/Functional/Profiler/ElasticsearchProfilerTest.php @@ -24,7 +24,7 @@ class ElasticsearchProfilerTest extends AbstractElasticsearchTestCase /** * {@inheritdoc} */ - protected function getDataArray() + protected function getDataArray(): array { return [ DummyDocument::class => [ diff --git a/Tests/Functional/Result/AggregationIteratorFindTest.php b/Tests/Functional/Result/AggregationIteratorFindTest.php index fb471ed1..2b72f2fc 100644 --- a/Tests/Functional/Result/AggregationIteratorFindTest.php +++ b/Tests/Functional/Result/AggregationIteratorFindTest.php @@ -21,7 +21,7 @@ class AggregationIteratorFindTest extends AbstractElasticsearchTestCase /** * {@inheritdoc} */ - protected function getDataArray() + protected function getDataArray(): array { return [ DummyDocument::class => [ diff --git a/Tests/Functional/Result/ArrayIteratorTest.php b/Tests/Functional/Result/ArrayIteratorTest.php index 0eb275ff..a26930bf 100644 --- a/Tests/Functional/Result/ArrayIteratorTest.php +++ b/Tests/Functional/Result/ArrayIteratorTest.php @@ -21,7 +21,7 @@ class ArrayIteratorTest extends AbstractElasticsearchTestCase { - protected function getDataArray() + protected function getDataArray(): array { return [ DummyDocument::class => [ diff --git a/Tests/Functional/Result/DocumentIteratorTest.php b/Tests/Functional/Result/DocumentIteratorTest.php index 6be40c45..0fd97136 100644 --- a/Tests/Functional/Result/DocumentIteratorTest.php +++ b/Tests/Functional/Result/DocumentIteratorTest.php @@ -22,7 +22,7 @@ class DocumentIteratorTest extends AbstractElasticsearchTestCase { - protected function getDataArray() + protected function getDataArray(): array { return [ DummyDocument::class => [ diff --git a/Tests/Functional/Result/DocumentWithNullObjectFieldTest.php b/Tests/Functional/Result/DocumentWithNullObjectFieldTest.php index cee6ddb0..66643bbd 100644 --- a/Tests/Functional/Result/DocumentWithNullObjectFieldTest.php +++ b/Tests/Functional/Result/DocumentWithNullObjectFieldTest.php @@ -15,7 +15,7 @@ class DocumentNullObjectFieldTest extends AbstractElasticsearchTestCase { - protected function getDataArray() + protected function getDataArray(): array { return [ DummyDocument::class => [ diff --git a/Tests/Functional/Result/GetDocumentSortTest.php b/Tests/Functional/Result/GetDocumentSortTest.php index 3a938ff2..8805d9e3 100644 --- a/Tests/Functional/Result/GetDocumentSortTest.php +++ b/Tests/Functional/Result/GetDocumentSortTest.php @@ -18,7 +18,7 @@ class GetDocumentSortTest extends AbstractElasticsearchTestCase { - protected function getDataArray() + protected function getDataArray(): array { return [ DummyDocument::class => [ diff --git a/Tests/Functional/Result/ObjectIteratorTest.php b/Tests/Functional/Result/ObjectIteratorTest.php index 77117878..de30fb69 100644 --- a/Tests/Functional/Result/ObjectIteratorTest.php +++ b/Tests/Functional/Result/ObjectIteratorTest.php @@ -19,7 +19,7 @@ class ObjectIteratorTest extends AbstractElasticsearchTestCase { - protected function getDataArray() + protected function getDataArray(): array { return [ DummyDocument::class => [ diff --git a/Tests/Functional/Service/IndexServiceTest.php b/Tests/Functional/Service/IndexServiceTest.php index 6eb6dc00..5d277188 100644 --- a/Tests/Functional/Service/IndexServiceTest.php +++ b/Tests/Functional/Service/IndexServiceTest.php @@ -21,7 +21,7 @@ */ class ManagerTest extends AbstractElasticsearchTestCase { - protected function getDataArray() + protected function getDataArray(): array { return [ DummyDocument::class => [ diff --git a/composer.json b/composer.json index 5a798852..defe1790 100644 --- a/composer.json +++ b/composer.json @@ -12,14 +12,14 @@ ], "require": { "php": "^7.1", - "symfony/framework-bundle": "^3.4|^4.1", - "symfony/dependency-injection": "^3.4|^4.1", - "symfony/console": "^3.4|^4.1", - "symfony/stopwatch": "^3.4|^4.1", - "symfony/finder": "^3.4|^4.1", - "symfony/serializer": "^3.4|^4.1", - "symfony/cache": "^3.4|^4.1", - "symfony/property-access": "^3.4|^4.1", + "symfony/framework-bundle": "^4.4|^5.0", + "symfony/dependency-injection": "^4.4|^5.0", + "symfony/console": "^4.4|^5.0", + "symfony/stopwatch": "^4.4|^5.0", + "symfony/finder": "^4.4|^5.0", + "symfony/serializer": "^4.4|^5.0", + "symfony/cache": "^4.4|^5.0", + "symfony/property-access": "^4.4|^5.0", "doctrine/annotations": "^1.6", "doctrine/cache": "^1.7", "doctrine/inflector": "^1.3", @@ -32,13 +32,12 @@ "mikey179/vfsstream": "~1.6", "phpunit/phpunit": "^7.0", "squizlabs/php_codesniffer": "^3.0", - "php-coveralls/php-coveralls": "^2.1", - "symfony/browser-kit" : "^3.4|^4.1", - "symfony/expression-language" : "^3.4|^4.1", - "symfony/twig-bundle": "^3.4|^4.1", - "symfony/yaml": "^3.4|^4.1", - "symfony/validator": "^3.4|^4.1", - "symfony/options-resolver": "^3.4|^4.1" + "symfony/browser-kit" : "^4.4|^5.0", + "symfony/expression-language" : "^4.4|^5.0", + "symfony/twig-bundle": "^4.4|^5.0", + "symfony/yaml": "^4.4|^5.0", + "symfony/validator": "^4.4|^5.0", + "symfony/options-resolver": "^4.4|^5.0" }, "autoload": { "psr-4": { "ONGR\\ElasticsearchBundle\\": "" }, From 4e119887f7cef0c18439867953291cc5a487d64b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= Date: Wed, 5 Feb 2020 18:23:36 +0200 Subject: [PATCH 10/13] update travis configuration --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d95df8a0..0f57fbdd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,12 +4,13 @@ php: - 7.1 - 7.2 - 7.3 + - 7.4 env: global: - ES_VERSION=6.2.3 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz matrix: - - SYMFONY="~3.4" - - SYMFONY="^4.1" + - SYMFONY="^4.4" + - SYMFONY="^5.0" install: - wget ${ES_DOWNLOAD_URL} - tar -xzf elasticsearch-${ES_VERSION}.tar.gz From a00f5a6453a4b0e0d48acfb098fe78f48291842c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= Date: Wed, 5 Feb 2020 18:28:21 +0200 Subject: [PATCH 11/13] exclude php 7.1 for symfony 5 since it is not supported --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0f57fbdd..d1efe231 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,10 @@ env: matrix: - SYMFONY="^4.4" - SYMFONY="^5.0" +jobs: + exclude: + - php: 7.1 + env: SYMFONY="^5.0" install: - wget ${ES_DOWNLOAD_URL} - tar -xzf elasticsearch-${ES_VERSION}.tar.gz From 4f488357a77f99350e93a6536f97b708231e80da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= Date: Wed, 5 Feb 2020 18:53:47 +0200 Subject: [PATCH 12/13] added buy me a coffee button --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5663b7f5..1a65ee6e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,12 @@ # ONGR Elasticsearch Bundle +[![Build Status](https://travis-ci.org/ongr-io/ElasticsearchBundle.svg?branch=master)](https://travis-ci.org/ongr-io/ElasticsearchBundle) +[![Latest Stable Version](https://poser.pugx.org/ongr/elasticsearch-bundle/v/stable)](https://packagist.org/packages/ongr/elasticsearch-bundle) +[![codecov](https://codecov.io/gh/ongr-io/ElasticsearchBundle/branch/master/graph/badge.svg)](https://codecov.io/gh/ongr-io/ElasticsearchBundle) +[![Total Downloads](https://poser.pugx.org/ongr/elasticsearch-bundle/downloads)](https://packagist.org/packages/ongr/elasticsearch-bundle) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ongr-io/ElasticsearchBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ongr-io/ElasticsearchBundle/?branch=master) + + Elasticsearch Bundle was created in order to serve the need for professional [Elasticsearch][1] integration with enterprise level Symfony applications. This bundle is: @@ -21,12 +28,9 @@ Technical goodies: If you need any help, [stack overflow][3] is the preferred way to get answers. is the preferred and recommended way to ask questions about ONGR bundles and libraries. +If you like this library, help me to develop it by buying a cup of coffee -[![Build Status](https://travis-ci.org/ongr-io/ElasticsearchBundle.svg?branch=master)](https://travis-ci.org/ongr-io/ElasticsearchBundle) -[![Latest Stable Version](https://poser.pugx.org/ongr/elasticsearch-bundle/v/stable)](https://packagist.org/packages/ongr/elasticsearch-bundle) -[![codecov](https://codecov.io/gh/ongr-io/ElasticsearchBundle/branch/master/graph/badge.svg)](https://codecov.io/gh/ongr-io/ElasticsearchBundle) -[![Total Downloads](https://poser.pugx.org/ongr/elasticsearch-bundle/downloads)](https://packagist.org/packages/ongr/elasticsearch-bundle) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ongr-io/ElasticsearchBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ongr-io/ElasticsearchBundle/?branch=master) +Buy Me A Coffee ## Version matrix From f5359012752aa2eefb2ce77e24832bc888c2d1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= Date: Wed, 5 Feb 2020 19:20:49 +0200 Subject: [PATCH 13/13] fix php 7.4 incompatibility issues --- Service/ExportService.php | 2 +- Service/ImportService.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Service/ExportService.php b/Service/ExportService.php index fba2949f..6997a7e8 100644 --- a/Service/ExportService.php +++ b/Service/ExportService.php @@ -99,7 +99,7 @@ public function exportIndex( */ protected function getFilePath($filename): string { - if ($filename{0} == '/' || strstr($filename, ':') !== false) { + if ($filename[0] == '/' || strstr($filename, ':') !== false) { return $filename; } diff --git a/Service/ImportService.php b/Service/ImportService.php index 83cd73ba..3fa43572 100644 --- a/Service/ImportService.php +++ b/Service/ImportService.php @@ -65,7 +65,7 @@ public function importIndex( */ protected function getFilePath($filename) { - if ($filename{0} == '/' || strstr($filename, ':') !== false) { + if ($filename[0] == '/' || strstr($filename, ':') !== false) { return $filename; }