Skip to content

Commit

Permalink
Merge pull request #61 from getkirby/fix/clean-content-throw-exception
Browse files Browse the repository at this point in the history
Fix throwing exception in `clean:content` command
  • Loading branch information
bastianallgeier authored Feb 22, 2024
2 parents b6837de + e9a100c commit 6430c1f
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions commands/clean/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Kirby\CLI\CLI;

function clean(
$cleanContent = function (
Generator $collection,
array|null $ignore = null,
string|null $lang = null
Expand Down Expand Up @@ -36,18 +36,14 @@ function clean(
$data = array_map(fn ($value) => null, array_flip($fieldsToBeDeleted));

// try to update the page with the data
try {
$item->update($data, $lang);
} catch (Exception $e) {
throw $e->getMessage();
}
$item->update($data, $lang);
}
}
}
};

return [
'description' => 'Deletes all fields from page, file or user content files that are not defined in the blueprint, no matter if they contain content or not.',
'command' => static function (CLI $cli): void {
'command' => static function (CLI $cli) use ($cleanContent): void {

$cli->confirmToContinue('This will delete all fields from content files that are not defined in blueprints, no matter if they contain content or not. Are you sure?');

Expand All @@ -63,17 +59,21 @@ function clean(
$ignore = ['uuid', 'title', 'slug', 'template', 'sort', 'focus'];

// call the script for all languages if multilang
if ($kirby->multilang() === true) {
$languages = $kirby->languages();
try {
if ($kirby->multilang() === true) {
$languages = $kirby->languages();

foreach ($languages as $language) {
$cleanContent($collection, $ignore, $language->code());
}

foreach ($languages as $language) {
clean($collection, $ignore, $language->code());
} else {
$cleanContent($collection, $ignore);
}

} else {
clean($collection, $ignore);
$cli->success('The content files have been cleaned');
} catch (Exception $e) {
$cli->error($e->getMessage());
}

$cli->success('The content files have been cleaned');
}
];

0 comments on commit 6430c1f

Please sign in to comment.