Skip to content

Commit

Permalink
Changed naming & query building, tests adapted to changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszdebinski committed Jul 25, 2024
1 parent 4eae46a commit f313a56
Show file tree
Hide file tree
Showing 24 changed files with 728 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/contracts/Persistence/Content/ContentInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class ContentInfo extends ValueObject
*/
public $isHidden = false;

public function getContentIdentifier(): string
public function getContentTypeIdentifier(): string
{
return $this->contentTypeIdentifier;
}
Expand Down
17 changes: 9 additions & 8 deletions src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler;
use Ibexa\Contracts\Core\Persistence\Content\MetadataUpdateStruct;
use Ibexa\Contracts\Core\Persistence\Content\Relation\CreateStruct as RelationCreateStruct;
use Ibexa\Contracts\Core\Persistence\Content\Type;
use Ibexa\Contracts\Core\Persistence\Content\UpdateStruct;
use Ibexa\Contracts\Core\Persistence\Content\VersionInfo;
use Ibexa\Contracts\Core\Repository\Values\Content\Relation;
Expand Down Expand Up @@ -770,14 +771,14 @@ private function internalLoadContent(
'a.sort_key_int AS ezcontentobject_attribute_sort_key_int',
'a.sort_key_string AS ezcontentobject_attribute_sort_key_string',
't.main_node_id AS ezcontentobject_tree_main_node_id',
'cc.identifier AS ezcontentclass_identifier',
'ct.identifier AS content_type_identifier',
)
->from('ezcontentobject', 'c')
->innerJoin(
'c',
'ezcontentobject_version',
'v',
$expr->andX(
$expr->and(
$expr->eq('c.id', 'v.contentobject_id'),
$expr->eq('v.version', $version ?? 'c.current_version')
)
Expand All @@ -786,7 +787,7 @@ private function internalLoadContent(
'v',
'ezcontentobject_attribute',
'a',
$expr->andX(
$expr->and(
$expr->eq('v.contentobject_id', 'a.contentobject_id'),
$expr->eq('v.version', 'a.version')
)
Expand All @@ -795,18 +796,18 @@ private function internalLoadContent(
'c',
'ezcontentobject_tree',
't',
$expr->andX(
$expr->and(
$expr->eq('c.id', 't.contentobject_id'),
$expr->eq('t.node_id', 't.main_node_id')
)
)
->leftJoin(
->innerJoin(
'c',
'ezcontentclass',
'cc',
'ct',
$expr->and(
$expr->eq('c.contentclass_id', 'cc.id'),
$expr->eq('cc.version', 0)
$expr->eq('c.contentclass_id', 'ct.id'),
$expr->eq('ct.version', Type::STATUS_DEFINED)
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Query\QueryBuilder as DoctrineQueryBuilder;
use Ibexa\Contracts\Core\Persistence\Content\Type;
use Ibexa\Core\Persistence\Legacy\Content\Gateway;
use function time;

Expand Down Expand Up @@ -116,7 +117,7 @@ public function createLoadContentInfoQueryBuilder(
->select(
'c.*',
't.main_node_id AS ezcontentobject_tree_main_node_id',
'cc.identifier AS ezcontentclass_identifier'
'ct.identifier AS content_type_identifier'
)
->from(Gateway::CONTENT_ITEM_TABLE, 'c')
->leftJoin(
Expand All @@ -125,13 +126,13 @@ public function createLoadContentInfoQueryBuilder(
't',
$joinCondition
)
->leftJoin(
->innerJoin(
'c',
'ezcontentclass',
'cc',
'ct',
$expr->and(
$expr->eq('c.contentclass_id', 'cc.id'),
$expr->eq('cc.version', 0)
$expr->eq('c.contentclass_id', 'ct.id'),
$expr->eq('ct.version', Type::STATUS_DEFINED)
)
);

Expand Down Expand Up @@ -177,8 +178,7 @@ public function createVersionInfoFindQueryBuilder(): DoctrineQueryBuilder
'c.name AS ezcontentobject_name',
'c.language_mask AS ezcontentobject_language_mask',
'c.is_hidden AS ezcontentobject_is_hidden',
// Content class
'cc.identifier AS ezcontentclass_identifier'
'ct.identifier AS content_type_identifier'
)
->from(Gateway::CONTENT_VERSION_TABLE, 'v')
->innerJoin(
Expand All @@ -196,13 +196,13 @@ public function createVersionInfoFindQueryBuilder(): DoctrineQueryBuilder
$expr->eq('t.main_node_id', 't.node_id')
)
)
->leftJoin(
->innerJoin(
'c',
'ezcontentclass',
'cc',
'ct',
$expr->and(
$expr->eq('c.contentclass_id', 'cc.id'),
$expr->eq('cc.version', 0)
$expr->eq('c.contentclass_id', 'ct.id'),
$expr->eq('ct.version', Type::STATUS_DEFINED)
)
);

Expand Down
5 changes: 2 additions & 3 deletions src/lib/Persistence/Legacy/Content/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,13 @@ private function loadCachedVersionFieldDefinitionsPerLanguage(
public function extractContentInfoFromRow(
array $row,
$prefix = '',
$treePrefix = 'ezcontentobject_tree_',
$contentClassPrefix = 'ezcontentclass_'
$treePrefix = 'ezcontentobject_tree_'
) {
$contentInfo = new ContentInfo();
$contentInfo->id = (int)$row["{$prefix}id"];
$contentInfo->name = (string)$row["{$prefix}name"];
$contentInfo->contentTypeId = (int)$row["{$prefix}contentclass_id"];
$contentInfo->contentTypeIdentifier = $row["{$contentClassPrefix}identifier"];
$contentInfo->contentTypeIdentifier = $row['content_type_identifier'];
$contentInfo->sectionId = (int)$row["{$prefix}section_id"];
$contentInfo->currentVersionNo = (int)$row["{$prefix}current_version"];
$contentInfo->ownerId = (int)$row["{$prefix}owner_id"];
Expand Down
13 changes: 7 additions & 6 deletions src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Doctrine\DBAL\Query\QueryBuilder;
use Ibexa\Contracts\Core\Persistence\Content\ContentInfo;
use Ibexa\Contracts\Core\Persistence\Content\Language\Handler as LanguageHandler;
use Ibexa\Contracts\Core\Persistence\Content\Type;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo;
use Ibexa\Core\Persistence\Legacy\Content\Gateway as ContentGateway;
Expand Down Expand Up @@ -218,7 +219,7 @@ private function getContentInfoList(
$query = $this->connection->createQueryBuilder();
$expr = $query->expr();
$query->select(
'DISTINCT c.*, main_tree.main_node_id AS main_tree_main_node_id, cc.identifier AS ezcontentclass_identifier',
'DISTINCT c.*, main_tree.main_node_id AS main_tree_main_node_id, ct.identifier AS content_type_identifier',
);

if ($sort !== null) {
Expand All @@ -237,18 +238,18 @@ private function getContentInfoList(
'c',
LocationGateway::CONTENT_TREE_TABLE,
'main_tree',
$expr->andX(
$expr->and(
'main_tree.contentobject_id = c.id',
'main_tree.main_node_id = main_tree.node_id'
)
)
->leftJoin(
->innerJoin(
'c',
'ezcontentclass',
'cc',
'ct',
$expr->and(
$expr->eq('c.contentclass_id', 'cc.id'),
$expr->eq('cc.version', 0)
$expr->eq('c.contentclass_id', 'ct.id'),
$expr->eq('ct.version', Type::STATUS_DEFINED)
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,7 @@ public function testUpdateContent()
{
$gateway = $this->getDatabaseGateway();

$this->insertDatabaseFixture(
__DIR__ . '/../_fixtures/contentobjects.php'
);
$this->insertContentToDatabase();

$metadataStruct = $this->getMetadataUpdateStructFixture();

Expand Down Expand Up @@ -594,9 +592,7 @@ public function testUpdateNonTranslatableField()

public function testListVersions(): void
{
$this->insertDatabaseFixture(
__DIR__ . '/../_fixtures/contentobjects.php'
);
$this->insertContentToDatabase();

$gateway = $this->getDatabaseGateway();
$res = $gateway->listVersions(226);
Expand Down Expand Up @@ -637,9 +633,7 @@ public function testListVersionNumbers()

public function testListVersionsForUser()
{
$this->insertDatabaseFixture(
__DIR__ . '/../_fixtures/contentobjects.php'
);
$this->insertContentToDatabase();

$gateway = $this->getDatabaseGateway();
$res = $gateway->listVersionsForUser(14);
Expand Down Expand Up @@ -676,9 +670,7 @@ public function testListVersionsForUser()

public function testLoadWithAllTranslations()
{
$this->insertDatabaseFixture(
__DIR__ . '/../_fixtures/contentobjects.php'
);
$this->insertContentToDatabase();

$gateway = $this->getDatabaseGateway();
$res = $gateway->load(226, 2);
Expand Down Expand Up @@ -737,9 +729,7 @@ public function testCreateFixtureForMapperExtractContentFromRows()

public function testLoadWithSingleTranslation()
{
$this->insertDatabaseFixture(
__DIR__ . '/../_fixtures/contentobjects.php'
);
$this->insertContentToDatabase();

$gateway = $this->getDatabaseGateway();
$res = $gateway->load(226, 2, [self::ENG_GB]);
Expand Down Expand Up @@ -1430,9 +1420,7 @@ public function testDeleteRelationWithCompositeBitmask(): void
*/
public function testUpdateAlwaysAvailableFlagRemove(): void
{
$this->insertDatabaseFixture(
__DIR__ . '/../_fixtures/contentobjects.php'
);
$this->insertContentToDatabase();

$gateway = $this->getDatabaseGateway();
$gateway->updateAlwaysAvailableFlag(103, false);
Expand Down Expand Up @@ -1496,9 +1484,7 @@ public function testUpdateAlwaysAvailableFlagRemove(): void
*/
public function testUpdateAlwaysAvailableFlagAdd(): void
{
$this->insertDatabaseFixture(
__DIR__ . '/../_fixtures/contentobjects.php'
);
$this->insertContentToDatabase();

$gateway = $this->getDatabaseGateway();
$contentId = 102;
Expand Down Expand Up @@ -1566,9 +1552,7 @@ public function testUpdateAlwaysAvailableFlagAdd(): void
*/
public function testUpdateContentAddAlwaysAvailableFlagMultilingual(): void
{
$this->insertDatabaseFixture(
__DIR__ . '/../_fixtures/contentobjects_multilingual.php'
);
$this->insertContentToDatabase('contentobjects_multilingual.php');

$gateway = $this->getDatabaseGateway();
$contentMetadataUpdateStruct = new MetadataUpdateStruct(
Expand Down Expand Up @@ -1615,9 +1599,7 @@ public function testUpdateContentAddAlwaysAvailableFlagMultilingual(): void
*/
public function testUpdateContentRemoveAlwaysAvailableFlagMultilingual(): void
{
$this->insertDatabaseFixture(
__DIR__ . '/../_fixtures/contentobjects_multilingual.php'
);
$this->insertContentToDatabase('contentobjects_multilingual.php');

$gateway = $this->getDatabaseGateway();
$contentMetadataUpdateStruct = new MetadataUpdateStruct(
Expand Down Expand Up @@ -1984,14 +1966,14 @@ private function assertContentVersionAttributesLanguages(
);
}

private function insertContentToDatabase(): void
private function insertContentToDatabase(string $fileName = 'contentobjects.php'): void
{
$this->insertDatabaseFixture(
__DIR__ . '/../_fixtures/contentclass.php'
);

$this->insertDatabaseFixture(
__DIR__ . '/../_fixtures/contentobjects.php'
__DIR__ . '/../_fixtures/' . $fileName
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,13 @@
'id' => 3,
'initial_language_id' => 2,
'current_version' => 1,
'contentclass_id' => 1,
],
1 => [
'id' => 4,
'initial_language_id' => 2,
'current_version' => 1,
'contentclass_id' => 2,
],
],
'ezcontentobject_name' => [
Expand Down Expand Up @@ -223,4 +225,46 @@
'content_translation' => 'eng-GB',
],
],
'ezcontentclass' => [
0 => [
'id' => 1,
'version' => '0',
'always_available' => 0,
'contentobject_name' => '<short_name|name>',
'created' => '1033917596',
'creator_id' => 14,
'identifier' => 'folder',
'initial_language_id' => 2,
'is_container' => true,
'language_mask' => 2,
'modified' => '1311154215',
'modifier_id' => 14,
'remote_id' => '5fcdb3fb687dd6dcf8c94bc84e8bd1b2',
'serialized_description_list' => 'a:0:{}',
'serialized_name_list' => 'a:1:{s:6:"eng-GB";s:6:"Folder";}',
'sort_field' => 1,
'sort_order' => 1,
'url_alias_name' => null,
],
1 => [
'id' => 2,
'version' => '0',
'always_available' => 1,
'contentobject_name' => '<name>',
'created' => '1033917896',
'creator_id' => 14,
'identifier' => 'user_group',
'initial_language_id' => 2,
'is_container' => true,
'language_mask' => 2,
'modified' => '1311154815',
'modifier_id' => 14,
'remote_id' => '0f2622aad22267e195c8e76b05c25e29',
'serialized_description_list' => 'a:0:{}',
'serialized_name_list' => 'a:2:{s:6:"eng-GB";s:10:"User group";s:16:"always-available";s:6:"eng-GB";}',
'sort_field' => 1,
'sort_order' => 1,
'url_alias_name' => null,
],
],
];
Loading

0 comments on commit f313a56

Please sign in to comment.