From 203b5d7adf4112273f55de57e9b877789811f69e Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Fri, 16 Mar 2018 17:37:19 +0100 Subject: [PATCH 1/2] TASK: Prevent issue When hook is called with non uid If some issues occur outside of our extension, we might not get a valid uid inside of our hooks. We will therefore add additional checks and prevent any further execution. Resolves: #112 --- Classes/Hook/DataHandler.php | 6 ++++- Tests/Unit/Hook/DataHandlerTest.php | 42 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Classes/Hook/DataHandler.php b/Classes/Hook/DataHandler.php index e0b8e40..6c3da5c 100644 --- a/Classes/Hook/DataHandler.php +++ b/Classes/Hook/DataHandler.php @@ -72,7 +72,7 @@ class DataHandler implements Singleton /** * Called by CoreDataHandler on deletion of records. */ - public function processCmdmap_deleteAction(string $table, int $uid) : bool + public function processCmdmap_deleteAction(string $table, string $uid) : bool { if (! $this->shouldProcessHookForTable($table)) { $this->logger->debug('Delete not processed.', [$table, $uid]); @@ -95,6 +95,10 @@ class DataHandler implements Singleton $uid = $dataHandler->substNEWwithIDs[$uid]; } + if (!is_numeric($uid) || $uid <= 0) { + continue; + } + $this->processRecord($table, $uid); } } diff --git a/Tests/Unit/Hook/DataHandlerTest.php b/Tests/Unit/Hook/DataHandlerTest.php index ed68993..60da2e6 100644 --- a/Tests/Unit/Hook/DataHandlerTest.php +++ b/Tests/Unit/Hook/DataHandlerTest.php @@ -91,4 +91,46 @@ class DataHandlerToProcessorTest extends AbstractUnitTestCase ], ]; } + + /** + * @test + */ + public function indexingIsNotCalledForCacheClearIfDataIsInvalid() + { + $coreDataHandlerMock = $this->getMockBuilder(CoreDataHandler::class)->getMock(); + $ownDataHandlerMock = $this->getMockBuilder(OwnDataHandler::class) + ->disableOriginalConstructor() + ->getMock(); + + $subject = new DataHandler($ownDataHandlerMock); + + $ownDataHandlerMock->expects($this->never())->method('update'); + + $subject->clearCachePostProc([ + 'cacheCmd' => 'NEW343', + ], $coreDataHandlerMock); + } + /** + * @test + */ + public function indexingIsNotCalledForProcesIfDataIsInvalid() + { + $coreDataHandlerMock = $this->getMockBuilder(CoreDataHandler::class)->getMock(); + $coreDataHandlerMock->datamap = [ + 'tt_content' => [ + 'NEW343' => [], + ], + ]; + $coreDataHandlerMock->substNEWwithIDs = []; + + $ownDataHandlerMock = $this->getMockBuilder(OwnDataHandler::class) + ->disableOriginalConstructor() + ->getMock(); + + $subject = new DataHandler($ownDataHandlerMock); + + $ownDataHandlerMock->expects($this->never())->method('update'); + + $subject->processDatamap_afterAllOperations($coreDataHandlerMock); + } } From 5c493aad2117dbf9cf90b2d1c1c0cae9225d17b3 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 20 Mar 2018 14:18:47 +0100 Subject: [PATCH 2/2] TASK: Fix typo in test method name --- Tests/Unit/Hook/DataHandlerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/Hook/DataHandlerTest.php b/Tests/Unit/Hook/DataHandlerTest.php index 60da2e6..aaf3935 100644 --- a/Tests/Unit/Hook/DataHandlerTest.php +++ b/Tests/Unit/Hook/DataHandlerTest.php @@ -113,7 +113,7 @@ class DataHandlerToProcessorTest extends AbstractUnitTestCase /** * @test */ - public function indexingIsNotCalledForProcesIfDataIsInvalid() + public function indexingIsNotCalledForProcessIfDataIsInvalid() { $coreDataHandlerMock = $this->getMockBuilder(CoreDataHandler::class)->getMock(); $coreDataHandlerMock->datamap = [