fix: Allow single tool in JSON+LD import

Previously an array of tools was required.

Closes #1641

Signed-off-by: Sebastian Fey <info@sebastianfey.de>
This commit is contained in:
Sebastian Fey 2023-10-29 14:07:42 +01:00
Родитель 49924f81c8
Коммит 2565266dd7
1 изменённых файлов: 17 добавлений и 11 удалений

Просмотреть файл

@ -41,20 +41,26 @@ class FixToolsFilter extends AbstractJSONFilter {
return true;
}
if (!is_array($json[self::TOOLS])) {
throw new InvalidRecipeException($this->l->t('Could not parse recipe tools. It is no array.'));
if (!is_array($json[self::TOOLS]) && !is_string($json[self::TOOLS])) {
throw new InvalidRecipeException($this->l->t('Could not parse recipe tools. Expected array or string.'));
}
$tools = $json[self::TOOLS];
$tools = array();
$tools = array_map(function ($t) {
$t = trim($t);
$t = $this->textCleaner->cleanUp($t, false);
return $t;
}, $tools);
$tools = array_filter($tools, fn ($t) => ($t));
ksort($tools);
$tools = array_values($tools);
if (!is_array($json[self::TOOLS])) {
$t = trim($json[self::TOOLS]);
$tools[] = $this->textCleaner->cleanUp($t, false);
}
else{
$tools = array_map(function ($t) {
$t = trim($t);
$t = $this->textCleaner->cleanUp($t, false);
return $t;
}, $json[self::TOOLS]);
$tools = array_filter($tools, fn($t) => ($t));
ksort($tools);
$tools = array_values($tools);
}
$changed = $tools !== $json[self::TOOLS];
$json[self::TOOLS] = $tools;