mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-25 22:56:16 +01:00
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:
commit
fef2bdac89
7 changed files with 32 additions and 109 deletions
|
@ -83,16 +83,6 @@ class DataHandler implements Singleton
|
||||||
$this->indexerFactory = $indexerFactory;
|
$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
|
* @param string $table
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -92,42 +92,36 @@ class DataHandler implements Singleton
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function processDatamap_afterAllOperations(CoreDataHandler $dataHandler)
|
||||||
* Called by CoreDataHandler on database operations, e.g. if new records were created or records were updated.
|
{
|
||||||
*
|
foreach ($dataHandler->datamap as $table => $record) {
|
||||||
* @param string $status
|
$uid = key($record);
|
||||||
* @param string $table
|
$fieldData = current($record);
|
||||||
* @param string|int $uid
|
|
||||||
* @param array $fieldArray
|
if (isset($fieldArray['uid'])) {
|
||||||
* @param CoreDataHandler $dataHandler
|
$uid = $fieldArray['uid'];
|
||||||
*
|
} elseif (isset($dataHandler->substNEWwithIDs[$uid])) {
|
||||||
* @return bool False if hook was not processed.
|
$uid = $dataHandler->substNEWwithIDs[$uid];
|
||||||
*/
|
}
|
||||||
public function processDatamap_afterDatabaseOperations($status, $table, $uid, array $fieldArray, CoreDataHandler $dataHandler)
|
|
||||||
|
$this->processRecord($table, $uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function processRecord(string $table, int $uid) : bool
|
||||||
{
|
{
|
||||||
if (! $this->shouldProcessHookForTable($table)) {
|
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;
|
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);
|
$record = $this->getRecord($table, $uid);
|
||||||
if ($record !== null) {
|
if ($record !== null) {
|
||||||
$this->dataHandler->update($table, $record);
|
$this->dataHandler->update($table, $record);
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->logger->debug(
|
$this->logger->debug('Indexing of record not processed, as he was not found in Database.', [$table, $uid]);
|
||||||
'Database update not processed, cause status is unhandled.',
|
|
||||||
[$status, $table, $uid, $fieldArray]
|
|
||||||
);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,10 +58,8 @@ class DataHandlerFinisher extends AbstractFinisher
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case 'update':
|
case 'update':
|
||||||
$this->dataHandler->update($tableName, $record);
|
|
||||||
break;
|
|
||||||
case 'add':
|
case 'add':
|
||||||
$this->dataHandler->add($tableName, $record);
|
$this->dataHandler->update($tableName, $record);
|
||||||
break;
|
break;
|
||||||
case 'delete':
|
case 'delete':
|
||||||
$this->dataHandler->delete($tableName, $record['uid']);
|
$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
|
* @test
|
||||||
*/
|
*/
|
||||||
public function updateWillNotBeTriggeredForSysCategory()
|
public function updateWillNotBeTriggeredForExistingSysCategory()
|
||||||
{
|
{
|
||||||
$this->subject->expects($this->exactly(0))->method('update');
|
$this->subject->expects($this->exactly(0))->method('update');
|
||||||
|
|
||||||
|
@ -83,9 +83,9 @@ class NonAllowedTablesTest extends AbstractDataHandlerTest
|
||||||
/**
|
/**
|
||||||
* @test
|
* @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 = GeneralUtility::makeInstance(Typo3DataHandler::class);
|
||||||
$tce->stripslashes_values = 0;
|
$tce->stripslashes_values = 0;
|
||||||
|
|
|
@ -66,7 +66,7 @@ class ProcessesAllowedTablesTest extends AbstractDataHandlerTest
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function updateWillBeTriggeredForTtContent()
|
public function updateWillBeTriggeredForExistingTtContent()
|
||||||
{
|
{
|
||||||
$this->subject->expects($this->exactly(1))->method('update')
|
$this->subject->expects($this->exactly(1))->method('update')
|
||||||
->with(
|
->with(
|
||||||
|
@ -94,9 +94,9 @@ class ProcessesAllowedTablesTest extends AbstractDataHandlerTest
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function addWillBeTriggeredForTtContent()
|
public function updateWillBeTriggeredForNewTtContent()
|
||||||
{
|
{
|
||||||
$this->subject->expects($this->exactly(1))->method('add')
|
$this->subject->expects($this->exactly(1))->method('update')
|
||||||
->with(
|
->with(
|
||||||
$this->equalTo('tt_content'),
|
$this->equalTo('tt_content'),
|
||||||
$this->callback(function ($record) {
|
$this->callback(function ($record) {
|
||||||
|
|
|
@ -83,19 +83,14 @@ class DataHandlerFinisherTest extends AbstractUnitTestCase
|
||||||
public function possibleFinisherSetup() : array
|
public function possibleFinisherSetup() : array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'valid add configuration' => [
|
|
||||||
'action' => 'add',
|
|
||||||
'nonCalledActions' => ['delete', 'update'],
|
|
||||||
'expectedSecondArgument' => ['uid' => 23],
|
|
||||||
],
|
|
||||||
'valid update configuration' => [
|
'valid update configuration' => [
|
||||||
'action' => 'update',
|
'action' => 'update',
|
||||||
'nonCalledActions' => ['delete', 'add'],
|
'nonCalledActions' => ['delete'],
|
||||||
'expectedSecondArgument' => ['uid' => 23],
|
'expectedSecondArgument' => ['uid' => 23],
|
||||||
],
|
],
|
||||||
'valid delete configuration' => [
|
'valid delete configuration' => [
|
||||||
'action' => 'delete',
|
'action' => 'delete',
|
||||||
'nonCalledActions' => ['update', 'add'],
|
'nonCalledActions' => ['update'],
|
||||||
'expectedSecondArgument' => 23,
|
'expectedSecondArgument' => 23,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
@ -109,7 +104,7 @@ class DataHandlerFinisherTest extends AbstractUnitTestCase
|
||||||
{
|
{
|
||||||
$this->subject->setOptions($options);
|
$this->subject->setOptions($options);
|
||||||
|
|
||||||
foreach (['add', 'update', 'delete'] as $nonCalledAction) {
|
foreach (['update', 'delete'] as $nonCalledAction) {
|
||||||
$this->dataHandlerMock->expects($this->never())->method($nonCalledAction);
|
$this->dataHandlerMock->expects($this->never())->method($nonCalledAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue