-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from netlogix/TYPO3_11
TYPO3 11.5
- Loading branch information
Showing
21 changed files
with
302 additions
and
230 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netlogix\Nxcachetags\EventListener; | ||
|
||
use Netlogix\Nxcachetags\Service\CacheTagService; | ||
use TYPO3\CMS\Extbase\Event\Persistence\EntityAddedToPersistenceEvent; | ||
|
||
class EntityAddedToPersistence | ||
{ | ||
/** | ||
* @var CacheTagService | ||
*/ | ||
protected CacheTagService $cacheTagService; | ||
|
||
public function injectCacheTagService(CacheTagService $cacheTagService) | ||
{ | ||
$this->cacheTagService = $cacheTagService; | ||
} | ||
|
||
public function __invoke(EntityAddedToPersistenceEvent $event): void | ||
{ | ||
$tags = $this->cacheTagService->createCacheTags($event->getObject()); | ||
|
||
foreach ($tags as $tag) { | ||
$this->cacheTagService->flushCachesByTag($tag); | ||
} | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netlogix\Nxcachetags\EventListener; | ||
|
||
use Netlogix\Nxcachetags\Service\CacheTagService; | ||
use TYPO3\CMS\Extbase\Event\Persistence\EntityRemovedFromPersistenceEvent; | ||
|
||
class EntityRemovedFromPersistence | ||
{ | ||
/** | ||
* @var CacheTagService | ||
*/ | ||
protected CacheTagService $cacheTagService; | ||
|
||
public function injectCacheTagService(CacheTagService $cacheTagService) | ||
{ | ||
$this->cacheTagService = $cacheTagService; | ||
} | ||
|
||
public function __invoke(EntityRemovedFromPersistenceEvent $event): void | ||
{ | ||
$tags = $this->cacheTagService->createCacheTags($event->getObject()); | ||
|
||
foreach ($tags as $tag) { | ||
$this->cacheTagService->flushCachesByTag($tag); | ||
} | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netlogix\Nxcachetags\EventListener; | ||
|
||
use Netlogix\Nxcachetags\Service\CacheTagService; | ||
use TYPO3\CMS\Extbase\Event\Persistence\EntityUpdatedInPersistenceEvent; | ||
|
||
class EntityUpdatedInPersistence | ||
{ | ||
/** | ||
* @var CacheTagService | ||
*/ | ||
protected CacheTagService $cacheTagService; | ||
|
||
public function injectCacheTagService(CacheTagService $cacheTagService) | ||
{ | ||
$this->cacheTagService = $cacheTagService; | ||
} | ||
|
||
public function __invoke(EntityUpdatedInPersistenceEvent $event): void | ||
{ | ||
$tags = $this->cacheTagService->createCacheTags($event->getObject()); | ||
|
||
foreach ($tags as $tag) { | ||
$this->cacheTagService->flushCachesByTag($tag); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,31 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
Netlogix\Nxcachetags\: | ||
resource: '../Classes/*' | ||
|
||
Netlogix\Nxcachetags\Service\RenderingContextIdentificationService: | ||
# the parent class has in inject for `ViewHelperVariableContainer` which cannot be injected | ||
# disable autowiring for this class and let TYPO3 do the work | ||
autowire: false | ||
|
||
Netlogix\Nxcachetags\EventListener\EntityAddedToPersistence: | ||
tags: | ||
- name: event.listener | ||
identifier: 'nxcachetags-afterInsertObject' | ||
event: TYPO3\CMS\Extbase\Event\Persistence\EntityAddedToPersistenceEvent | ||
|
||
Netlogix\Nxcachetags\EventListener\EntityUpdatedInPersistence: | ||
tags: | ||
- name: event.listener | ||
identifier: 'nxcachetags-afterUpdateObject' | ||
event: TYPO3\CMS\Extbase\Event\Persistence\EntityUpdatedInPersistenceEvent | ||
|
||
Netlogix\Nxcachetags\EventListener\EntityRemovedFromPersistence: | ||
tags: | ||
- name: event.listener | ||
identifier: 'nxcachetags-afterRemoveObject' | ||
event: TYPO3\CMS\Extbase\Event\Persistence\EntityRemovedFromPersistenceEvent |
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
45 changes: 45 additions & 0 deletions
45
Tests/Functional/EventListener/EntityAddedToPersistenceTest.php
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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netlogix\Nxcachetags\Tests\Functional\EventListener; | ||
|
||
use Netlogix\Nxcachetags\EventListener\EntityAddedToPersistence; | ||
use Netlogix\Nxcachetags\Service\CacheTagService; | ||
use Nimut\TestingFramework\TestCase\FunctionalTestCase; | ||
use TYPO3\CMS\Core\Cache\CacheManager; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; | ||
use TYPO3\CMS\Extbase\Domain\Model\Category; | ||
use TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository; | ||
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; | ||
|
||
class EntityAddedToPersistenceTest extends FunctionalTestCase | ||
{ | ||
protected $testExtensionsToLoad = ['typo3conf/ext/nxcachetags']; | ||
|
||
/** | ||
* @test | ||
* @return void | ||
*/ | ||
public function itCallsEventAfterAddingObjectToPersistence() { | ||
$mockCacheTagService = $this->getMockBuilder(CacheTagService::class) | ||
->onlyMethods(['flushCachesByTag']) | ||
->getMock(); | ||
$mockCacheTagService->injectCacheManager(GeneralUtility::makeInstance(CacheManager::class)); | ||
$mockCacheTagService->injectConfigurationManager(GeneralUtility::makeInstance(ConfigurationManager::class)); | ||
$mockCacheTagService->initializeObject(); | ||
$mockCacheTagService->expects(self::atLeastOnce())->method('flushCachesByTag'); | ||
|
||
|
||
GeneralUtility::setSingletonInstance(CacheTagService::class, $mockCacheTagService); | ||
|
||
|
||
$object = new Category(); | ||
$object->setTitle(uniqid('title_')); | ||
|
||
$repo = GeneralUtility::makeInstance(CategoryRepository::class); | ||
$repo->add($object); | ||
GeneralUtility::makeInstance(PersistenceManager::class)->persistAll(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
Tests/Functional/EventListener/EntityRemovedFromPersistenceTest.php
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Netlogix\Nxcachetags\Tests\Functional\EventListener; | ||
|
||
use Netlogix\Nxcachetags\Service\CacheTagService; | ||
use Nimut\TestingFramework\TestCase\FunctionalTestCase; | ||
use TYPO3\CMS\Core\Cache\CacheManager; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; | ||
use TYPO3\CMS\Extbase\Domain\Model\Category; | ||
use TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository; | ||
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; | ||
|
||
class EntityRemovedFromPersistenceTest extends FunctionalTestCase | ||
{ | ||
protected $testExtensionsToLoad = ['typo3conf/ext/nxcachetags']; | ||
|
||
/** | ||
* @test | ||
* @return void | ||
*/ | ||
public function itCallsEventAfterAddingObjectToPersistence() | ||
{ | ||
$mockCacheTagService = $this->getMockBuilder(CacheTagService::class) | ||
->onlyMethods(['flushCachesByTag']) | ||
->getMock(); | ||
$mockCacheTagService->injectCacheManager(GeneralUtility::makeInstance(CacheManager::class)); | ||
$mockCacheTagService->injectConfigurationManager(GeneralUtility::makeInstance(ConfigurationManager::class)); | ||
$mockCacheTagService->initializeObject(); | ||
$mockCacheTagService->expects(self::atLeastOnce())->method('flushCachesByTag'); | ||
GeneralUtility::setSingletonInstance(CacheTagService::class, $mockCacheTagService); | ||
|
||
$repo = GeneralUtility::makeInstance(CategoryRepository::class); | ||
|
||
$cat = new Category(); | ||
$cat->setTitle(uniqid('title_')); | ||
$repo->add($cat); | ||
GeneralUtility::makeInstance(PersistenceManager::class)->persistAll(); | ||
|
||
|
||
$cat->setTitle(uniqid('title_')); | ||
$repo->remove($cat); | ||
GeneralUtility::makeInstance(PersistenceManager::class)->persistAll(); | ||
} | ||
} |
Oops, something went wrong.