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 Aug 1, 2023
2 parents 8804d46 + 002ffa4 commit e29ab00
Show file tree
Hide file tree
Showing 18 changed files with 388 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/contracts/Persistence/Content/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ public function deleteTranslationFromContent($contentId, $languageCode);
* @return \Ibexa\Contracts\Core\Persistence\Content The Content Draft w/o removed Translation
*/
public function deleteTranslationFromDraft($contentId, $versionNo, $languageCode);

/**
* @param array<int> $contentIds
*
* @return array<\Ibexa\Contracts\Core\Persistence\Content\VersionInfo>
*
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentException
* @throws \Ibexa\Core\Base\Exceptions\NotFoundException
*/
public function loadVersionInfoList(array $contentIds): array;
}

class_alias(Handler::class, 'eZ\Publish\SPI\Persistence\Content\Handler');
13 changes: 13 additions & 0 deletions src/contracts/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ public function loadVersionInfo(ContentInfo $contentInfo, ?int $versionNo = null
*/
public function loadVersionInfoById(int $contentId, ?int $versionNo = null): VersionInfo;

/**
* Bulk-load VersionInfo items by the list of ContentInfo Value Objects.
*
* @param array<\Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo> $contentInfoList
*
* @return array<int, \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo> List of VersionInfo items with Content Ids as keys
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*/
public function loadVersionInfoListByContentInfo(array $contentInfoList): array;

/**
* Loads content in a version for the given content info object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public function loadVersionInfoById(
return $this->innerService->loadVersionInfoById($contentId, $versionNo);
}

public function loadVersionInfoListByContentInfo(array $contentInfoList): array
{
return $this->innerService->loadVersionInfoListByContentInfo($contentInfoList);
}

public function loadContentByContentInfo(
ContentInfo $contentInfo,
array $languages = null,
Expand Down
1 change: 1 addition & 0 deletions src/contracts/Test/IbexaTestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->load(static function (ContainerBuilder $container): void {
$container->setParameter('ibexa.core.test.resource_dir', self::getResourcesPath());
$container->setParameter('ezpublish.kernel.root_dir', dirname(__DIR__, 3));
});

$this->loadConfiguration($loader);
Expand Down
13 changes: 5 additions & 8 deletions src/lib/Helper/TranslationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,12 @@ public function getTranslatedContentName(Content $content, $forcedLanguage = nul

/**
* Returns content name, translated, from a VersionInfo object.
* By default this method uses prioritized languages, unless $forcedLanguage is provided.
*
* @param \Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo $versionInfo
* @param string $forcedLanguage
*
* @return string
* By default, this method uses prioritized languages, unless $forcedLanguage is provided.
*/
private function getTranslatedContentNameByVersionInfo(VersionInfo $versionInfo, $forcedLanguage = null)
{
public function getTranslatedContentNameByVersionInfo(
VersionInfo $versionInfo,
?string $forcedLanguage = null
): string {
foreach ($this->getLanguages($forcedLanguage) as $lang) {
$translatedName = $versionInfo->getName($lang);
if ($translatedName !== null) {
Expand Down
29 changes: 29 additions & 0 deletions src/lib/Persistence/Cache/ContentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,35 @@ private function getCacheTagsForVersion(VersionInfo $versionInfo, array $tags =

return $getContentInfoTagsFn($contentInfo, $tags);
}

public function loadVersionInfoList(array $contentIds): array
{
return $this->getMultipleCacheValues(
$contentIds,
$this->cacheIdentifierGenerator->generateKey(
self::CONTENT_VERSION_INFO_IDENTIFIER,
[],
true
) . '-',
function (array $cacheMissIds): array {
return $this->persistenceHandler->contentHandler()->loadVersionInfoList($cacheMissIds);
},
function (VersionInfo $versionInfo): array {
return $this->getCacheTagsForVersion($versionInfo);
},
function (VersionInfo $versionInfo) {
return [
$this->cacheIdentifierGenerator->generateKey(
self::CONTENT_VERSION_INFO_IDENTIFIER,
[$versionInfo->contentInfo->id],
true
),
];
},
'',
['content' => $contentIds]
);
}
}

class_alias(ContentHandler::class, 'eZ\Publish\Core\Persistence\Cache\ContentHandler');
7 changes: 7 additions & 0 deletions src/lib/Persistence/Legacy/Content/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,13 @@ abstract public function deleteTranslationFromVersion(
int $versionNo,
string $languageCode
): void;

/**
* @param array<int> $contentIds
*
* @throws \Ibexa\Core\Base\Exceptions\DatabaseException
*/
abstract public function loadVersionInfoList(array $contentIds): array;
}

class_alias(Gateway::class, 'eZ\Publish\Core\Persistence\Legacy\Content\Gateway');
23 changes: 23 additions & 0 deletions src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,29 @@ private function setLanguageMaskForUpdateQuery(

return $query;
}

/**
* @throws \Doctrine\DBAL\Driver\Exception
* @throws \Doctrine\DBAL\Exception
*/
public function loadVersionInfoList(array $contentIds): array
{
$queryBuilder = $this->queryBuilder->createVersionInfoFindQueryBuilder();
$expr = $queryBuilder->expr();

$queryBuilder
->andWhere(
$expr->in(
'c.id',
$queryBuilder->createNamedParameter($contentIds, Connection::PARAM_INT_ARRAY)
)
)
->andWhere(
$expr->eq('v.version', 'c.current_version')
);

return $queryBuilder->execute()->fetchAllAssociative();
}
}

class_alias(DoctrineDatabase::class, 'eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase');
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,15 @@ public function deleteTranslationFromVersion(
throw DatabaseException::wrap($e);
}
}

public function loadVersionInfoList(array $contentIds): array
{
try {
return $this->innerGateway->loadVersionInfoList($contentIds);
} catch (DBALException | PDOException $e) {
throw DatabaseException::wrap($e);
}
}
}

