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; } /**