Skip to content

Commit aa086db

Browse files
committed
Merged branch '1.3' of ezsystems/ezplatform-kernel into 4.3
2 parents d336bfd + b787ccb commit aa086db

File tree

14 files changed

+101
-2
lines changed

14 files changed

+101
-2
lines changed

src/contracts/Persistence/Content/Location/Handler.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ public function loadParentLocationsForDraftContent($contentId);
110110
*/
111111
public function copySubtree($sourceId, $destinationParentId);
112112

113+
public function getSubtreeSize(string $path): int;
114+
113115
/**
114116
* Moves location identified by $sourceId into new parent identified by $destinationParentId.
115117
*

src/contracts/Repository/Decorator/LocationServiceDecorator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public function getLocationChildCount(Location $location): int
8787
return $this->innerService->getLocationChildCount($location);
8888
}
8989

90+
public function getSubtreeSize(Location $location): int
91+
{
92+
return $this->innerService->getSubtreeSize($location);
93+
}
94+
9095
public function createLocation(
9196
ContentInfo $contentInfo,
9297
LocationCreateStruct $locationCreateStruct

src/contracts/Repository/LocationService.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ public function loadParentLocationsForDraftContent(VersionInfo $versionInfo, ?ar
125125
*/
126126
public function getLocationChildCount(Location $location): int;
127127

128+
/**
129+
* Return the subtree size of a given location.
130+
*
131+
* Warning! This method is not permission aware by design.
132+
*/
133+
public function getSubtreeSize(Location $location): int;
134+
128135
/**
129136
* Creates the new $location in the content repository for the given content.
130137
*

src/contracts/Repository/Values/Content/Location.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @property-read bool $explicitlyHidden Indicates that the Location entity has been explicitly marked as hidden.
2525
* @property-read string $remoteId a global unique id of the content object
2626
* @property-read int $parentLocationId the id of the parent location
27-
* @property-read string $pathString the path to this location e.g. /1/2/4/23 where 23 is current id.
27+
* @property-read string $pathString @deprecated use {@see Location::getPathString()} instead.
2828
* @property-read array $path Same as $pathString but as array, e.g. [ 1, 2, 4, 23 ]
2929
* @property-read int $depth Depth location has in the location tree
3030
* @property-read int $sortField Specifies which property the child locations should be sorted on. Valid values are found at {@link Location::SORT_FIELD_*}
@@ -239,6 +239,15 @@ public function getSortClauses(): array
239239

240240
return [$sortClause];
241241
}
242+
243+
/**
244+
* The path to the Location represented by the current instance,
245+
* e.g. /1/2/4/23 where 23 is current id.
246+
*/
247+
public function getPathString(): string
248+
{
249+
return $this->pathString;
250+
}
242251
}
243252

244253
class_alias(Location::class, 'eZ\Publish\API\Repository\Values\Content\Location');

src/contracts/Repository/Values/ContentType/ContentType.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* @property-read string $remoteId a global unique id of the content object
2828
* @property-read string $urlAliasSchema URL alias schema. If nothing is provided, $nameSchema will be used instead.
2929
* @property-read string $nameSchema The name schema.
30-
* @property-read bool $isContainer This flag hints to UIs if type may have children or not.
30+
* @property-read bool $isContainer @deprecated use strict getter {@see ContentType::isContainer} instead.
3131
* @property-read string $mainLanguageCode the main language of the content type names and description used for fallback.
3232
* @property-read bool $defaultAlwaysAvailable if an instance of a content type is created the always available flag is set by default this this value.
3333
* @property-read string[] $languageCodes array of language codes used by content type translations.
@@ -228,6 +228,11 @@ public function getFirstFieldDefinitionOfType(string $fieldTypeIdentifier): ?Fie
228228

229229
return null;
230230
}
231+
232+
public function isContainer(): bool
233+
{
234+
return $this->isContainer;
235+
}
231236
}
232237

233238
class_alias(ContentType::class, 'eZ\Publish\API\Repository\Values\ContentType\ContentType');

src/lib/Persistence/Cache/LocationHandler.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,15 @@ public function copySubtree($sourceId, $destinationParentId, $newOwnerId = null)
256256
return $this->persistenceHandler->locationHandler()->copySubtree($sourceId, $destinationParentId, $newOwnerId);
257257
}
258258

259+
public function getSubtreeSize(string $path): int
260+
{
261+
$this->logger->logCall(__METHOD__, [
262+
'path' => $path,
263+
]);
264+
265+
return $this->persistenceHandler->locationHandler()->getSubtreeSize($path);
266+
}
267+
259268
/**
260269
* {@inheritdoc}
261270
*/

src/lib/Persistence/Legacy/Content/Location/Gateway.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ abstract public function loadParentLocationsDataForDraftContent(int $contentId):
111111
*/
112112
abstract public function getSubtreeContent(int $sourceId, bool $onlyIds = false): array;
113113

114+
abstract public function getSubtreeSize(string $path): int;
115+
114116
/**
115117
* Returns data for the first level children of the location identified by given $locationId.
116118
*/

src/lib/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,21 @@ public function getSubtreeContent(int $sourceId, bool $onlyIds = false): array
237237
: $results;
238238
}
239239

240+
public function getSubtreeSize(string $path): int
241+
{
242+
$query = $this->createNodeQueryBuilder([$this->dbPlatform->getCountExpression('node_id')]);
243+
$query->andWhere(
244+
$query->expr()->like(
245+
't.path_string',
246+
$query->createPositionalParameter(
247+
$path . '%',
248+
)
249+
)
250+
);
251+
252+
return (int) $query->execute()->fetchOne();
253+
}
254+
240255
/**
241256
* Return constraint which limits the given $query to the subtree starting at $rootLocationId.
242257
*/

src/lib/Persistence/Legacy/Content/Location/Gateway/ExceptionConversion.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ public function getSubtreeContent(int $sourceId, bool $onlyIds = false): array
106106
}
107107
}
108108

109+
public function getSubtreeSize(string $path): int
110+
{
111+
try {
112+
return $this->innerGateway->getSubtreeSize($path);
113+
} catch (DBALException | PDOException $e) {
114+
throw DatabaseException::wrap($e);
115+
}
116+
}
117+
109118
public function getChildren(int $locationId): array
110119
{
111120
try {

src/lib/Persistence/Legacy/Content/Location/Handler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ public function copySubtree($sourceId, $destinationParentId, $newOwnerId = null)
332332
return $copiedSubtreeRootLocation;
333333
}
334334

335+
public function getSubtreeSize(string $path): int
336+
{
337+
return $this->locationGateway->getSubtreeSize($path);
338+
}
339+
335340
/**
336341
* Retrieves section ID of the location's content.
337342
*

0 commit comments

Comments
 (0)