diff --git a/src/contracts/Persistence/Content/Location/Trashed.php b/src/contracts/Persistence/Content/Location/Trashed.php index 7d676b92db..1da85310cc 100644 --- a/src/contracts/Persistence/Content/Location/Trashed.php +++ b/src/contracts/Persistence/Content/Location/Trashed.php @@ -19,6 +19,9 @@ class Trashed extends Location * @var mixed Trashed timestamp. */ public $trashed; + + /** @var array Location ID to a Content ID map of removed items */ + public $removedLocationContentIdMap = []; } class_alias(Trashed::class, 'eZ\Publish\SPI\Persistence\Content\Location\Trashed'); diff --git a/src/lib/Persistence/Legacy/Content/Location/Trash/Handler.php b/src/lib/Persistence/Legacy/Content/Location/Trash/Handler.php index 739e808043..2070200667 100644 --- a/src/lib/Persistence/Legacy/Content/Location/Trash/Handler.php +++ b/src/lib/Persistence/Legacy/Content/Location/Trash/Handler.php @@ -99,6 +99,7 @@ public function trashSubtree($locationId) $locationRows = $this->locationGateway->getSubtreeContent($locationId); $isLocationRemoved = false; $parentLocationId = null; + $removedLocationsContentMap = []; foreach ($locationRows as $locationRow) { if ($locationRow['node_id'] == $locationId) { @@ -107,6 +108,7 @@ public function trashSubtree($locationId) if ($this->locationGateway->countLocationsByContentId($locationRow['contentobject_id']) == 1) { $this->locationGateway->trashLocation($locationRow['node_id']); + $removedLocationsContentMap[(int)$locationRow['node_id']] = (int)$locationRow['contentobject_id']; } else { if ($locationRow['node_id'] == $locationId) { $isLocationRemoved = true; @@ -133,7 +135,14 @@ public function trashSubtree($locationId) $this->locationHandler->markSubtreeModified($parentLocationId, time()); } - return $isLocationRemoved ? null : $this->loadTrashItem($locationId); + if ($isLocationRemoved === true) { + return null; + } + + $trashItem = $this->loadTrashItem($locationId); + $trashItem->removedLocationContentIdMap = $removedLocationsContentMap; + + return $trashItem; } /** diff --git a/src/lib/Repository/TrashService.php b/src/lib/Repository/TrashService.php index 15f5340d6f..7f2f64e753 100644 --- a/src/lib/Repository/TrashService.php +++ b/src/lib/Repository/TrashService.php @@ -376,7 +376,10 @@ protected function buildDomainTrashItemObject(Trashed $spiTrashItem, Content $co 'depth' => $spiTrashItem->depth, 'sortField' => $spiTrashItem->sortField, 'sortOrder' => $spiTrashItem->sortOrder, - 'trashed' => isset($spiTrashItem->trashed) ? new DateTime('@' . $spiTrashItem->trashed) : new DateTime('@0'), + 'trashed' => isset($spiTrashItem->trashed) + ? new DateTime('@' . $spiTrashItem->trashed) + : new DateTime('@0'), + 'removedLocationContentIdMap' => $spiTrashItem->removedLocationContentIdMap, 'parentLocation' => $this->proxyDomainMapper->createLocationProxy($spiTrashItem->parentId), ] ); diff --git a/src/lib/Repository/Values/Content/TrashItem.php b/src/lib/Repository/Values/Content/TrashItem.php index a00610bbb1..904f28c2b2 100644 --- a/src/lib/Repository/Values/Content/TrashItem.php +++ b/src/lib/Repository/Values/Content/TrashItem.php @@ -32,6 +32,9 @@ class TrashItem extends APITrashItem /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location */ protected $parentLocation; + /** @var array */ + protected $removedLocationContentIdMap = []; + /** * Returns the content info of the content object of this trash item. * @@ -47,6 +50,14 @@ public function getParentLocation(): ?Location return $this->parentLocation; } + /** + * @return array + */ + public function getRemovedLocationContentIdMap(): array + { + return $this->removedLocationContentIdMap; + } + /** * Function where list of properties are returned. * diff --git a/tests/integration/Core/Repository/TrashServiceTest.php b/tests/integration/Core/Repository/TrashServiceTest.php index 9a4ff8abf8..ffb2bc5446 100644 --- a/tests/integration/Core/Repository/TrashServiceTest.php +++ b/tests/integration/Core/Repository/TrashServiceTest.php @@ -245,11 +245,6 @@ public function testLoadTrashItem() $trashItemReloaded->pathString ); - $this->assertEquals( - $trashItem, - $trashItemReloaded - ); - $this->assertInstanceOf( DateTime::class, $trashItemReloaded->trashed @@ -1015,6 +1010,31 @@ public function testDeleteThrowsNotFoundExceptionForNonExistingTrashItem() )); } + public function testTrashProperlyAssignsRemovedLocationContentMapToTrashItem(): void + { + $repository = $this->getRepository(); + $trashService = $repository->getTrashService(); + $locationService = $repository->getLocationService(); + + $folder1 = $this->createFolder(['eng-GB' => 'Folder1'], 2); + $folder2 = $this->createFolder(['eng-GB' => 'Folder2'], $folder1->contentInfo->getMainLocationId()); + $folder3 = $this->createFolder(['eng-GB' => 'Folder2'], $folder2->contentInfo->getMainLocationId()); + + $folderLocation = $locationService->loadLocation($folder1->contentInfo->getMainLocationId()); + + $trashItem = $trashService->trash($folderLocation); + $removedLocationContentMap = $trashItem->getRemovedLocationContentIdMap(); + + self::assertSame( + [ + $folderLocation->id => $folder1->id, + $folder2->contentInfo->getMainLocationId() => $folder2->id, + $folder3->contentInfo->getMainLocationId() => $folder3->id, + ], + $removedLocationContentMap, + ); + } + /** * @return array */