class_alias(ExceptionConversion::class, 'eZ\Publish\Core\Persistence\Legacy\Content\Gateway\ExceptionConversion');
29 changes: 29 additions & 0 deletions src/lib/Persistence/Legacy/Content/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,35 @@ static function ($lang) use ($languageCode) {
// reload entire Version w/o removed Translation
return $this->load($contentId, $versionNo);
}

/**
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*/
public function loadVersionInfoList(array $contentIds): array
{
$rows = $this->contentGateway->loadVersionInfoList($contentIds);
$mappedRows = array_map(
static function (array $row): array {
return [
'id' => $row['ezcontentobject_id'],
'version' => $row['ezcontentobject_version_version'],
];
},
$rows,
);

$versionInfoList = $this->mapper->extractVersionInfoListFromRows(
$rows,
$this->contentGateway->loadVersionedNameData($mappedRows)
);

$versionInfoListById = [];
foreach ($versionInfoList as $versionInfo) {
$versionInfoListById[$versionInfo->contentInfo->id] = $versionInfo;
}

return $versionInfoListById;
}
}

class_alias(Handler::class, 'eZ\Publish\Core\Persistence\Legacy\Content\Handler');
37 changes: 37 additions & 0 deletions src/lib/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,43 @@ public function loadVersionInfoById(int $contentId, ?int $versionNo = null): API
return $versionInfo;
}

public function loadVersionInfoListByContentInfo(array $contentInfoList): array
{
foreach ($contentInfoList as $idx => $contentInfo) {
if (!$contentInfo instanceof ContentInfo) {
throw new InvalidArgumentException(
'$contentInfoList',
sprintf(
'Element at position %d is not an instance of %s',
$idx,
$contentInfo
)
);
}
}

$contentIds = array_map(
static function (ContentInfo $contentInfo): int {
return $contentInfo->getId();
},
$contentInfoList
);

$persistenceVersionInfos = $this->persistenceHandler
->contentHandler()
->loadVersionInfoList($contentIds);

$versionInfoList = [];
foreach ($persistenceVersionInfos as $persistenceVersionInfo) {
$versionInfo = $this->contentDomainMapper->buildVersionInfoDomainObject($persistenceVersionInfo);
if ($this->permissionResolver->canUser('content', 'read', $versionInfo)) {
$versionInfoList[$versionInfo->getContentInfo()->getId()] = $versionInfo;
}
}

return $versionInfoList;
}

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 5 additions & 0 deletions src/lib/Repository/SiteAccessAware/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public function loadVersionInfoById(int $contentId, ?int $versionNo = null): Ver
return $this->service->loadVersionInfoById($contentId, $versionNo);
}

public function loadVersionInfoListByContentInfo(array $contentInfoList): array
{
return $this->service->loadVersionInfoListByContentInfo($contentInfoList);
}

public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, ?int $versionNo = null, bool $useAlwaysAvailable = true): Content
{
return $this->service->loadContentByContentInfo(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Integration\Core\Repository\ContentService;

use Ibexa\Tests\Integration\Core\RepositoryTestCase;

/**
* @covers \eZ\Publish\API\Repository\ContentService
*/
final class LoadVersionInfoTest extends RepositoryTestCase
{
/**
* @throws \eZ\Publish\API\Repository\Exceptions\Exception
*/
public function testLoadVersionInfoListByContentInfo(): void
{
$contentService = self::getContentService();

$folder1 = $this->createFolder(['eng-GB' => 'Folder1'], 2);
$folder2 = $this->createFolder(['eng-GB' => 'Folder2'], 2);

$versionInfoList = $contentService->loadVersionInfoListByContentInfo(
[
$folder1->getVersionInfo()->getContentInfo(),
$folder2->getVersionInfo()->getContentInfo(),
]
);

self::assertCount(2, $versionInfoList);

foreach ($versionInfoList as $versionInfo) {
$loadedVersionInfo = $contentService->loadVersionInfo(
$versionInfo->getContentInfo(),
$versionInfo->versionNo
);
self::assertEquals($loadedVersionInfo, $versionInfo);
}
}
}
73 changes: 73 additions & 0 deletions tests/integration/Core/RepositoryTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Integration\Core;

use eZ\Publish\API\Repository\Values\Content\Content;
use Ibexa\Contracts\Core\Test\IbexaKernelTestCase;
use InvalidArgumentException;

abstract class RepositoryTestCase extends IbexaKernelTestCase
{
public const CONTENT_TREE_ROOT_ID = 2;

private const CONTENT_TYPE_FOLDER_IDENTIFIER = 'folder';

protected function setUp(): void
{
parent::setUp();

self::loadSchema();
self::loadFixtures();

self::setAdministratorUser();
}

/**
* @param array<string, string> $names
*
* @throws \eZ\Publish\API\Repository\Exceptions\Exception
*/
public function createFolder(array $names, int $parentLocationId = self::CONTENT_TREE_ROOT_ID): Content

Check failure on line 36 in tests/integration/Core/RepositoryTestCase.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Method Ibexa\Tests\Integration\Core\RepositoryTestCase::createFolder() has invalid return type eZ\Publish\API\Repository\Values\Content\Content.

Check failure on line 36 in tests/integration/Core/RepositoryTestCase.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Method Ibexa\Tests\Integration\Core\RepositoryTestCase::createFolder() has invalid return type eZ\Publish\API\Repository\Values\Content\Content.

Check failure on line 36 in tests/integration/Core/RepositoryTestCase.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Method Ibexa\Tests\Integration\Core\RepositoryTestCase::createFolder() has invalid return type eZ\Publish\API\Repository\Values\Content\Content.
{
$contentService = self::getContentService();
$draft = $this->createFolderDraft($names, $parentLocationId);

return $contentService->publishVersion($draft->getVersionInfo());
}

/**
* @param array<string, string> $names
*
* @throws \eZ\Publish\API\Repository\Exceptions\Exception
*/
public function createFolderDraft(array $names, int $parentLocationId = self::CONTENT_TREE_ROOT_ID): Content

Check failure on line 49 in tests/integration/Core/RepositoryTestCase.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (7.4)

Method Ibexa\Tests\Integration\Core\RepositoryTestCase::createFolderDraft() has invalid return type eZ\Publish\API\Repository\Values\Content\Content.

Check failure on line 49 in tests/integration/Core/RepositoryTestCase.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.0)

Method Ibexa\Tests\Integration\Core\RepositoryTestCase::createFolderDraft() has invalid return type eZ\Publish\API\Repository\Values\Content\Content.

Check failure on line 49 in tests/integration/Core/RepositoryTestCase.php

View workflow job for this annotation

GitHub Actions / Unit tests & SQLite integration tests (8.1)

Method Ibexa\Tests\Integration\Core\RepositoryTestCase::createFolderDraft() has invalid return type eZ\Publish\API\Repository\Values\Content\Content.
{
if (empty($names)) {
throw new InvalidArgumentException(__METHOD__ . ' requires $names to be not empty');
}

$contentService = self::getContentService();
$contentTypeService = self::getContentTypeService();
$locationService = self::getLocationService();

$folderType = $contentTypeService->loadContentTypeByIdentifier(self::CONTENT_TYPE_FOLDER_IDENTIFIER);
$mainLanguageCode = array_keys($names)[0];
$contentCreateStruct = $contentService->newContentCreateStruct($folderType, $mainLanguageCode);
foreach ($names as $languageCode => $name) {
$contentCreateStruct->setField('name', $name, $languageCode);
}

return $contentService->createContent(
$contentCreateStruct,
[
$locationService->newLocationCreateStruct($parentLocationId),
]
);
}
}
Loading

0 comments on commit e29ab00

Please sign in to comment.