Skip to content

Commit

Permalink
IBX-5905: Added content type identifier to ContentInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszdebinski committed Jul 26, 2023
1 parent b475a03 commit f36b357
Show file tree
Hide file tree
Showing 11 changed files with 505 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/contracts/Persistence/Content/ContentInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class ContentInfo extends ValueObject
*/
public $contentTypeId;

public string $contentTypeIdentifier;

/**
* Section id the content is assigned to.
*
Expand Down Expand Up @@ -134,6 +136,11 @@ class ContentInfo extends ValueObject
* @var bool
*/
public $isHidden = false;

public function getContentIdentifier(): string
{
return $this->contentTypeIdentifier;
}
}

class_alias(ContentInfo::class, 'eZ\Publish\SPI\Persistence\Content\ContentInfo');
12 changes: 11 additions & 1 deletion src/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,8 @@ private function internalLoadContent(
'a.data_text AS ezcontentobject_attribute_data_text',
'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'
't.main_node_id AS ezcontentobject_tree_main_node_id',
'cc.identifier AS ezcontentclass_identifier',
)
->from('ezcontentobject', 'c')
->innerJoin(
Expand Down Expand Up @@ -798,6 +799,15 @@ private function internalLoadContent(
$expr->eq('c.id', 't.contentobject_id'),
$expr->eq('t.node_id', 't.main_node_id')
)
)
->leftJoin(
'c',
'ezcontentclass',
'cc',
$expr->and(
$expr->eq('c.contentclass_id', 'cc.id'),
$expr->eq('cc.version', 0)
)
);

$queryBuilder->where(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,26 @@ public function createLoadContentInfoQueryBuilder(
}

$queryBuilder
->select('c.*', 't.main_node_id AS ezcontentobject_tree_main_node_id')
->select(
'c.*',
't.main_node_id AS ezcontentobject_tree_main_node_id',
'cc.identifier AS ezcontentclass_identifier'
)
->from(Gateway::CONTENT_ITEM_TABLE, 'c')
->leftJoin(
'c',
'ezcontentobject_tree',
't',
$joinCondition
)
->leftJoin(
'c',
'ezcontentclass',
'cc',
$expr->and(
$expr->eq('c.contentclass_id', 'cc.id'),
$expr->eq('cc.version', 0)
)
);

return $queryBuilder;
Expand Down Expand Up @@ -163,7 +176,9 @@ public function createVersionInfoFindQueryBuilder(): DoctrineQueryBuilder
'c.status AS ezcontentobject_status',
'c.name AS ezcontentobject_name',
'c.language_mask AS ezcontentobject_language_mask',
'c.is_hidden AS ezcontentobject_is_hidden'
'c.is_hidden AS ezcontentobject_is_hidden',
// Content class
'cc.identifier AS ezcontentclass_identifier'
)
->from(Gateway::CONTENT_VERSION_TABLE, 'v')
->innerJoin(
Expand All @@ -180,6 +195,15 @@ public function createVersionInfoFindQueryBuilder(): DoctrineQueryBuilder
$expr->eq('t.contentobject_id', 'v.contentobject_id'),
$expr->eq('t.main_node_id', 't.node_id')
)
)
->leftJoin(
'c',
'ezcontentclass',
'cc',
$expr->and(
$expr->eq('c.contentclass_id', 'cc.id'),
$expr->eq('cc.version', 0)
)
);

return $query;
Expand Down
9 changes: 7 additions & 2 deletions src/lib/Persistence/Legacy/Content/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,17 @@ public function extractContentFromRows(array $rows, array $nameRows, $prefix = '
*
* @return \Ibexa\Contracts\Core\Persistence\Content\ContentInfo
*/
public function extractContentInfoFromRow(array $row, $prefix = '', $treePrefix = 'ezcontentobject_tree_')
{
public function extractContentInfoFromRow(
array $row,
$prefix = '',
$treePrefix = 'ezcontentobject_tree_',
$contentClassPrefix = 'ezcontentclass_'
) {
$contentInfo = new ContentInfo();
$contentInfo->id = (int)$row["{$prefix}id"];
$contentInfo->name = $row["{$prefix}name"];
$contentInfo->contentTypeId = (int)$row["{$prefix}contentclass_id"];
$contentInfo->contentTypeIdentifier = $row["{$contentClassPrefix}identifier"];
$contentInfo->sectionId = (int)$row["{$prefix}section_id"];
$contentInfo->currentVersionNo = (int)$row["{$prefix}current_version"];
$contentInfo->isPublished = ($row["{$prefix}status"] == ContentInfo::STATUS_PUBLISHED);
Expand Down
14 changes: 12 additions & 2 deletions src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,9 @@ private function getContentInfoList(
array $languageFilter
): array {
$query = $this->connection->createQueryBuilder();
$expr = $query->expr();
$query->select(
'DISTINCT c.*, main_tree.main_node_id AS main_tree_main_node_id',
'DISTINCT c.*, main_tree.main_node_id AS main_tree_main_node_id, cc.identifier AS ezcontentclass_identifier',
);

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

if ($sort !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ public function testListVersions(): void

foreach ($res as $row) {
$this->assertCount(
23,
24,
$row
);
}
Expand Down Expand Up @@ -651,7 +651,7 @@ public function testListVersionsForUser()

foreach ($res as $row) {
$this->assertCount(
23,
24,
$row
);
}
Expand Down Expand Up @@ -698,9 +698,7 @@ public function testLoadWithAllTranslations()

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

$gateway = $this->getDatabaseGateway();

Expand All @@ -721,9 +719,7 @@ public function testCreateFixtureForMapperExtractContentFromRowsMultipleVersions

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

$gateway = $this->getDatabaseGateway();

Expand Down Expand Up @@ -1667,9 +1663,7 @@ public function testUpdateContentRemoveAlwaysAvailableFlagMultilingual(): void
*/
public function testLoadVersionInfo(): void
{
$this->insertDatabaseFixture(
__DIR__ . '/../_fixtures/contentobjects.php'
);
$this->insertContentToDatabase();

$gateway = $this->getDatabaseGateway();

Expand Down Expand Up @@ -1989,6 +1983,17 @@ private function assertContentVersionAttributesLanguages(
->orderBy('id')
);
}

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

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

class_alias(DoctrineDatabaseTest::class, 'eZ\Publish\Core\Persistence\Legacy\Tests\Content\Gateway\DoctrineDatabaseTest');
Loading

0 comments on commit f36b357

Please sign in to comment.