mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 01:36:11 +01:00
BUGFIX: Allow indexing of new records with their relations
Relations were inserted by TYPO3's DataHandler after indexing and were therefore not indexed. We now use a later hook after DataHandler has finished everything, so we know that we can index. As it's not relevant, we do not differentiate between add and update anymore, as both trigger "indexDocument" internal. Resolves: #112
This commit is contained in:
parent
07c9d5a136
commit
47b3282034
7 changed files with 32 additions and 109 deletions
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
$record = $this->getRecord($table, $uid);
|
||||
if ($record !== null) {
|
||||
$this->dataHandler->update($table, $record);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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']);
|
||||
|
|
|
@ -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".'
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue