Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-8562: Fixed flooding content attributes table with duplicates #409

Merged
merged 7 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions eZ/Publish/Core/Persistence/Legacy/Content/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ public function load($id, $version = null, array $translations = null)
$this->contentGateway->loadVersionedNameData([[
'id' => $id,
'version' => $rows[0]['ezcontentobject_version_version'],
]])
]]),
'ezcontentobject_',
$translations
);
$content = $contentObjects[0];
unset($rows, $contentObjects);
Expand Down Expand Up @@ -371,7 +373,9 @@ public function loadContentList(array $contentIds, array $translations = null):
try {
$contentList = $this->mapper->extractContentFromRows(
$contentItemsRow,
$contentItemNameData[$contentId]
$contentItemNameData[$contentId],
'ezcontentobject_',
$translations
);
$contentItems[$contentId] = $contentList[0];
} catch (Exception $e) {
Expand Down
18 changes: 12 additions & 6 deletions eZ/Publish/Core/Persistence/Legacy/Content/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public function convertToStorageValue(Field $field)
* @param array<array<string, scalar>> $rows
* @param array<array<string, scalar>> $nameRows
* @param string $prefix
* @param array<string>|null $translations
*
* @return \eZ\Publish\SPI\Persistence\Content[]
*
Expand All @@ -228,7 +229,8 @@ public function convertToStorageValue(Field $field)
public function extractContentFromRows(
array $rows,
array $nameRows,
string $prefix = 'ezcontentobject_'
string $prefix = 'ezcontentobject_',
?array $translations = null
): array {
$versionedNameData = [];

Expand All @@ -245,7 +247,8 @@ public function extractContentFromRows(

$fieldDefinitions = $this->loadCachedVersionFieldDefinitionsPerLanguage(
$rows,
$prefix
$prefix,
$translations
);

foreach ($rows as $row) {
Expand Down Expand Up @@ -313,9 +316,10 @@ private function buildContentObjects(
$content->versionInfo = $versionInfo;
$content->versionInfo->names = $names;
$content->versionInfo->contentInfo = $contentInfo;
$content->fields = array_values($fields[$contentId][$versionId]);
$content->fields = array_values($fields[$contentId][$versionId] ?? []);

$missingVersionFieldDefinitions = $missingFieldDefinitions[$contentId][$versionId] ?? [];

$missingVersionFieldDefinitions = $missingFieldDefinitions[$contentId][$versionId];
foreach ($missingVersionFieldDefinitions as $languageCode => $versionFieldDefinitions) {
foreach ($versionFieldDefinitions as $fieldDefinition) {
$event = $this->eventDispatcher->dispatch(
Expand Down Expand Up @@ -347,7 +351,8 @@ private function buildContentObjects(
*/
private function loadCachedVersionFieldDefinitionsPerLanguage(
array $rows,
string $prefix
string $prefix,
?array $translations = null
): array {
$fieldDefinitions = [];
$contentTypes = [];
Expand All @@ -363,7 +368,8 @@ private function loadCachedVersionFieldDefinitionsPerLanguage(
continue;
}

$languageCodes = $this->extractLanguageCodesFromMask($languageMask, $allLanguages);
$allLanguagesCodes = $this->extractLanguageCodesFromMask($languageMask, $allLanguages);
$languageCodes = empty($translations) ? $allLanguagesCodes : array_intersect($translations, $allLanguagesCodes);
alongosz marked this conversation as resolved.
Show resolved Hide resolved
$contentTypes[$contentTypeId] = $contentTypes[$contentTypeId] ?? $this->contentTypeHandler->load($contentTypeId);
$contentType = $contentTypes[$contentTypeId];
foreach ($contentType->fieldDefinitions as $fieldDefinition) {
Expand Down
Loading