mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 04:56:11 +01:00
Feature/improve scrutinizer (#3)
* TASK: Fix scrutinizer issues * TASK: Add library dependency * FIX: Adjust php and TYPO3 requirements * TASK: Adjust test
This commit is contained in:
parent
b079dd8125
commit
e75f24092e
16 changed files with 96 additions and 102 deletions
|
@ -1,9 +1,11 @@
|
|||
filter:
|
||||
excluded_paths:
|
||||
- 'Configuration/*'
|
||||
- 'Documentation/*'
|
||||
- 'Resources/JavaScript/*'
|
||||
- 'Resources/*'
|
||||
paths:
|
||||
- 'Classes/*'
|
||||
- 'Tests/*'
|
||||
tools:
|
||||
|
||||
php_cpd:
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -29,7 +29,7 @@ use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
|
|||
class IndexerFactory implements Singleton
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@ interface IndexerInterface
|
|||
{
|
||||
/**
|
||||
* Index the index.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index();
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -134,7 +134,6 @@ class DataHandlerTest extends UnitTestCase
|
|||
->method('update')
|
||||
->with(
|
||||
$this->equalTo($table),
|
||||
$this->equalTo($recordUid),
|
||||
$this->equalTo($record)
|
||||
);
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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' => [],
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue