From 5141e84b476966ab9b297b8672dc6d600d65f1d8 Mon Sep 17 00:00:00 2001 From: pmishev Date: Tue, 16 Mar 2021 17:56:50 +0000 Subject: [PATCH] [BC] Removed DocumentMetadata::getType() Wait until ES server is up before running travis tests Updated typehints and docs --- .travis.yml | 1 + .../Provider/AbstractDoctrineProvider.php | 8 +++---- Document/Provider/AbstractProvider.php | 6 ++--- Document/Provider/ElasticsearchProvider.php | 16 +++++++++----- Document/Provider/ProviderRegistry.php | 18 +++++++-------- Document/Repository/Repository.php | 2 +- Mapping/DocumentMetadata.php | 22 ++++++------------- Resources/doc/commands.md | 2 +- Resources/doc/dataproviders.md | 2 +- Resources/doc/mapping.md | 4 +--- Resources/doc/search.md | 2 +- Resources/doc/setup.md | 2 +- Result/DocumentConverter.php | 18 ++++++++------- 13 files changed, 50 insertions(+), 53 deletions(-) diff --git a/.travis.yml b/.travis.yml index fae4647..e658f53 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,7 @@ before_script: - export XDEBUG_MODE=coverage script: + - wget -q --waitretry=1 --retry-connrefused -T 10 -O - http://127.0.0.1:9200 - vendor/bin/simple-phpunit --coverage-clover=Tests/App/build/clover.xml 2>/dev/null - vendor/bin/phpcs -np --standard=PSR2 --ignore=vendor/,Tests/App/,var/ ./ diff --git a/Document/Provider/AbstractDoctrineProvider.php b/Document/Provider/AbstractDoctrineProvider.php index f6c6e37..da134e0 100644 --- a/Document/Provider/AbstractDoctrineProvider.php +++ b/Document/Provider/AbstractDoctrineProvider.php @@ -38,10 +38,10 @@ abstract class AbstractDoctrineProvider extends AbstractProvider protected $sourceDataHydration = AbstractQuery::HYDRATE_OBJECT; /** - * @param string $documentClass The type the provider is for + * @param string $documentClass The document class the provider is for * @param EntityManagerInterface $em The Doctrine entity manager */ - public function __construct($documentClass, EntityManagerInterface $em) + public function __construct(string $documentClass, EntityManagerInterface $em) { parent::__construct($documentClass); $this->em = $em; @@ -50,7 +50,7 @@ public function __construct($documentClass, EntityManagerInterface $em) /** * @param int $batchSize */ - public function setBatchSize($batchSize) + public function setBatchSize(int $batchSize) { $this->batchSize = $batchSize; } @@ -60,7 +60,7 @@ public function setBatchSize($batchSize) * * @return Query */ - abstract public function getQuery(); + abstract public function getQuery(): Query; /** * Converts a Doctrine entity to Elasticsearch entity diff --git a/Document/Provider/AbstractProvider.php b/Document/Provider/AbstractProvider.php index 4e6b9ff..b94c06a 100644 --- a/Document/Provider/AbstractProvider.php +++ b/Document/Provider/AbstractProvider.php @@ -10,14 +10,14 @@ abstract class AbstractProvider implements ProviderInterface { /** - * @var string The type the provider is for + * @var string The document class the provider is for */ private $documentClass; /** - * @param string $documentClass The type the provider is for + * @param string $documentClass The document class the provider is for */ - public function __construct($documentClass) + public function __construct(string $documentClass) { $this->documentClass = $documentClass; } diff --git a/Document/Provider/ElasticsearchProvider.php b/Document/Provider/ElasticsearchProvider.php index 907512b..bc7607f 100644 --- a/Document/Provider/ElasticsearchProvider.php +++ b/Document/Provider/ElasticsearchProvider.php @@ -23,7 +23,7 @@ class ElasticsearchProvider extends AbstractProvider protected $sourceIndexManager; /** - * @var string The type the data is coming from + * @var string The document class the data is coming from */ protected $sourceDocumentClass; @@ -38,13 +38,17 @@ class ElasticsearchProvider extends AbstractProvider protected $chunkSize = 500; /** - * @param string $documentClass The type the provider is for + * @param string $documentClass The document class the provider is for * @param DocumentMetadataCollector $metadataCollector The metadata collector * @param IndexManager $sourceIndexManager The index manager of the data source - * @param string $sourceDocumentClass The type the data is coming from + * @param string $sourceDocumentClass The document class the data is coming from */ - public function __construct($documentClass, DocumentMetadataCollector $metadataCollector, IndexManager $sourceIndexManager, $sourceDocumentClass) - { + public function __construct( + string $documentClass, + DocumentMetadataCollector $metadataCollector, + IndexManager $sourceIndexManager, + string $sourceDocumentClass + ) { parent::__construct($documentClass); $this->sourceIndexManager = $sourceIndexManager; $this->metadataCollector = $metadataCollector; @@ -87,7 +91,7 @@ public function getDocuments() * * @return array */ - public function getDocument($id) + public function getDocument($id): array { $params = [ 'index' => $this->sourceIndexManager->getLiveIndex(), diff --git a/Document/Provider/ProviderRegistry.php b/Document/Provider/ProviderRegistry.php index daa2121..7fed467 100644 --- a/Document/Provider/ProviderRegistry.php +++ b/Document/Provider/ProviderRegistry.php @@ -8,7 +8,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareTrait; /** - * References persistence providers for each index and type. + * References persistence providers for each index. */ class ProviderRegistry implements ContainerAwareInterface { @@ -53,9 +53,9 @@ public function __construct( /** - * Registers a provider service for the specified type entity. + * Registers a provider service for the specified document class. * - * @param string $documentClass The FQN or alias to the type entity + * @param string $documentClass The FQN or alias to the document class * @param string $providerId The provider service id */ public function addProvider(string $documentClass, string $providerId) : void @@ -64,9 +64,9 @@ public function addProvider(string $documentClass, string $providerId) : void } /** - * Unsets registered provider for the specified type entity. + * Unsets registered provider for the specified document class. * - * @param string $documentClass The FQN or alias to the type entity + * @param string $documentClass The FQN or alias to the document class */ public function removeProvider(string $documentClass) : void { @@ -74,9 +74,9 @@ public function removeProvider(string $documentClass) : void } /** - * Gets registered provider service id for the specified type entity. + * Gets registered provider service id for the specified document class. * - * @param string $documentClass The FQN or alias to the type entity + * @param string $documentClass The FQN or alias to the document class * * @return string|null */ @@ -88,13 +88,13 @@ public function getProviderId(string $documentClass) : ?string } /** - * Gets the provider for a type. + * Gets the provider for a document class. * * @param string $documentClass FQN or alias (e.g App:Entity) * * @return ProviderInterface * - * @throws \InvalidArgumentException if no provider was registered for the type + * @throws \InvalidArgumentException if no provider was registered for the document class */ public function getProviderInstance(string $documentClass) : ProviderInterface { diff --git a/Document/Repository/Repository.php b/Document/Repository/Repository.php index 1b3e32c..42ca1aa 100644 --- a/Document/Repository/Repository.php +++ b/Document/Repository/Repository.php @@ -31,7 +31,7 @@ class Repository protected $finder; /** - * The type metadata + * The document metadata * * @var DocumentMetadata */ diff --git a/Mapping/DocumentMetadata.php b/Mapping/DocumentMetadata.php index e08affb..b6034bd 100644 --- a/Mapping/DocumentMetadata.php +++ b/Mapping/DocumentMetadata.php @@ -41,11 +41,11 @@ protected function configureOptions(OptionsResolver $optionsResolver) } /** - * Retrieves type mapping for the Elasticsearch client + * Retrieves index mapping for the Elasticsearch client * * @return array */ - public function getClientMapping() + public function getClientMapping(): array { $mapping = array_filter( array_merge( @@ -64,7 +64,7 @@ function ($value) { /** * @return array */ - public function getProperties() + public function getProperties(): array { return $this->metadata['properties']; } @@ -72,7 +72,7 @@ public function getProperties() /** * @return array */ - public function getPropertiesMetadata() + public function getPropertiesMetadata(): array { return $this->metadata['propertiesMetadata']; } @@ -80,7 +80,7 @@ public function getPropertiesMetadata() /** * @return array */ - public function getFields() + public function getFields(): array { return $this->metadata['fields']; } @@ -88,7 +88,7 @@ public function getFields() /** * @return string|null */ - public function getRepositoryClass() + public function getRepositoryClass(): ?string { return $this->metadata['repositoryClass']; } @@ -96,16 +96,8 @@ public function getRepositoryClass() /** * @return string */ - public function getClassName() + public function getClassName(): string { return $this->metadata['className']; } - - /** - * @return string - */ - public function getType() - { - return $this->metadata['type']; - } } diff --git a/Resources/doc/commands.md b/Resources/doc/commands.md index dbc4686..6bda480 100644 --- a/Resources/doc/commands.md +++ b/Resources/doc/commands.md @@ -12,7 +12,7 @@ Creates a new index in Elasticsearch for the specified manager with the configur Command name: `sineflow:es:index:build ` -Rebuilds the data in the specified index, using the configured data providers for each type in the index. If no data providers are configured, by default a *self* provider is registered for each type, so the index would be rebuilt from itself - useful when mapping has changed and you need to update it. +Rebuilds the data in the specified index, using the configured data provider. If no data provider is configured, by default a *self* provider is registered, so the index would be rebuilt from itself - useful when mapping has changed, and you need to update it. An important thing to note is that currently this command will only work if you have set `use_aliases: true` in your index configuration. What it does is, it creates a new index and points the *write* alias to it, as well as to the old one. When building the new index is complete without errors, both read and write aliases are pointed to it and removed from the old one. diff --git a/Resources/doc/dataproviders.md b/Resources/doc/dataproviders.md index 351ce9c..c32420d 100644 --- a/Resources/doc/dataproviders.md +++ b/Resources/doc/dataproviders.md @@ -4,7 +4,7 @@ Simply put, data providers are the sources of data for your Elasticsearch indice By default, each index is assigned a default *self* data provider (`ElasticsearchProvider`), which retrieves the data from the Elasticsearch index itself. This is useful when you want to rebuild the index (like if you changed the mapping and want to update it). -In order to define your own custom data provider for a certain type, you have to create a service that implements `ProviderInterface` and tag it as `sfes.provider`, specifying the entity it is for in the `type` argument: +In order to define your own custom data provider for an index, you have to create a service that implements `ProviderInterface` and tag it as `sfes.provider`, specifying the entity it is for in the `type` argument: ``` services: diff --git a/Resources/doc/mapping.md b/Resources/doc/mapping.md index 046cbac..c610f57 100644 --- a/Resources/doc/mapping.md +++ b/Resources/doc/mapping.md @@ -4,7 +4,7 @@ The Elasticsearch bundle requires document mapping definitions to create the cor ## Document class annotations -Elasticsearch type mappings are defined using annotations within document entity classes that implement DocumentInterface: +Elasticsearch index mappings are defined using annotations within document entity classes that implement DocumentInterface: ```php count($searchBody); ## Searching in multiple types and indices -It is convenient to search in a single type as shown above, but sometime you may wish to search in multiple indices and/or types. The finder service comes in play: +It is convenient to search in a single index as shown above, but sometime you may wish to search in multiple indices. The finder service comes in play: ```php $finder = $this->get('sfes.finder'); diff --git a/Resources/doc/setup.md b/Resources/doc/setup.md index dd8c506..4f28589 100644 --- a/Resources/doc/setup.md +++ b/Resources/doc/setup.md @@ -51,7 +51,7 @@ sineflow_elasticsearch: > This is the very basic example only, for a more detailed description of configuration options, please take a look at the [configuration](configuration.md) chapter. -A couple of things to note in this example: `dev_customer` is the name of the physical index in Elasticsearch and `App:Customer` represents the class where the document type mapping is defined. (more info at [the mapping chapter](mapping.md)). +A couple of things to note in this example: `dev_customer` is the name of the physical index in Elasticsearch and `App:Customer` represents the class where the document mapping is defined. (more info at [the mapping chapter](mapping.md)). ### Step 4: Define your Elasticsearch types as `Document` objects diff --git a/Result/DocumentConverter.php b/Result/DocumentConverter.php index 9fdf55d..6b1ddff 100644 --- a/Result/DocumentConverter.php +++ b/Result/DocumentConverter.php @@ -30,7 +30,7 @@ class DocumentConverter * @param DocumentMetadataCollector $metadataCollector * @param string $languageSeparator */ - public function __construct(DocumentMetadataCollector $metadataCollector, $languageSeparator) + public function __construct(DocumentMetadataCollector $metadataCollector, string $languageSeparator) { $this->metadataCollector = $metadataCollector; $this->languageSeparator = $languageSeparator; @@ -45,7 +45,7 @@ public function __construct(DocumentMetadataCollector $metadataCollector, $langu * * @return DocumentInterface */ - public function convertToDocument($rawData, $documentClass) + public function convertToDocument(array $rawData, string $documentClass) { // Get document metadata $metadata = $this->metadataCollector->getDocumentMetadata($documentClass); @@ -94,7 +94,7 @@ public function convertToDocument($rawData, $documentClass) * * @return ObjectInterface */ - public function assignArrayToObject(array $array, ObjectInterface $object, array $propertiesMetadata) + public function assignArrayToObject(array $array, ObjectInterface $object, array $propertiesMetadata): ObjectInterface { foreach ($propertiesMetadata as $esField => $propertyMetadata) { // Skip fields from the mapping that have no value set, unless they are multilanguage fields @@ -160,8 +160,10 @@ public function assignArrayToObject(array $array, ObjectInterface $object, array * @param array $propertiesMetadata * * @return array + * + * @throws \ReflectionException */ - public function convertToArray(ObjectInterface $object, $propertiesMetadata = []) + public function convertToArray(ObjectInterface $object, $propertiesMetadata = []): array { if (empty($propertiesMetadata)) { $propertiesMetadata = $this->metadataCollector->getObjectPropertiesMetadata(get_class($object)); @@ -209,18 +211,18 @@ public function convertToArray(ObjectInterface $object, $propertiesMetadata = [] } /** - * Check if object is the correct type + * Check if object is the correct class * * @param ObjectInterface $object - * @param array $expectedClass + * @param string $expectedClass * * @throws \InvalidArgumentException */ - private function checkObjectType(ObjectInterface $object, $expectedClass) + private function checkObjectType(ObjectInterface $object, string $expectedClass) { if (get_class($object) !== $expectedClass) { throw new \InvalidArgumentException( - sprintf('Expected object of type "%s", got "%s"', $expectedClass, get_class($object)) + sprintf('Expected object of "%s", got "%s"', $expectedClass, get_class($object)) ); } }