Skip to content

Commit

Permalink
Merge branch '4.5' into main
Browse files Browse the repository at this point in the history
# Conflicts:
#	phpstan-baseline.neon
  • Loading branch information
barw4 committed Oct 20, 2023
2 parents 09972d4 + f836872 commit 2c1d41d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
7 changes: 6 additions & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -38820,6 +38820,11 @@ parameters:
count: 4
path: tests/integration/Core/Repository/TrashServiceTest.php

-
message: "#^Cannot call method getRemovedLocationContentIdMap\\(\\) on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\TrashItem\\|null\\.$#"
count: 1
path: tests/integration/Core/Repository/TrashServiceTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Integration\\\\Core\\\\Repository\\\\TrashServiceTest\\:\\:assertAliasNotExists\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -38972,7 +38977,7 @@ parameters:

-
message: "#^Parameter \\#1 \\$locationId of method Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\LocationService\\:\\:loadLocation\\(\\) expects int, int\\|null given\\.$#"
count: 5
count: 6
path: tests/integration/Core/Repository/TrashServiceTest.php

-
Expand Down
3 changes: 3 additions & 0 deletions src/contracts/Persistence/Content/Location/Trashed.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ 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 array $removedLocationContentIdMap = [];
}

class_alias(Trashed::class, 'eZ\Publish\SPI\Persistence\Content\Location\Trashed');
11 changes: 10 additions & 1 deletion src/lib/Persistence/Legacy/Content/Location/Trash/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/lib/Repository/TrashService.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,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
11 changes: 11 additions & 0 deletions src/lib/Repository/Values/Content/TrashItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class TrashItem extends APITrashItem
/** @var \Ibexa\Contracts\Core\Repository\Values\Content\Location */
protected $parentLocation;

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

/**
* Returns the content info of the content object of this trash item.
*
Expand All @@ -47,6 +50,14 @@ public function getParentLocation(): ?Location
return $this->parentLocation;
}

/**
* @return array<int, int>
*/
public function getRemovedLocationContentIdMap(): array
{
return $this->removedLocationContentIdMap;
}

/**
* Function where list of properties are returned.
*
Expand Down
30 changes: 25 additions & 5 deletions tests/integration/Core/Repository/TrashServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,6 @@ public function testLoadTrashItem()
$trashItemReloaded->pathString
);

$this->assertEquals(
$trashItem,
$trashItemReloaded
);

$this->assertInstanceOf(
DateTime::class,
$trashItemReloaded->trashed
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit 2c1d41d

Please sign in to comment.