From be78b2b72209e1f8ec1ff29daeb7ed59d685cc33 Mon Sep 17 00:00:00 2001 From: Simon Schmidt Date: Tue, 31 Mar 2026 12:27:12 +0200 Subject: [PATCH] [BUGFIX] sync test for fields to update with config --- Classes/Domain/Service/AlternativeService.php | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/Classes/Domain/Service/AlternativeService.php b/Classes/Domain/Service/AlternativeService.php index 1a3b373..8ca8843 100644 --- a/Classes/Domain/Service/AlternativeService.php +++ b/Classes/Domain/Service/AlternativeService.php @@ -69,18 +69,36 @@ protected function getLanguagesToUpdate(array $properties, File $image): array protected function updateMetadata(int $uid, array $labels): void { - $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(self::TABLE); - $connection->update( - self::TABLE, - [ - 'title' => $labels['title'], - 'description' => $labels['description'], - 'alternative' => $labels['alternativeText'], - ], - [ - 'uid' => $uid, - ] - ); + $fieldsToUpdate = $this->getUpdatesFields($labels); + if ($fieldsToUpdate !== []) { + $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(self::TABLE); + $connection->update( + self::TABLE, + $fieldsToUpdate, + [ + 'uid' => $uid, + ] + ); + } + } + + protected function getUpdatesFields(array $labels): array + { + $fields = []; + + if (ConfigurationUtility::getConfigurationByKey('setTitle') === '1') { + $fields['title'] = $labels['title']; + } + + if (ConfigurationUtility::getConfigurationByKey('setDescription') === '1') { + $fields['description'] = $labels['description']; + } + + if (ConfigurationUtility::getConfigurationByKey('setAlternative') === '1') { + $fields['alternative'] = $labels['alternativeText']; + } + + return $fields; } protected function getOrCreateTranslation(int $metadataUid, int $languageUid, int $fileUid): array @@ -165,6 +183,8 @@ protected function shouldUpdate(array $properties): bool if ($this->enforce) { return true; } - return empty($properties['title']) && empty($properties['description']) && empty($properties['alternative']); + return (ConfigurationUtility::getConfigurationByKey('setTitle') !== '1' || empty($properties['title'])) && + (ConfigurationUtility::getConfigurationByKey('setDescription') !== '1' || empty($properties['description'])) && + (ConfigurationUtility::getConfigurationByKey('setAlternative') !== '1' || empty($properties['alternative'])); } }