Merge pull request #115 from Codappix/feature/112-resolve-relations-for-new-records

BUGFIX: Allow indexing of new records with their relations
This commit is contained in:
Daniel Siepmann 2018-02-23 10:20:58 +01:00 committed by GitHub
commit fef2bdac89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 109 deletions

View file

@ -83,16 +83,6 @@ class DataHandler implements Singleton
$this->indexerFactory = $indexerFactory;
}
/**
* @param string $table
* @param array $record
*/
public function add($table, array $record)
{
$this->logger->debug('Record received for add.', [$table, $record]);
$this->getIndexer($table)->indexDocument($record['uid']);
}
/**
* @param string $table
*/

View file

@ -92,42 +92,36 @@ class DataHandler implements Singleton
return true;
}
/**
* Called by CoreDataHandler on database operations, e.g. if new records were created or records were updated.
*
* @param string $status
* @param string $table
* @param string|int $uid
* @param array $fieldArray
* @param CoreDataHandler $dataHandler
*
* @return bool False if hook was not processed.
*/
public function processDatamap_afterDatabaseOperations($status, $table, $uid, array $fieldArray, CoreDataHandler $dataHandler)
public function processDatamap_afterAllOperations(CoreDataHandler $dataHandler)
{
foreach ($dataHandler->datamap as $table => $record) {
$uid = key($record);
$fieldData = current($record);
if (isset($fieldArray['uid'])) {
$uid = $fieldArray['uid'];
} elseif (isset($dataHandler->substNEWwithIDs[$uid])) {
$uid = $dataHandler->substNEWwithIDs[$uid];
}
$this->processRecord($table, $uid);
}
}
protected function processRecord(string $table, int $uid) : bool
{
if (! $this->shouldProcessHookForTable($table)) {
$this->logger->debug('Database update not processed.', [$table, $uid]);
$this->logger->debug('Indexing of record not processed.', [$table, $uid]);
return false;
}
if ($status === 'new') {
$fieldArray['uid'] = $dataHandler->substNEWwithIDs[$uid];
$this->dataHandler->add($table, $fieldArray);
return true;
}
if ($status === 'update') {
$record = $this->getRecord($table, $uid);
if ($record !== null) {
$this->dataHandler->update($table, $record);
}
return true;
}
$this->logger->debug(
'Database update not processed, cause status is unhandled.',
[$status, $table, $uid, $fieldArray]
);
$this->logger->debug('Indexing of record not processed, as he was not found in Database.', [$table, $uid]);
return false;
}

View file

@ -58,10 +58,8 @@ class DataHandlerFinisher extends AbstractFinisher
switch ($action) {
case 'update':
$this->dataHandler->update($tableName, $record);
break;
case 'add':
$this->dataHandler->add($tableName, $record);
$this->dataHandler->update($tableName, $record);
break;
case 'delete':
$this->dataHandler->delete($tableName, $record['uid']);

View file

@ -1,54 +0,0 @@
<?php
namespace Codappix\SearchCore\Tests\Functional\Hooks\DataHandler;
/*
* Copyright (C) 2016 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
use Codappix\SearchCore\Domain\Service\DataHandler as DataHandlerService;
use Codappix\SearchCore\Hook\DataHandler as DataHandlerHook;
use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
class IgnoresUnkownOperationTest extends AbstractDataHandlerTest
{
/**
* @var DataHandlerService|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface
*/
protected $subject;
/**
* @test
*/
public function dataHandlerCommandSomethingIsIgnored()
{
$subject = new DataHandlerHook($this->subject);
$this->assertFalse(
$subject->processDatamap_afterDatabaseOperations(
'something',
'tt_content',
1,
[],
new Typo3DataHandler
),
'Hook processed status "something".'
);
}
}

View file

@ -64,7 +64,7 @@ class NonAllowedTablesTest extends AbstractDataHandlerTest
/**
* @test
*/
public function updateWillNotBeTriggeredForSysCategory()
public function updateWillNotBeTriggeredForExistingSysCategory()
{
$this->subject->expects($this->exactly(0))->method('update');
@ -83,9 +83,9 @@ class NonAllowedTablesTest extends AbstractDataHandlerTest
/**
* @test
*/
public function addWillNotBeTriggeredForSysCategoy()
public function updateWillNotBeTriggeredForNewSysCategoy()
{
$this->subject->expects($this->exactly(0))->method('add');
$this->subject->expects($this->exactly(0))->method('update');
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class);
$tce->stripslashes_values = 0;

View file

@ -66,7 +66,7 @@ class ProcessesAllowedTablesTest extends AbstractDataHandlerTest
/**
* @test
*/
public function updateWillBeTriggeredForTtContent()
public function updateWillBeTriggeredForExistingTtContent()
{
$this->subject->expects($this->exactly(1))->method('update')
->with(
@ -94,9 +94,9 @@ class ProcessesAllowedTablesTest extends AbstractDataHandlerTest
/**
* @test
*/
public function addWillBeTriggeredForTtContent()
public function updateWillBeTriggeredForNewTtContent()
{
$this->subject->expects($this->exactly(1))->method('add')
$this->subject->expects($this->exactly(1))->method('update')
->with(
$this->equalTo('tt_content'),
$this->callback(function ($record) {

View file

@ -83,19 +83,14 @@ class DataHandlerFinisherTest extends AbstractUnitTestCase
public function possibleFinisherSetup() : array
{
return [
'valid add configuration' => [
'action' => 'add',
'nonCalledActions' => ['delete', 'update'],
'expectedSecondArgument' => ['uid' => 23],
],
'valid update configuration' => [
'action' => 'update',
'nonCalledActions' => ['delete', 'add'],
'nonCalledActions' => ['delete'],
'expectedSecondArgument' => ['uid' => 23],
],
'valid delete configuration' => [
'action' => 'delete',
'nonCalledActions' => ['update', 'add'],
'nonCalledActions' => ['update'],
'expectedSecondArgument' => 23,
],
];
@ -109,7 +104,7 @@ class DataHandlerFinisherTest extends AbstractUnitTestCase
{
$this->subject->setOptions($options);
foreach (['add', 'update', 'delete'] as $nonCalledAction) {
foreach (['update', 'delete'] as $nonCalledAction) {
$this->dataHandlerMock->expects($this->never())->method($nonCalledAction);
}