Skip to content

Commit 10984b6

Browse files
committed
fix: Apply code review #94
1 parent b272dc8 commit 10984b6

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

commands/clean/content.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
// get the keys and normalize to lowercase
2424
$originalContentKeys = array_keys($contentFields);
2525
$contentFieldKeys = array_map('strtolower', $originalContentKeys);
26+
$contentFieldKeys = array_map('mb_strtolower', $originalContentKeys);
2627

2728
// get all field keys from blueprint and normalize to lowercase
2829
$blueprintFields = array_keys($item->blueprint()->fields());
29-
$blueprintFieldKeys = array_map('strtolower', $blueprintFields);
30+
$blueprintFieldKeys = array_map('mb_strtolower', $blueprintFields);
3031

3132
// get all field keys that are in $contentFieldKeys but not in $blueprintFieldKeys
3233
$fieldsToBeDeleted = array_diff($contentFieldKeys, $blueprintFieldKeys);
@@ -36,16 +37,15 @@
3637
// create a mapping: lowercase => original field name
3738
$lowercaseToOriginal = array_combine($contentFieldKeys, $originalContentKeys);
3839

39-
// flip keys and values and set new values to null
40-
$data = array_map(
41-
fn ($field) => null,
42-
array_flip(array_intersect_key($lowercaseToOriginal, array_flip($fieldsToBeDeleted)))
43-
);
40+
// build data array with original field names as keys and null as values
41+
$data = [];
42+
foreach ($fieldsToBeDeleted as $lowercaseField) {
43+
$originalField = $lowercaseToOriginal[$lowercaseField];
44+
$data[$originalField] = null;
45+
}
4446

4547
// try to update the page with the data
46-
if (count($data) > 0) {
47-
$item->update($data, $lang);
48-
}
48+
$item->update($data, $lang);
4949
}
5050
}
5151
};

0 commit comments

Comments
 (0)