Merge pull request #133 from Codappix/feature/131-index-page-on-cache-clear

FEATURE: Index page if cache was cleared
This commit is contained in:
Daniel Siepmann 2018-03-14 11:37:05 +01:00 committed by GitHub
commit 26b8849104
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 184 additions and 21 deletions

View file

@ -99,6 +99,24 @@ class DataHandler implements Singleton
} }
} }
public function clearCachePostProc(array $parameters, CoreDataHandler $dataHandler)
{
$pageUid = 0;
// If editor uses "small page blizzard"
if (isset($parameters['cacheCmd']) && is_numeric($parameters['cacheCmd'])) {
$pageUid = $parameters['cacheCmd'];
}
// If records were changed
if (isset($parameters['uid_page']) && is_numeric($parameters['uid_page'])) {
$pageUid = $parameters['uid_page'];
}
if ($pageUid > 0) {
$this->processRecord('pages', (int) $pageUid);
}
}
protected function processRecord(string $table, int $uid) : bool protected function processRecord(string $table, int $uid) : bool
{ {
if (! $this->shouldProcessHookForTable($table)) { if (! $this->shouldProcessHookForTable($table)) {

View file

@ -5,5 +5,6 @@ Changelog
:maxdepth: 1 :maxdepth: 1
:glob: :glob:
changelog/20180408-131-respect-page-cache-clear
changelog/20180408-introduce-php70-type-hints changelog/20180408-introduce-php70-type-hints
changelog/20180406-120-facet-configuration changelog/20180406-120-facet-configuration

View file

@ -0,0 +1,14 @@
Feature 131 "Pages do not get indexed if content has changed"
=============================================================
Previously we only used DataHandler hooks triggered when processing records. This way we did not
index a page when content has changed.
We now also use cache clear hooks of DataHandler to index pages whenever their cache get cleared.
This way we also index a page if an integrator configured to clear further pages if content was
changed.
Still there are limitations. We do not get informed for pages which got cleared due to attached
caches via TypoScript.
See :issue:`131`.

View file

@ -47,7 +47,11 @@ class NonAllowedTablesTest extends AbstractDataHandlerTest
*/ */
public function deletionWillNotBeTriggeredForSysCategories() public function deletionWillNotBeTriggeredForSysCategories()
{ {
$this->subject->expects($this->exactly(0))->method('delete'); $this->subject->expects($this->exactly(1))
->method('update')
->with('pages', $this->callback(function (array $record) {
return isset($record['uid']) && $record['uid'] === 1;
}));
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class); $tce = GeneralUtility::makeInstance(Typo3DataHandler::class);
$tce->stripslashes_values = 0; $tce->stripslashes_values = 0;
@ -66,7 +70,11 @@ class NonAllowedTablesTest extends AbstractDataHandlerTest
*/ */
public function updateWillNotBeTriggeredForExistingSysCategory() public function updateWillNotBeTriggeredForExistingSysCategory()
{ {
$this->subject->expects($this->exactly(0))->method('update'); $this->subject->expects($this->exactly(1))
->method('update')
->with('pages', $this->callback(function (array $record) {
return isset($record['uid']) && $record['uid'] === 1;
}));
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class); $tce = GeneralUtility::makeInstance(Typo3DataHandler::class);
$tce->stripslashes_values = 0; $tce->stripslashes_values = 0;
@ -85,7 +93,11 @@ class NonAllowedTablesTest extends AbstractDataHandlerTest
*/ */
public function updateWillNotBeTriggeredForNewSysCategoy() public function updateWillNotBeTriggeredForNewSysCategoy()
{ {
$this->subject->expects($this->exactly(0))->method('update'); $this->subject->expects($this->exactly(1))
->method('update')
->with('pages', $this->callback(function (array $record) {
return isset($record['uid']) && $record['uid'] === 1;
}));
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class); $tce = GeneralUtility::makeInstance(Typo3DataHandler::class);
$tce->stripslashes_values = 0; $tce->stripslashes_values = 0;

View file

@ -50,6 +50,11 @@ class ProcessesAllowedTablesTest extends AbstractDataHandlerTest
$this->subject->expects($this->exactly(1)) $this->subject->expects($this->exactly(1))
->method('delete') ->method('delete')
->with($this->equalTo('tt_content'), $this->equalTo('1')); ->with($this->equalTo('tt_content'), $this->equalTo('1'));
$this->subject->expects($this->exactly(1))
->method('update')
->with('pages', $this->callback(function (array $record) {
return isset($record['uid']) && $record['uid'] === 1;
}));
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class); $tce = GeneralUtility::makeInstance(Typo3DataHandler::class);
$tce->stripslashes_values = 0; $tce->stripslashes_values = 0;
@ -68,15 +73,23 @@ class ProcessesAllowedTablesTest extends AbstractDataHandlerTest
*/ */
public function updateWillBeTriggeredForExistingTtContent() public function updateWillBeTriggeredForExistingTtContent()
{ {
$this->subject->expects($this->exactly(1))->method('update') $this->subject->expects($this->exactly(2))->method('update')
->with( ->withConsecutive(
$this->equalTo('tt_content'), [
$this->callback(function ($record) { $this->equalTo('tt_content'),
return isset($record['uid']) && $record['uid'] === 1 $this->callback(function ($record) {
&& isset($record['pid']) && $record['pid'] === 1 return isset($record['uid']) && $record['uid'] === 1
&& isset($record['colPos']) && $record['colPos'] === 1 && isset($record['pid']) && $record['pid'] === 1
; && isset($record['colPos']) && $record['colPos'] === 1
}) ;
})
],
[
$this->equalTo('pages'),
$this->callback(function ($record) {
return isset($record['uid']) && $record['uid'] === 1;
})
]
); );
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class); $tce = GeneralUtility::makeInstance(Typo3DataHandler::class);
@ -96,15 +109,23 @@ class ProcessesAllowedTablesTest extends AbstractDataHandlerTest
*/ */
public function updateWillBeTriggeredForNewTtContent() public function updateWillBeTriggeredForNewTtContent()
{ {
$this->subject->expects($this->exactly(1))->method('update') $this->subject->expects($this->exactly(2))->method('update')
->with( ->withConsecutive(
$this->equalTo('tt_content'), [
$this->callback(function ($record) { $this->equalTo('tt_content'),
return isset($record['uid']) && $record['uid'] === 2 $this->callback(function ($record) {
&& isset($record['pid']) && $record['pid'] === 1 return isset($record['uid']) && $record['uid'] === 2
&& isset($record['header']) && $record['header'] === 'a new record' && isset($record['pid']) && $record['pid'] === 1
; && isset($record['header']) && $record['header'] === 'a new record'
}) ;
})
],
[
$this->equalTo('pages'),
$this->callback(function ($record) {
return isset($record['uid']) && $record['uid'] === 1;
})
]
); );
$tce = GeneralUtility::makeInstance(Typo3DataHandler::class); $tce = GeneralUtility::makeInstance(Typo3DataHandler::class);

View file

@ -0,0 +1,94 @@
<?php
namespace Codappix\SearchCore\Tests\Unit\Hook;
/*
* Copyright (C) 2018 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\Domain\Service\DataHandler as OwnDataHandler;
use Codappix\SearchCore\Hook\DataHandler;
use Codappix\SearchCore\Tests\Unit\AbstractUnitTestCase;
use TYPO3\CMS\Core\DataHandling\DataHandler as CoreDataHandler;
class DataHandlerToProcessorTest extends AbstractUnitTestCase
{
/**
* @test
* @dataProvider getPossibleCallCombinations
*/
public function fieldsAreCopiedAsConfigured(array $parameters, bool $expectCall)
{
$coreDataHandlerMock = $this->getMockBuilder(CoreDataHandler::class)->getMock();
$ownDataHandlerMock = $this->getMockBuilder(OwnDataHandler::class)
->disableOriginalConstructor()
->getMock();
$subject = $this->getMockBuilder(DataHandler::class)
->setConstructorArgs([$ownDataHandlerMock])
->setMethods(['getRecord'])
->getMock();
$ownDataHandlerMock->expects($this->any())
->method('supportsTable')
->willReturn(true);
if ($expectCall) {
$subject->expects($this->once())
->method('getRecord')
->with('pages', 10)
->willReturn(['uid' => 10]);
$ownDataHandlerMock->expects($this->once())
->method('update')
->with('pages', ['uid' => 10]);
} else {
$subject->expects($this->never())
->method('getRecord');
$ownDataHandlerMock->expects($this->never())
->method('update');
}
$subject->clearCachePostProc($parameters, $coreDataHandlerMock);
}
public function getPossibleCallCombinations() : array
{
return [
'Editor triggered cache clear of page manual' => [
'parameters' => [
'cacheCmd' => '10',
],
'expectCall' => true,
],
'Editor changed records on a page' => [
'parameters' => [
'uid_page' =>10,
],
'expectCall' => true,
],
'Something unexpected' => [
'parameters' => [],
'expectCall' => false,
],
'Something unexpected' => [
'parameters' => [
'cacheCmd' => 'something like a tag?!',
],
'expectCall' => false,
],
];
}
}

View file

@ -15,6 +15,9 @@ call_user_func(
], ],
], ],
't3lib/class.t3lib_tcemain.php' => [ 't3lib/class.t3lib_tcemain.php' => [
'clearCachePostProc' => [
$extensionKey => \Codappix\SearchCore\Hook\DataHandler::class . '->clearCachePostProc',
],
'processCmdmapClass' => [ 'processCmdmapClass' => [
$extensionKey => \Codappix\SearchCore\Hook\DataHandler::class, $extensionKey => \Codappix\SearchCore\Hook\DataHandler::class,
], ],