|
8 | 8 | $cleanContent = function ( |
9 | 9 | CLI $cli, |
10 | 10 | Generator $collection, |
11 | | - array|null $ignore = null, |
12 | | - string $lang = 'default', |
| 11 | + string $lang, |
| 12 | + array $ignore = [], |
13 | 13 | bool $dryrun = false, |
14 | 14 | ): void { |
15 | 15 | foreach ($collection as $item) { |
|
25 | 25 |
|
26 | 26 | // get the keys and normalize to lowercase |
27 | 27 | $originalContentKeys = array_keys($contentFields); |
28 | | - $contentFieldKeys = array_map('mb_strtolower', $originalContentKeys); |
| 28 | + $contentFieldKeys = array_map('mb_strtolower', $originalContentKeys); |
29 | 29 |
|
30 | 30 | // get all field keys from blueprint and normalize to lowercase |
31 | | - $blueprintFields = array_keys($item->blueprint()->fields()); |
| 31 | + $blueprintFields = array_keys($item->blueprint()->fields()); |
32 | 32 | $blueprintFieldKeys = array_map('mb_strtolower', $blueprintFields); |
33 | 33 |
|
34 | 34 | // get all field keys that are in $contentFieldKeys but not in $blueprintFieldKeys |
|
53 | 53 | } |
54 | 54 |
|
55 | 55 | // don't update models that have changes |
56 | | - if ($item->version('changes')->exists() === true) { |
| 56 | + if ($item->version('changes')->exists($lang) === true) { |
57 | 57 | $cli->error('The ' . $item::CLASS_ALIAS . ' (' . $item->id() . ') has changes and cannot be cleaned. Save the changes and try again.'); |
58 | 58 | } |
59 | 59 |
|
|
68 | 68 | // check if the version exists for the given language |
69 | 69 | // and try to update the page with the data |
70 | 70 | if ($version->exists($lang) === true) { |
71 | | - $version->update($data); |
| 71 | + $version->update($data, $lang); |
72 | 72 | } |
73 | 73 | } |
74 | 74 | }; |
|
101 | 101 | // should call kirby models for each loop |
102 | 102 | // since generators cannot be cloned |
103 | 103 | // otherwise run into an exception |
104 | | - $collection = $kirby->models(); |
105 | | - |
106 | | - $cleanContent($cli, $collection, $ignore, $language->code(), $dryrun); |
| 104 | + $cleanContent( |
| 105 | + cli: $cli, |
| 106 | + collection: $kirby->models(), |
| 107 | + lang: $language->code(), |
| 108 | + ignore: $ignore, |
| 109 | + dryrun: $dryrun |
| 110 | + ); |
107 | 111 | } |
108 | 112 |
|
109 | 113 | $cli->success('The content files have been cleaned'); |
|
0 commit comments