Skip to content

Commit

Permalink
Merge branch '1.3' of ezsystems/ezplatform-kernel into 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Oct 20, 2023
2 parents 11e30fe + 336f0a6 commit 7bb75b1
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 20 deletions.
21 changes: 8 additions & 13 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15157,12 +15157,12 @@ parameters:

-
message: "#^Cannot access offset int\\|string on Ibexa\\\\Contracts\\\\Core\\\\Persistence\\\\Content\\\\Field\\.$#"
count: 3
count: 1
path: src/lib/Persistence/Legacy/Content/FieldHandler.php

-
message: "#^Cannot access offset string on Ibexa\\\\Contracts\\\\Core\\\\Persistence\\\\Content\\\\Field\\.$#"
count: 4
count: 2
path: src/lib/Persistence/Legacy/Content/FieldHandler.php

-
Expand Down Expand Up @@ -20515,11 +20515,6 @@ parameters:
count: 1
path: src/lib/Repository/Mapper/ContentDomainMapper.php

-
message: "#^Cannot access offset mixed on iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Persistence\\\\Content\\>\\.$#"
count: 1
path: src/lib/Repository/Mapper/ContentDomainMapper.php

-
message: "#^Cannot call method error\\(\\) on Psr\\\\Log\\\\LoggerInterface\\|null\\.$#"
count: 1
Expand Down Expand Up @@ -38905,6 +38900,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 @@ -39057,7 +39057,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 Expand Up @@ -58435,11 +58435,6 @@ parameters:
count: 1
path: tests/lib/Repository/Service/Mock/ContentTest.php

-
message: "#^Cannot access offset mixed on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\.$#"
count: 1
path: tests/lib/Repository/Service/Mock/ContentTest.php

-
message: "#^Cannot access offset string on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Field\\.$#"
count: 1
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 $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 @@ -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),
]
);
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 $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 7bb75b1

Please sign in to comment.