зеркало из https://github.com/nextcloud/cookbook.git
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:
Родитель
49924f81c8
Коммит
2565266dd7
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче