diff --git a/Classes/Controller/CrawlerController.php b/Classes/Controller/CrawlerController.php index e99fef4d9..90cad3277 100644 --- a/Classes/Controller/CrawlerController.php +++ b/Classes/Controller/CrawlerController.php @@ -599,18 +599,9 @@ public function readUrl($queueId, $force = false, string $processId = '') 'result_data' => json_encode($result), ]; - /** @var AfterQueueItemAddedEvent $event */ - $event = $this->eventDispatcher->dispatch(new AfterQueueItemAddedEvent($queueId, $field_array)); - $field_array = $event->getFieldArray(); - - //This should be extracted, we should listen to the event ourself, - // and move the code block here to an appropiate place. /Tomas 2024-10-07 - GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(QueueRepository::TABLE_NAME) - ->update(QueueRepository::TABLE_NAME, $field_array, [ - 'qid' => (int) $queueId, - ]); - + $this->eventDispatcher->dispatch(new AfterQueueItemAddedEvent($queueId, $field_array)); $this->logger?->debug('crawler-readurl stop ' . microtime(true)); + return $ret; } @@ -637,13 +628,7 @@ public function readUrlFromArray($field_array) 'result_data' => json_encode($result), ]; - /** @var AfterQueueItemAddedEvent $event */ - $event = $this->eventDispatcher->dispatch(new AfterQueueItemAddedEvent($queueId, $field_array)); - $field_array = $event->getFieldArray(); - - $connectionForCrawlerQueue->update(QueueRepository::TABLE_NAME, $field_array, [ - 'qid' => $queueId, - ]); + $this->eventDispatcher->dispatch(new AfterQueueItemAddedEvent($queueId, $field_array)); return $result; } diff --git a/Classes/EventListener/AfterQueueItemAddedEventListener.php b/Classes/EventListener/AfterQueueItemAddedEventListener.php new file mode 100644 index 000000000..894b7ce97 --- /dev/null +++ b/Classes/EventListener/AfterQueueItemAddedEventListener.php @@ -0,0 +1,21 @@ +getConnectionForTable(QueueRepository::TABLE_NAME) + ->update(QueueRepository::TABLE_NAME, $event->getFieldArray(), [ + 'qid' => (int) $event->getQueueId(), + ]); + } +} diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index b124a0c2b..404201d2a 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -94,3 +94,8 @@ services: AOE\Crawler\ContextMenu\ItemProvider: tags: - name: backend.contextmenu.itemprovider + + AOE\Crawler\EventListener\AfterQueueItemAddedEventListener: + tags: + - name: event.listener + identifier: 'tx-crawler-after-queue-item-added' diff --git a/Tests/Functional/EventListener/AfterQueueItemAddedEventListenerTest.php b/Tests/Functional/EventListener/AfterQueueItemAddedEventListenerTest.php new file mode 100644 index 000000000..aba5718f0 --- /dev/null +++ b/Tests/Functional/EventListener/AfterQueueItemAddedEventListenerTest.php @@ -0,0 +1,43 @@ +eventDispatcher = GeneralUtility::makeInstance(EventDispatcher::class); + $this->queueRepository = GeneralUtility::makeInstance(QueueRepository::class); + $this->importCSVDataSet(__DIR__ . '/../Fixtures/tx_crawler_queue.csv'); + } + + #[Test] + public function listenerIsInvoked(): void + { + $event = new AfterQueueItemAddedEvent(1001, [ + 'parameters' => 'test params', + ]); + $this->eventDispatcher->dispatch($event); + + $queueItem = $this->queueRepository->getQueueEntriesByQid(1001, true); + self::assertEquals('test params', $queueItem['parameters']); + } +}