diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 31e46af..7cbd254 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,9 +1,11 @@ filter: excluded_paths: + - 'Configuration/*' - 'Documentation/*' - - 'Resources/JavaScript/*' + - 'Resources/*' paths: - 'Classes/*' + - 'Tests/*' tools: php_cpd: diff --git a/Classes/Connection/ConnectionInterface.php b/Classes/Connection/ConnectionInterface.php index ca3474d..65acdeb 100644 --- a/Classes/Connection/ConnectionInterface.php +++ b/Classes/Connection/ConnectionInterface.php @@ -26,49 +26,50 @@ namespace Leonmrni\SearchCore\Connection; interface ConnectionInterface { /** - * Will add a new document, based on his identifier and record type. + * Will add a new document. * - * @param string $recordType - * @param int $identifier - * @param array $record + * @param string $documentType + * @param array $document * - * @return + * @return void */ - public function add($recordType, $identifier, array $record); + public function add($documentType, array $document); /** - * Add the given records. + * Add the given documents. * - * @param string $recordType - * @param array $records + * @param string $documentType + * @param array $documents + * + * @return void */ - public function addDocuments($recordType, array $records); + public function addDocuments($documentType, array $documents); /** - * Will update an existing document, based on his identifier and record type. + * Will update an existing document. * - * @param string $recordType - * @param int $identifier - * @param array $record + * @param string $documentType + * @param array $document * - * @return + * @return void */ - public function update($recordType, $identifier, array $record); + public function update($documentType, array $document); /** - * Will remove an existing document, based on his identifier and record type. + * Will remove an existing document. * - * @param string $recordType + * @param string $documentType * @param int $identifier * - * @return + * @return void */ - public function delete($recordType, $identifier); + public function delete($documentType, $identifier); /** * Search by given request and return result. * * @param SearchRequestInterface $searchRequest + * * @return SearchResultInterface */ public function search(SearchRequestInterface $searchRequest); diff --git a/Classes/Connection/Elasticsearch.php b/Classes/Connection/Elasticsearch.php index 118139a..3c518e7 100644 --- a/Classes/Connection/Elasticsearch.php +++ b/Classes/Connection/Elasticsearch.php @@ -33,17 +33,17 @@ class Elasticsearch implements Singleton, ConnectionInterface protected $connection; /** - * @var IndexFactory + * @var Elasticsearch\IndexFactory */ protected $indexFactory; /** - * @var TypeFactory + * @var Elasticsearch\TypeFactory */ protected $typeFactory; /** - * @var DocumentFactory + * @var Elasticsearch\DocumentFactory */ protected $documentFactory; @@ -80,44 +80,39 @@ class Elasticsearch implements Singleton, ConnectionInterface $this->documentFactory = $documentFactory; } - public function add($recordType, $identifier, array $record) + public function add($documentType, array $document) { throw new \Exception('Implement', 1481190734); } - public function delete($recordType, $identifier) + public function delete($documentType, $identifier) { throw new \Exception('Implement', 1481190734); } - public function update($tableName, $identifier, array $record) + public function update($documentType, array $document) { - $this->addDocument($tableName, $identifier, $record); - } - - protected function addDocument($tableName, $identifier, array $record) - { - throw new \Exception('Implement', 1481192791); + throw new \Exception('Implement', 1481190734); } /** - * Add the given records to elasticsearch. + * Add the given documents to elasticsearch. * - * @param string $tableName - * @param array $records + * @param string $documentType + * @param array $documents */ - public function addDocuments($tableName, array $records) + public function addDocuments($documentType, array $documents) { $type = $this->typeFactory->getType( $this->indexFactory->getIndex( $this->connection, - $tableName + $documentType ), - $tableName + $documentType ); $type->addDocuments( - $this->documentFactory->getDocuments($tableName, $records) + $this->documentFactory->getDocuments($documentType, $documents) ); $type->getIndex()->refresh(); diff --git a/Classes/Connection/Elasticsearch/DocumentFactory.php b/Classes/Connection/Elasticsearch/DocumentFactory.php index 5b58aa8..43462fe 100644 --- a/Classes/Connection/Elasticsearch/DocumentFactory.php +++ b/Classes/Connection/Elasticsearch/DocumentFactory.php @@ -43,40 +43,42 @@ class DocumentFactory implements Singleton } /** - * Creates document from record. + * Creates document from document. * - * @param string $tableName - * @param array $record + * @param string $documentType + * @param array $document * * @return \Elastica\Document */ - public function getDocument($tableName, array $record) + public function getDocument($documentType, array $document) { - if (!isset($record['search_identifier'])) { - throw new \Exception('No search_identifier provided for record.', 1481194385); + // TODO: Use DocumentType for further configuration. + + if (!isset($document['search_identifier'])) { + throw new \Exception('No search_identifier provided for document.', 1481194385); } - $identifier = $record['search_identifier']; - unset($record['search_identifier']); + $identifier = $document['search_identifier']; + unset($document['search_identifier']); - $this->logger->debug('Convert record to document', [$identifier, $record]); - return new \Elastica\Document($identifier, $record); + $this->logger->debug('Convert document to document', [$identifier, $document]); + return new \Elastica\Document($identifier, $document); } /** - * Creates documents based on records. + * Creates documents based on documents. * - * @param string $tableName - * @param array $records + * @param string $documentType + * @param array $documents * * @return array */ - public function getDocuments($tableName, array $records) + public function getDocuments($documentType, array $documents) { - foreach ($records as &$record) { - $record = $this->getDocument($tableName, $record); + foreach ($documents as &$document) { + $document = $this->getDocument($documentType, $document); } - return $records; + return $documents; } } diff --git a/Classes/Connection/Elasticsearch/IndexFactory.php b/Classes/Connection/Elasticsearch/IndexFactory.php index 54d648b..0a06ad4 100644 --- a/Classes/Connection/Elasticsearch/IndexFactory.php +++ b/Classes/Connection/Elasticsearch/IndexFactory.php @@ -20,6 +20,7 @@ namespace Leonmrni\SearchCore\Connection\Elasticsearch; * 02110-1301, USA. */ +use Elastica\Exception\ResponseException; use TYPO3\CMS\Core\SingletonInterface as Singleton; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; @@ -34,20 +35,20 @@ class IndexFactory implements Singleton * Get an index bases on TYPO3 table name. * * @param Connection $connection - * @param string $tableName + * @param string $documentType * * @return \Elastica\Index */ - public function getIndex(Connection $connection, $tableName) + public function getIndex(Connection $connection, $documentType) { - // TODO: Fetch index name from configuration, based on $tableName. + // TODO: Fetch index name from configuration, based on $documentType. $index = $connection->getClient()->getIndex('typo3content'); try { // TODO: Provide configuration?! // http://elastica.io/getting-started/storing-and-indexing-documents.html#section-analysis $index->create(); - } catch (\Elastica\Exception\ResponseException $exception) { + } catch (ResponseException $exception) { if (stripos($exception->getMessage(), 'already exists') === false) { throw $exception; } diff --git a/Classes/Connection/Elasticsearch/TypeFactory.php b/Classes/Connection/Elasticsearch/TypeFactory.php index 7fa7adc..b529937 100644 --- a/Classes/Connection/Elasticsearch/TypeFactory.php +++ b/Classes/Connection/Elasticsearch/TypeFactory.php @@ -34,12 +34,12 @@ class TypeFactory implements Singleton * Get an index bases on TYPO3 table name. * * @param \Elastica\Index $index - * @param string $tableName + * @param string $documentType * * @return \Elastica\Type */ - public function getType(\Elastica\Index $index, $tableName) + public function getType(\Elastica\Index $index, $documentType) { - return $index->getType($tableName); + return $index->getType($documentType); } } diff --git a/Classes/Controller/SearchController.php b/Classes/Controller/SearchController.php index 9f4873c..b7624f7 100644 --- a/Classes/Controller/SearchController.php +++ b/Classes/Controller/SearchController.php @@ -47,7 +47,7 @@ class SearchController extends ActionController /** * Process a search and deliver original request and result to view. * - * @param SearchRequest $searchRequest + * @param null|SearchRequest $searchRequest */ public function searchAction(SearchRequest $searchRequest = null) { diff --git a/Classes/Domain/Index/IndexerFactory.php b/Classes/Domain/Index/IndexerFactory.php index 0f99396..4ecbfb9 100644 --- a/Classes/Domain/Index/IndexerFactory.php +++ b/Classes/Domain/Index/IndexerFactory.php @@ -29,7 +29,7 @@ use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; class IndexerFactory implements Singleton { /** - * @var ObjectManager + * @var ObjectManagerInterface */ protected $objectManager; diff --git a/Classes/Domain/Index/IndexerInterface.php b/Classes/Domain/Index/IndexerInterface.php index da93f5d..af5ceca 100644 --- a/Classes/Domain/Index/IndexerInterface.php +++ b/Classes/Domain/Index/IndexerInterface.php @@ -27,6 +27,8 @@ interface IndexerInterface { /** * Index the index. + * + * @return void */ public function index(); } diff --git a/Classes/Domain/Index/TcaIndexer.php b/Classes/Domain/Index/TcaIndexer.php index 1dd303e..7e6671a 100644 --- a/Classes/Domain/Index/TcaIndexer.php +++ b/Classes/Domain/Index/TcaIndexer.php @@ -54,7 +54,7 @@ class TcaIndexer implements IndexerInterface } /** - * @param string $tableName + * @param TcaIndexer\TcaTableService $tcaTableService * @param ConnectionInterface $connection */ public function __construct( @@ -76,7 +76,7 @@ class TcaIndexer implements IndexerInterface } /** - * @return \Iterator + * @return \Generator */ protected function getRecordGenerator() { diff --git a/Classes/Domain/Index/TcaIndexer/TcaTableService.php b/Classes/Domain/Index/TcaIndexer/TcaTableService.php index e30cbd6..4cb38f6 100644 --- a/Classes/Domain/Index/TcaIndexer/TcaTableService.php +++ b/Classes/Domain/Index/TcaIndexer/TcaTableService.php @@ -132,11 +132,7 @@ class TcaTableService */ protected function isRelation(array &$columnConfig) { - if (isset($columnConfig['foreign_table'])) { - return true; - } - - return false; + return isset($columnConfig['foreign_table']); } /** @@ -158,10 +154,7 @@ class TcaTableService $this->tca['ctrl']['languageField'], $this->tca['ctrl']['origUid'], ]; - if (in_array($columnName, $systemFields)) { - return true; - } - return false; + return in_array($columnName, $systemFields); } } diff --git a/Classes/Domain/Service/DataHandler.php b/Classes/Domain/Service/DataHandler.php index 110dd98..66913e1 100644 --- a/Classes/Domain/Service/DataHandler.php +++ b/Classes/Domain/Service/DataHandler.php @@ -63,22 +63,20 @@ class DataHandler implements Singleton /** * @param string $table - * @param int $identifier * @param array $record */ - public function add($table, $identifier, array $record) + public function add($table, array $record) { - $this->logger->debug('Record received for add.', [$table, $identifier, $record]); - $this->connection->add($table, $identifier, $record); + $this->logger->debug('Record received for add.', [$table, $record]); + $this->connection->add($table, $record); } /** * @param string $table - * @param int $identifier */ - public function update($table, $identifier, array $record) + public function update($table, array $record) { - $this->logger->debug('Record received for update.', [$table, $identifier, $record]); - $this->connection->update($table, $identifier, $record); + $this->logger->debug('Record received for update.', [$table, $record]); + $this->connection->update($table, $record); } } diff --git a/Classes/Hook/DataHandler.php b/Classes/Hook/DataHandler.php index 21d8565..a413aa2 100644 --- a/Classes/Hook/DataHandler.php +++ b/Classes/Hook/DataHandler.php @@ -74,11 +74,8 @@ class DataHandler implements Singleton * * @param string $table * @param int $uid - * @param array $record - * @param bool $recordWasDeleted - * @param CoreDataHandler $dataHandler */ - public function processCmdmap_deleteAction($table, $uid, array $record, $recordWasDeleted, CoreDataHandler $dataHandler) + public function processCmdmap_deleteAction($table, $uid) { if (! $this->shouldProcessTable($table)) { $this->logger->debug('Delete not processed, cause table is not allowed.', [$table]); @@ -105,20 +102,23 @@ class DataHandler implements Singleton } if ($status === 'new') { - $this->dataHandler->add($table, $dataHandler->substNEWwithIDs[$uid], $fieldArray); + $fieldArray['uid'] = $dataHandler->substNEWwithIDs[$uid]; + $this->dataHandler->add($table, $fieldArray); return; } if ($status === 'update') { - $this->dataHandler->update( - $table, - $uid, - $this->getRecord($table, $uid) - ); + $record = $this->getRecord($table, $uid); + if ($record !== null) { + $this->dataHandler->update($table, $record); + } return; } - $this->logger->debug('Database update not processed, cause status is unhandled.', [$status, $table, $uid, $fieldArray]); + $this->logger->debug( + 'Database update not processed, cause status is unhandled.', + [$status, $table, $uid, $fieldArray] + ); } /** @@ -126,7 +126,7 @@ class DataHandler implements Singleton * * TODO: Fetch from config * - * @return array + * @return string[] */ protected function getTablesToProcess() { @@ -149,7 +149,7 @@ class DataHandler implements Singleton * * @param string $table * @param int $uid - * @return array + * @return null|array */ protected function getRecord($table, $uid) { diff --git a/Tests/Unit/Hook/DataHandlerTest.php b/Tests/Unit/Hook/DataHandlerTest.php index cf01df6..50b346d 100644 --- a/Tests/Unit/Hook/DataHandlerTest.php +++ b/Tests/Unit/Hook/DataHandlerTest.php @@ -134,7 +134,6 @@ class DataHandlerTest extends UnitTestCase ->method('update') ->with( $this->equalTo($table), - $this->equalTo($recordUid), $this->equalTo($record) ); diff --git a/composer.json b/composer.json index b8fea1d..8ac7521 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ }, "require" : { "php": ">=5.6.0", - "typo3/cms": ">=6.2.0" + "typo3/cms": ">=6.2.0", + "ruflin/elastica": "~1.4" }, "require-dev": { "phpunit/phpunit": "~4.8.0" diff --git a/ext_emconf.php b/ext_emconf.php index 185982f..8614d21 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -6,8 +6,8 @@ $EM_CONF[$_EXTKEY] = [ 'category' => 'be', 'constraints' => [ 'depends' => [ - 'typo3' => '7.6.2-8.99.99', - 'php' => '7.0.0-7.99.99' + 'typo3' => '6.2.0-8.99.99', + 'php' => '5.6.0-7.99.99' ], 'conflicts' => [], ],