-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Add flushed and edited pages to crawler queue (#271)
- Loading branch information
1 parent
7a98c98
commit 0d88d0a
Showing
12 changed files
with
229 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AOE\Crawler\Hooks; | ||
|
||
/* | ||
* (c) 2020 AOE GmbH <[email protected]> | ||
* | ||
* This file is part of the TYPO3 Crawler Extension. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use AOE\Crawler\Api\CrawlerApi; | ||
use AOE\Crawler\Domain\Repository\QueueRepository; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Extbase\Object\ObjectManager; | ||
|
||
class DataHandlerHook | ||
{ | ||
public function addFlushedPagesToCrawlerQueue(array $parameters, \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler): void | ||
{ | ||
$pageIdsToBeFlushedFromCache = $parameters['pageIdArray']; | ||
if (empty($pageIdsToBeFlushedFromCache)) { | ||
return; | ||
} | ||
foreach ($pageIdsToBeFlushedFromCache as $pageId) { | ||
$pageId = (int) $pageId; | ||
if ($pageId < 1) { | ||
continue; | ||
} | ||
if ($this->getQueueRepository()->isPageInQueue($pageId)) { | ||
continue; | ||
} | ||
$this->getCrawlerApi()->addPageToQueue($pageId); | ||
} | ||
} | ||
|
||
private function getQueueRepository(): QueueRepository | ||
{ | ||
return GeneralUtility::makeInstance(ObjectManager::class)->get(QueueRepository::class); | ||
} | ||
|
||
private function getCrawlerApi(): CrawlerApi | ||
{ | ||
return GeneralUtility::makeInstance(ObjectManager::class)->get(CrawlerApi::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.. include:: /Includes.txt | ||
|
||
============================ | ||
Automatic add pages to Queue | ||
============================ | ||
|
||
Since 9.1.0 | ||
|
||
Edit Pages | ||
---------- | ||
|
||
With this feature, you will automatically add pages to the crawler queue | ||
when you are editing content on the page, unless it's within a workspace, then | ||
it will not be added to the queue before it's published. | ||
|
||
This functionality gives you the advantages that you would not need to keep track | ||
of which pages you have edited, it will automatically be handle on next crawler | ||
process task, see :ref:`executing-the-queue-label`. This ensure that | ||
your cache or e.g. Search Index is always up to date and the end-users will see | ||
the most current content as soon as possible. | ||
|
||
Clear Page Single Cache | ||
----------------------- | ||
|
||
As the edit and clear page cache function is using the same dataHandler hooks, | ||
we have an additional feature for free. When you clear the page cache for a specific | ||
page then it will also be added automatically to the crawler queue. Again this will | ||
be processed during the next crawler process. | ||
|
||
.. figure:: /Images/backend_clear_cache.png | ||
:alt: Clearing the page cache | ||
|
||
Clearing the page cache | ||
|
||
.. figure:: /Images/backend_clear_cache_queue.png | ||
:alt: Page is added to the crawler queue | ||
|
||
Page is added to the crawler queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,5 +47,4 @@ Example:: | |
|
||
return false; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AOE\Crawler\Tests\Unit\Hooks; | ||
|
||
/* | ||
* (c) 2020 AOE GmbH <[email protected]> | ||
* | ||
* This file is part of the TYPO3 Crawler Extension. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use AOE\Crawler\Api\CrawlerApi; | ||
use AOE\Crawler\Domain\Repository\QueueRepository; | ||
use AOE\Crawler\Hooks\DataHandlerHook; | ||
use Nimut\TestingFramework\TestCase\UnitTestCase; | ||
use Prophecy\Argument; | ||
use TYPO3\CMS\Core\Cache\CacheManager; | ||
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface; | ||
use TYPO3\CMS\Core\DataHandling\DataHandler; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Extbase\Object\ObjectManager; | ||
|
||
class DataHandlerHookTest extends UnitTestCase | ||
{ | ||
/** | ||
* Page with ID 1 is not in queue, should be added | ||
* Page with ID 2 is already in queue. Should NOT be added. | ||
* | ||
* @test | ||
*/ | ||
public function itShouldAddPageToQueue(): void | ||
{ | ||
$dataHandlerHook = new DataHandlerHook(); | ||
|
||
$crawlerApi = $this->prophesize(CrawlerApi::class); | ||
$crawlerApi->addPageToQueue(1)->shouldBeCalled(); | ||
|
||
$queueRepository = $this->prophesize(QueueRepository::class); | ||
$queueRepository->isPageInQueue(1)->willReturn(false); | ||
$queueRepository->isPageInQueue(2)->willReturn(true); | ||
|
||
$objectManager = $this->prophesize(ObjectManager::class); | ||
$objectManager->get(QueueRepository::class)->willReturn($queueRepository->reveal()); | ||
$objectManager->get(CrawlerApi::class)->willReturn($crawlerApi->reveal()); | ||
|
||
$cacheManager = $this->prophesize(CacheManager::class); | ||
$cacheManager->getCache(Argument::any())->willReturn($this->prophesize(FrontendInterface::class)->reveal()); | ||
|
||
GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManager->reveal()); | ||
GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal()); | ||
|
||
$dataHandler = new DataHandler(); | ||
|
||
$dataHandlerHook->addFlushedPagesToCrawlerQueue( | ||
[ | ||
'table' => 'pages', | ||
'pageIdArray' => [0, 1, 2], | ||
], | ||
$dataHandler | ||
); | ||
} | ||
|
||
/** | ||
* Page with ID 1 is not in queue, should be added | ||
* Page with ID 2 is already in queue. Should NOT be added. | ||
* Page with ID 3 is not in queue, should be added | ||
* | ||
* @test | ||
*/ | ||
public function itShouldAddPageToQueueWithMorePages(): void | ||
{ | ||
$dataHandlerHook = new DataHandlerHook(); | ||
$crawlerApi = $this->prophesize(CrawlerApi::class); | ||
$crawlerApi->addPageToQueue(1)->shouldBeCalled(); | ||
$crawlerApi->addPageToQueue(3)->shouldBeCalled(); | ||
|
||
$queueRepository = $this->prophesize(QueueRepository::class); | ||
$queueRepository->isPageInQueue(1)->willReturn(false); | ||
$queueRepository->isPageInQueue(2)->willReturn(true); | ||
$queueRepository->isPageInQueue(3)->willReturn(false); | ||
|
||
$objectManager = $this->prophesize(ObjectManager::class); | ||
$objectManager->get(QueueRepository::class)->willReturn($queueRepository->reveal()); | ||
$objectManager->get(CrawlerApi::class)->willReturn($crawlerApi->reveal()); | ||
|
||
$cacheManager = $this->prophesize(CacheManager::class); | ||
$cacheManager->getCache(Argument::any())->willReturn($this->prophesize(FrontendInterface::class)->reveal()); | ||
|
||
GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManager->reveal()); | ||
GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal()); | ||
|
||
$dataHandler = new DataHandler(); | ||
|
||
$dataHandlerHook->addFlushedPagesToCrawlerQueue( | ||
[ | ||
'table' => 'tt_content', | ||
'pageIdArray' => [0, 1, 2, 3], | ||
], | ||
$dataHandler | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
declare(strict_types=1); | ||
|
||
namespace AOE\Crawler\Tests\Unit\Hook; | ||
namespace AOE\Crawler\Tests\Unit\Hooks; | ||
|
||
/* | ||
* (c) 2020 AOE GmbH <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php | ||
defined('TYPO3_MODE') or die(); | ||
|
||
\AOE\Crawler\Utility\HookUtility::registerHooks($_EXTKEY); | ||
\AOE\Crawler\Utility\HookUtility::registerHooks('crawler'); | ||
\AOE\Crawler\Utility\BackendUtility::registerIcons(); | ||
|
||
$GLOBALS['TYPO3_CONF_VARS']['BE']['ContextMenu']['ItemProviders'][1566472321] = \AOE\Crawler\ContextMenu\ItemProvider::class; |