Skip to content

Commit 4f3f5da

Browse files
IBX-5905: Added content type identifier to ContentInfo
1 parent b475a03 commit 4f3f5da

File tree

11 files changed

+503
-9
lines changed

11 files changed

+503
-9
lines changed

src/contracts/Persistence/Content/ContentInfo.php

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class ContentInfo extends ValueObject
4343
*/
4444
public $contentTypeId;
4545

46+
public string $contentTypeIdentifier;
47+
4648
/**
4749
* Section id the content is assigned to.
4850
*
@@ -134,6 +136,11 @@ class ContentInfo extends ValueObject
134136
* @var bool
135137
*/
136138
public $isHidden = false;
139+
140+
public function getContentIdentifier(): string
141+
{
142+
return $this->contentTypeIdentifier;
143+
}
137144
}
138145

139146
class_alias(ContentInfo::class, 'eZ\Publish\SPI\Persistence\Content\ContentInfo');

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,8 @@ private function internalLoadContent(
769769
'a.data_text AS ezcontentobject_attribute_data_text',
770770
'a.sort_key_int AS ezcontentobject_attribute_sort_key_int',
771771
'a.sort_key_string AS ezcontentobject_attribute_sort_key_string',
772-
't.main_node_id AS ezcontentobject_tree_main_node_id'
772+
't.main_node_id AS ezcontentobject_tree_main_node_id',
773+
'cc.identifier AS ezcontentclass_identifier',
773774
)
774775
->from('ezcontentobject', 'c')
775776
->innerJoin(
@@ -798,6 +799,15 @@ private function internalLoadContent(
798799
$expr->eq('c.id', 't.contentobject_id'),
799800
$expr->eq('t.node_id', 't.main_node_id')
800801
)
802+
)
803+
->leftJoin(
804+
'c',
805+
'ezcontentclass',
806+
'cc',
807+
$expr->and(
808+
$expr->eq('c.contentclass_id', 'cc.id'),
809+
$expr->eq('cc.version', 0)
810+
)
801811
);
802812

803813
$queryBuilder->where(

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

+26-2
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,26 @@ public function createLoadContentInfoQueryBuilder(
113113
}
114114

115115
$queryBuilder
116-
->select('c.*', 't.main_node_id AS ezcontentobject_tree_main_node_id')
116+
->select(
117+
'c.*',
118+
't.main_node_id AS ezcontentobject_tree_main_node_id',
119+
'cc.identifier AS ezcontentclass_identifier'
120+
)
117121
->from(Gateway::CONTENT_ITEM_TABLE, 'c')
118122
->leftJoin(
119123
'c',
120124
'ezcontentobject_tree',
121125
't',
122126
$joinCondition
127+
)
128+
->leftJoin(
129+
'c',
130+
'ezcontentclass',
131+
'cc',
132+
$expr->and(
133+
$expr->eq('c.contentclass_id', 'cc.id'),
134+
$expr->eq('cc.version', 0)
135+
)
123136
);
124137

125138
return $queryBuilder;
@@ -163,7 +176,9 @@ public function createVersionInfoFindQueryBuilder(): DoctrineQueryBuilder
163176
'c.status AS ezcontentobject_status',
164177
'c.name AS ezcontentobject_name',
165178
'c.language_mask AS ezcontentobject_language_mask',
166-
'c.is_hidden AS ezcontentobject_is_hidden'
179+
'c.is_hidden AS ezcontentobject_is_hidden',
180+
// Content class
181+
'cc.identifier AS ezcontentclass_identifier'
167182
)
168183
->from(Gateway::CONTENT_VERSION_TABLE, 'v')
169184
->innerJoin(
@@ -180,6 +195,15 @@ public function createVersionInfoFindQueryBuilder(): DoctrineQueryBuilder
180195
$expr->eq('t.contentobject_id', 'v.contentobject_id'),
181196
$expr->eq('t.main_node_id', 't.node_id')
182197
)
198+
)
199+
->leftJoin(
200+
'c',
201+
'ezcontentclass',
202+
'cc',
203+
$expr->and(
204+
$expr->eq('c.contentclass_id', 'cc.id'),
205+
$expr->eq('cc.version', 0)
206+
)
183207
);
184208

185209
return $query;

