From d4ab46bb45aadcb2f4389fdba1cdf4ad8f0bf4ad Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Mon, 31 Mar 2025 12:19:10 +0200 Subject: [PATCH 1/7] IBX-8054 Add extension point for doing cleanup during deleteoperation --- .../Persistence/Legacy/Content/TreeHandler.php | 18 ++++++++++++++++-- .../storage_engines/legacy/content.yml | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib/Persistence/Legacy/Content/TreeHandler.php b/src/lib/Persistence/Legacy/Content/TreeHandler.php index 629326589b..61d7f9e9ab 100644 --- a/src/lib/Persistence/Legacy/Content/TreeHandler.php +++ b/src/lib/Persistence/Legacy/Content/TreeHandler.php @@ -53,6 +53,9 @@ class TreeHandler */ protected $fieldHandler; + /** @var iterable<\Ibexa\Contracts\Core\Persistence\Content\DeleteContentHandler> */ + private iterable $deleteContentHandlers; + /** * @param \Ibexa\Core\Persistence\Legacy\Content\Location\Gateway $locationGateway * @param \Ibexa\Core\Persistence\Legacy\Content\Location\Mapper $locationMapper @@ -65,13 +68,15 @@ public function __construct( 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 +104,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 +125,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 From 5260aea9bc03139a0531c47d094c2701a002c8da Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Mon, 31 Mar 2025 12:50:54 +0200 Subject: [PATCH 2/7] fixup! IBX-8054 Add extension point for doing cleanup during deleteoperation --- .../Persistence/Content/DeleteContentHandler.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/contracts/Persistence/Content/DeleteContentHandler.php diff --git a/src/contracts/Persistence/Content/DeleteContentHandler.php b/src/contracts/Persistence/Content/DeleteContentHandler.php new file mode 100644 index 0000000000..b5e48ab146 --- /dev/null +++ b/src/contracts/Persistence/Content/DeleteContentHandler.php @@ -0,0 +1,14 @@ + Date: Mon, 31 Mar 2025 12:58:33 +0200 Subject: [PATCH 3/7] fixup! IBX-8054 Add extension point for doing cleanup during deleteoperation --- tests/lib/Persistence/Legacy/Content/TreeHandlerTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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(), + [], ); } } From 886a8f14b8de6f8c9243be941ee61d5f58102bd4 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Mon, 31 Mar 2025 13:20:12 +0200 Subject: [PATCH 4/7] fixup! IBX-8054 Add extension point for doing cleanup during deleteoperation --- src/contracts/Persistence/Content/DeleteContentHandler.php | 4 ++-- src/lib/Persistence/Legacy/Content/TreeHandler.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/contracts/Persistence/Content/DeleteContentHandler.php b/src/contracts/Persistence/Content/DeleteContentHandler.php index b5e48ab146..6376f11ac2 100644 --- a/src/contracts/Persistence/Content/DeleteContentHandler.php +++ b/src/contracts/Persistence/Content/DeleteContentHandler.php @@ -8,7 +8,7 @@ interface DeleteContentHandler { - public function preDeleteContent(ContentInfo $contentInfo, ?int $mainLocationId); + public function preDeleteContent(ContentInfo $contentInfo, ?int $mainLocationId): void; - public function postDeleteContent(ContentInfo $contentInfo, ?int $mainLocationId); + public function postDeleteContent(ContentInfo $contentInfo, ?int $mainLocationId): void; } diff --git a/src/lib/Persistence/Legacy/Content/TreeHandler.php b/src/lib/Persistence/Legacy/Content/TreeHandler.php index 61d7f9e9ab..08e3123cb8 100644 --- a/src/lib/Persistence/Legacy/Content/TreeHandler.php +++ b/src/lib/Persistence/Legacy/Content/TreeHandler.php @@ -62,6 +62,7 @@ class TreeHandler * @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, From 41dddf9202fc95baa77e5fe8c0be1cb63335515f Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Wed, 23 Apr 2025 13:53:19 +0200 Subject: [PATCH 5/7] Added temporary branch alias --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4a742f0dfd..6d30e9238d 100644 --- a/composer.json +++ b/composer.json @@ -158,7 +158,8 @@ }, "extra": { "branch-alias": { - "dev-main": "4.6.x-dev" + "dev-main": "4.6.x-dev", + "dev-IBX-8054_add_extension_point_for_doing_cleanup_during_delete_operation": "4.6.x-dev" } } } From 87b05599834be2114445595f9123fc30fe6eb137 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Thu, 24 Apr 2025 08:36:10 +0200 Subject: [PATCH 6/7] Revert "Added temporary branch alias" This reverts commit 41dddf9202fc95baa77e5fe8c0be1cb63335515f. --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 6d30e9238d..4a742f0dfd 100644 --- a/composer.json +++ b/composer.json @@ -158,8 +158,7 @@ }, "extra": { "branch-alias": { - "dev-main": "4.6.x-dev", - "dev-IBX-8054_add_extension_point_for_doing_cleanup_during_delete_operation": "4.6.x-dev" + "dev-main": "4.6.x-dev" } } } From 790d1c6ab3ea996ab906c525d65c9ae06f9eefa9 Mon Sep 17 00:00:00 2001 From: Vidar Langseid Date: Thu, 24 Apr 2025 08:38:13 +0200 Subject: [PATCH 7/7] Update src/lib/Persistence/Legacy/Content/TreeHandler.php Co-authored-by: Andrew Longosz --- src/lib/Persistence/Legacy/Content/TreeHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Persistence/Legacy/Content/TreeHandler.php b/src/lib/Persistence/Legacy/Content/TreeHandler.php index 08e3123cb8..780b8ee4f3 100644 --- a/src/lib/Persistence/Legacy/Content/TreeHandler.php +++ b/src/lib/Persistence/Legacy/Content/TreeHandler.php @@ -70,7 +70,7 @@ public function __construct( ContentGateway $contentGateway, ContentMapper $contentMapper, FieldHandler $fieldHandler, - iterable $deleteContentHandlers, + iterable $deleteContentHandlers ) { $this->locationGateway = $locationGateway; $this->locationMapper = $locationMapper;