Skip to content

Commit

Permalink
IBX-6631: Enriched TrashItem with removedLocationContentIdMap
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Oct 11, 2023
1 parent 83cc49f commit dfc6389
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 24 deletions.
11 changes: 11 additions & 0 deletions eZ/Publish/API/Repository/Values/Content/TrashItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@ abstract class TrashItem extends Location
* @var \DateTime
*/
protected $trashed;

/** @var array<int, int> */
protected $removedLocationContentIdMap = [];

/**
* @return array<int, int>
*/
public function getRemovedLocationContentIdMap(): array
{
return $this->removedLocationContentIdMap;
}
}
8 changes: 3 additions & 5 deletions eZ/Publish/Core/Persistence/Cache/TrashHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace eZ\Publish\Core\Persistence\Cache;

use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\SPI\Persistence\Content\Location;
use eZ\Publish\SPI\Persistence\Content\Location\Trash\Handler as TrashHandlerInterface;
use eZ\Publish\SPI\Persistence\Content\Relation;

Expand All @@ -19,14 +20,11 @@ class TrashHandler extends AbstractHandler implements TrashHandlerInterface
private const CONTENT_IDENTIFIER = 'content';
private const LOCATION_PATH_IDENTIFIER = 'location_path';

/**
* {@inheritdoc}
*/
public function loadTrashItem($id)
public function loadTrashItem(int $id, array $trashedLocationsContentMap = []): Location\Trashed
{
$this->logger->logCall(__METHOD__, ['id' => $id]);

return $this->persistenceHandler->trashHandler()->loadTrashItem($id);
return $this->persistenceHandler->trashHandler()->loadTrashItem($id, $trashedLocationsContentMap);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Mapper
* @param string $prefix
* @param \eZ\Publish\SPI\Persistence\Content\Location|null $location
*
* @return \eZ\Publish\SPI\Persistence\Content\Location
* @return \eZ\Publish\SPI\Persistence\Content\Location|\eZ\Publish\SPI\Persistence\Content\Location\Trashed
*/
public function createLocationFromRow(array $data, $prefix = '', ?Location $location = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,15 @@ public function __construct(
$this->contentHandler = $contentHandler;
}

/**
* Loads the data for the trashed location identified by $id.
* $id is the same as original location (which has been previously trashed).
*
* @param int $id
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*
* @return \eZ\Publish\SPI\Persistence\Content\Location\Trashed
*/
public function loadTrashItem($id)
public function loadTrashItem(int $id, array $trashedLocationsContentMap = []): Trashed
{
$data = $this->locationGateway->loadTrashByLocation($id);

return $this->locationMapper->createLocationFromRow($data, null, new Trashed());
return $this->locationMapper->createLocationFromRow(
$data,
null,
new Trashed(['removedLocationContentIdMap' => $trashedLocationsContentMap]),
);
}

/**
Expand All @@ -109,6 +103,7 @@ public function trashSubtree($locationId)
$locationRows = $this->locationGateway->getSubtreeContent($locationId);
$isLocationRemoved = false;
$parentLocationId = null;
$trashedLocationsContentMap = [];

foreach ($locationRows as $locationRow) {
if ($locationRow['node_id'] == $locationId) {
Expand All @@ -117,6 +112,7 @@ public function trashSubtree($locationId)

if ($this->locationGateway->countLocationsByContentId($locationRow['contentobject_id']) == 1) {
$this->locationGateway->trashLocation($locationRow['node_id']);
$trashedLocationsContentMap[$locationRow['node_id']] = $locationRow['contentobject_id'];
} else {
if ($locationRow['node_id'] == $locationId) {
$isLocationRemoved = true;
Expand All @@ -143,7 +139,7 @@ public function trashSubtree($locationId)
$this->locationHandler->markSubtreeModified($parentLocationId, time());
}

return $isLocationRemoved ? null : $this->loadTrashItem($locationId);
return $isLocationRemoved ? null : $this->loadTrashItem($locationId, $trashedLocationsContentMap);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion eZ/Publish/Core/Repository/TrashService.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,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),
]
);
Expand Down
8 changes: 4 additions & 4 deletions eZ/Publish/SPI/Persistence/Content/Location/Trash/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
namespace eZ\Publish\SPI\Persistence\Content\Location\Trash;

use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
use eZ\Publish\SPI\Persistence\Content\Location;
use eZ\Publish\SPI\Persistence\Content\Location\Trashed;

/**
* The Trash Handler interface defines operations on Location elements in the storage engine.
Expand All @@ -17,13 +19,11 @@ interface Handler
* Loads the data for the trashed location identified by $id.
* $id is the same as original location (which has been previously trashed).
*
* @param int $id
* @param array<int, int> $trashedLocationsContentMap
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*
* @return \eZ\Publish\SPI\Persistence\Content\Location\Trashed
*/
public function loadTrashItem($id);
public function loadTrashItem(int $id, array $trashedLocationsContentMap = []): Trashed;

/**
* Sends a subtree starting to $locationId to the trash
Expand Down
3 changes: 3 additions & 0 deletions eZ/Publish/SPI/Persistence/Content/Location/Trashed.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ class Trashed extends Location
* @var mixed Trashed timestamp.
*/
public $trashed;

/** @var array<int, int> Location ID to a Content ID map of removed items */
public $removedLocationContentIdMap = [];
}

0 comments on commit dfc6389

Please sign in to comment.