src/lib/Persistence/Legacy/Content/Mapper.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,17 @@ public function extractContentFromRows(array $rows, array $nameRows, $prefix = '
243243
*
244244
* @return \Ibexa\Contracts\Core\Persistence\Content\ContentInfo
245245
*/
246-
public function extractContentInfoFromRow(array $row, $prefix = '', $treePrefix = 'ezcontentobject_tree_')
247-
{
246+
public function extractContentInfoFromRow(
247+
array $row,
248+
$prefix = '',
249+
$treePrefix = 'ezcontentobject_tree_',
250+
$contentClassPrefix = 'ezcontentclass_'
251+
) {
248252
$contentInfo = new ContentInfo();
249253
$contentInfo->id = (int)$row["{$prefix}id"];
250254
$contentInfo->name = $row["{$prefix}name"];
251255
$contentInfo->contentTypeId = (int)$row["{$prefix}contentclass_id"];
256+
$contentInfo->contentTypeIdentifier = $row["{$contentClassPrefix}identifier"];
252257
$contentInfo->sectionId = (int)$row["{$prefix}section_id"];
253258
$contentInfo->currentVersionNo = (int)$row["{$prefix}current_version"];
254259
$contentInfo->isPublished = ($row["{$prefix}status"] == ContentInfo::STATUS_PUBLISHED);

src/lib/Search/Legacy/Content/Gateway/DoctrineDatabase.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,9 @@ private function getContentInfoList(
216216
array $languageFilter
217217
): array {
218218
$query = $this->connection->createQueryBuilder();
219+
$expr = $query->expr();
219220
$query->select(
220-
'DISTINCT c.*, main_tree.main_node_id AS main_tree_main_node_id',
221+
'DISTINCT c.*, main_tree.main_node_id AS main_tree_main_node_id, cc.identifier AS ezcontentclass_identifier',
221222
);
222223

223224
if ($sort !== null) {
@@ -236,10 +237,19 @@ private function getContentInfoList(
236237
'c',
237238
LocationGateway::CONTENT_TREE_TABLE,
238239
'main_tree',
239-
$query->expr()->andX(
240+
$expr->andX(
240241
'main_tree.contentobject_id = c.id',
241242
'main_tree.main_node_id = main_tree.node_id'
242243
)
244+
)
245+
->leftJoin(
246+
'c',
247+
'ezcontentclass',
248+
'cc',
249+
$expr->and(
250+
$expr->eq('c.contentclass_id', 'cc.id'),
251+
$expr->eq('cc.version', 0)
252+
)
243253
);
244254

245255
if ($sort !== null) {

tests/lib/Persistence/Legacy/Content/Gateway/DoctrineDatabaseTest.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ public function testListVersions(): void
608608

609609
foreach ($res as $row) {
610610
$this->assertCount(
611-
23,
611+
24,
612612
$row
613613
);
614614
}
@@ -651,7 +651,7 @@ public function testListVersionsForUser()
651651

652652
foreach ($res as $row) {
653653
$this->assertCount(
654-
23,
654+
24,
655655
$row
656656
);
657657
}
@@ -698,6 +698,10 @@ public function testLoadWithAllTranslations()
698698

699699
public function testCreateFixtureForMapperExtractContentFromRowsMultipleVersions()
700700
{
701+
$this->insertDatabaseFixture(
702+
__DIR__ . '/../_fixtures/contentclass.php'
703+
);
704+
701705
$this->insertDatabaseFixture(
702706
__DIR__ . '/../_fixtures/contentobjects.php'
703707
);
@@ -721,6 +725,10 @@ public function testCreateFixtureForMapperExtractContentFromRowsMultipleVersions
721725

722726
public function testCreateFixtureForMapperExtractContentFromRows()
723727
{
728+
$this->insertDatabaseFixture(
729+
__DIR__ . '/../_fixtures/contentclass.php'
730+
);
731+
724732
$this->insertDatabaseFixture(
725733
__DIR__ . '/../_fixtures/contentobjects.php'
726734
);
@@ -1667,6 +1675,10 @@ public function testUpdateContentRemoveAlwaysAvailableFlagMultilingual(): void
16671675
*/
16681676
public function testLoadVersionInfo(): void
16691677
{
1678+
$this->insertDatabaseFixture(
1679+
__DIR__ . '/../_fixtures/contentclass.php'
1680+
);
1681+
16701682
$this->insertDatabaseFixture(
16711683
__DIR__ . '/../_fixtures/contentobjects.php'
16721684
);

0 commit comments

Comments
 (0)