Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
14 changes: 14 additions & 0 deletions src/contracts/Persistence/Content/DeleteContentHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace Ibexa\Contracts\Core\Persistence\Content;

interface DeleteContentHandler
{
public function preDeleteContent(ContentInfo $contentInfo, ?int $mainLocationId): void;

public function postDeleteContent(ContentInfo $contentInfo, ?int $mainLocationId): void;
}
19 changes: 17 additions & 2 deletions src/lib/Persistence/Legacy/Content/TreeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,31 @@ 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
* @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;
}

/**
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/Persistence/Legacy/Content/TreeHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ protected function getPartlyMockedTreeHandler(array $methods)
$this->getContentGatewayMock(),
$this->getContentMapperMock(),
$this->getFieldHandlerMock(),
[],
]
)
->getMock();
Expand All @@ -571,7 +572,8 @@ protected function getTreeHandler()
$this->getLocationMapperMock(),
$this->getContentGatewayMock(),
$this->getContentMapperMock(),
$this->getFieldHandlerMock()
$this->getFieldHandlerMock(),
[],
);
}
}
Expand Down
Loading