From 07e30320f3c0b45a6dd9844ddaa6fa457daa42c2 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk Date: Fri, 23 Oct 2026 13:35:01 +0200 Subject: [PATCH] [MAINTENANCE] Shorten 'place' metadata field value Introduces a reusable 'shortenValue' method to limit the length of concatenated metadata strings. This method is now applied to the 'place' field to prevent overly long values. The 'getAuthors' method was also refactored to utilize this new common shortening logic, gracefully adding 'et al.' when truncated. --- Classes/Command/BaseCommand.php | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/Classes/Command/BaseCommand.php b/Classes/Command/BaseCommand.php index 2178164f56..9610ea5cfa 100644 --- a/Classes/Command/BaseCommand.php +++ b/Classes/Command/BaseCommand.php @@ -215,7 +215,7 @@ protected function saveToDatabase(Document $document, bool $softCommit = false): // set title data $document->setTitle($metadata['title'][0] ?? ''); $document->setTitleSorting($metadata['title_sorting'][0] ?? ''); - $document->setPlace(implode('; ', $metadata['place'] ?? [])); + $document->setPlace($this->shortenValue($metadata['place'] ?? [])); $document->setYear(implode('; ', $metadata['year'] ?? [])); $document->setAuthor($this->getAuthors($metadata['author'] ?? [])); $document->setThumbnail($doc->thumbnail); @@ -447,26 +447,39 @@ private function getAuthors(array $metadataAuthor): string } } - $authors = ''; + return $this->shortenValue($metadataAuthor); + } + + /** + * Shorten the value to a maximum length, adding an ellipsis if necessary. + * + * @access private + * + * @param array $values The values to shorten + * + * @return string The shortened value + */ + private function shortenValue(array $values): string + { + $value = ''; $delimiter = '; '; $ellipsis = 'et al.'; - $count = count($metadataAuthor); + $count = count($values); for ($i = 0; $i < $count; $i++) { // Build the next part to add - $nextPart = ($i === 0 ? '' : $delimiter) . $metadataAuthor[$i]; + $nextPart = ($i === 0 ? '' : $delimiter) . $values[$i]; // Check if adding this part and ellipsis in future would exceed the character limit - if (strlen($authors . $nextPart . $delimiter . $ellipsis) > 255) { - // Add ellipsis and stop adding more authors - $authors .= $delimiter . $ellipsis; + if (strlen($value . $nextPart . $delimiter . $ellipsis) > 255) { + // Add ellipsis and stop adding more values + $value .= $delimiter . $ellipsis; break; } // Add the part to the main string - $authors .= $nextPart; + $value .= $nextPart; } - - return $authors; + return $value; } /**