Skip to content

Commit

Permalink
IBX-6631: Simplified the solution
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Oct 12, 2023
1 parent dfc6389 commit 94b7703
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
8 changes: 5 additions & 3 deletions eZ/Publish/Core/Persistence/Cache/TrashHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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 @@ -20,11 +19,14 @@ class TrashHandler extends AbstractHandler implements TrashHandlerInterface
private const CONTENT_IDENTIFIER = 'content';
private const LOCATION_PATH_IDENTIFIER = 'location_path';

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

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

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

public function loadTrashItem(int $id, array $trashedLocationsContentMap = []): Trashed
/**
* 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)
{
$data = $this->locationGateway->loadTrashByLocation($id);

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

/**
Expand Down Expand Up @@ -139,7 +145,14 @@ public function trashSubtree($locationId)
$this->locationHandler->markSubtreeModified($parentLocationId, time());
}

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

$trashItem = $this->loadTrashItem($locationId);
$trashItem->removedLocationContentIdMap = $trashedLocationsContentMap;

return $trashItem;
}

/**
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,8 +7,6 @@
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 @@ -19,11 +17,13 @@ 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 array<int, int> $trashedLocationsContentMap
* @param int $id
*
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*
* @return \eZ\Publish\SPI\Persistence\Content\Location\Trashed
*/
public function loadTrashItem(int $id, array $trashedLocationsContentMap = []): Trashed;
public function loadTrashItem($id);

/**
* Sends a subtree starting to $locationId to the trash
Expand Down

0 comments on commit 94b7703

Please sign in to comment.