diff --git a/src/contracts/Persistence/Content/DeleteContentHandler.php b/src/contracts/Persistence/Content/DeleteContentHandler.php new file mode 100644 index 0000000000..6376f11ac2 --- /dev/null +++ b/src/contracts/Persistence/Content/DeleteContentHandler.php @@ -0,0 +1,14 @@ + */ + private iterable $deleteContentHandlers; + /** * @param \Ibexa\Core\Persistence\Legacy\Content\Location\Gateway $locationGateway * @param \Ibexa\Core\Persistence\Legacy\Content\Location\Mapper $locationMapper * @param \Ibexa\Core\Persistence\Legacy\Content\Gateway $contentGateway * @param \Ibexa\Core\Persistence\Legacy\Content\Mapper $contentMapper * @param \Ibexa\Core\Persistence\Legacy\Content\FieldHandler $fieldHandler + * @param iterable<\Ibexa\Contracts\Core\Persistence\Content\DeleteContentHandler> $deleteContentHandlers */ public function __construct( LocationGateway $locationGateway, LocationMapper $locationMapper, ContentGateway $contentGateway, ContentMapper $contentMapper, - FieldHandler $fieldHandler + FieldHandler $fieldHandler, + iterable $deleteContentHandlers ) { $this->locationGateway = $locationGateway; $this->locationMapper = $locationMapper; $this->contentGateway = $contentGateway; $this->contentMapper = $contentMapper; $this->fieldHandler = $fieldHandler; + $this->deleteContentHandlers = $deleteContentHandlers; } /** @@ -99,7 +105,13 @@ public function loadContentInfo($contentId) */ public function removeRawContent($contentId) { - $mainLocationId = $this->loadContentInfo($contentId)->mainLocationId; + $contentInfo = $this->loadContentInfo($contentId); + $mainLocationId = $contentInfo->mainLocationId; + + foreach ($this->deleteContentHandlers as $handler) { + $handler->preDeleteContent($contentInfo, $mainLocationId); + } + // there can be no Locations for Draft Content items if (null !== $mainLocationId) { $this->locationGateway->removeElementFromTrash($mainLocationId); @@ -114,6 +126,9 @@ public function removeRawContent($contentId) $this->contentGateway->deleteVersions($contentId); $this->contentGateway->deleteNames($contentId); $this->contentGateway->deleteContent($contentId); + foreach ($this->deleteContentHandlers as $handler) { + $handler->postDeleteContent($contentInfo, $mainLocationId); + } } /** diff --git a/src/lib/Resources/settings/storage_engines/legacy/content.yml b/src/lib/Resources/settings/storage_engines/legacy/content.yml index fa9b13d1df..9115540861 100644 --- a/src/lib/Resources/settings/storage_engines/legacy/content.yml +++ b/src/lib/Resources/settings/storage_engines/legacy/content.yml @@ -56,6 +56,7 @@ services: - '@ibexa.persistence.legacy.content.gateway' - '@Ibexa\Core\Persistence\Legacy\Content\Mapper' - '@Ibexa\Core\Persistence\Legacy\Content\FieldHandler' + - !tagged_iterator 'ibexa.core.delete.content.handler' Ibexa\Core\Persistence\Legacy\Content\Handler: class: Ibexa\Core\Persistence\Legacy\Content\Handler diff --git a/tests/lib/Persistence/Legacy/Content/TreeHandlerTest.php b/tests/lib/Persistence/Legacy/Content/TreeHandlerTest.php index 9daf814d36..1c5babe207 100644 --- a/tests/lib/Persistence/Legacy/Content/TreeHandlerTest.php +++ b/tests/lib/Persistence/Legacy/Content/TreeHandlerTest.php @@ -556,6 +556,7 @@ protected function getPartlyMockedTreeHandler(array $methods) $this->getContentGatewayMock(), $this->getContentMapperMock(), $this->getFieldHandlerMock(), + [], ] ) ->getMock(); @@ -571,7 +572,8 @@ protected function getTreeHandler() $this->getLocationMapperMock(), $this->getContentGatewayMock(), $this->getContentMapperMock(), - $this->getFieldHandlerMock() + $this->getFieldHandlerMock(), + [], ); } }