Skip to content

Instantly share code, notes, and snippets.

@bnomei
Created September 16, 2023 06:45
Show Gist options
  • Save bnomei/bf4eef840b7063eac30e36475858aadf to your computer and use it in GitHub Desktop.
Save bnomei/bf4eef840b7063eac30e36475858aadf to your computer and use it in GitHub Desktop.
Kirby CMS Command to Find duplicate Uuids
<?php
use Kirby\CLI\CLI;
use Kirby\Cms\Page;
return [
'description' => 'Find duplicate Uuids',
'args' => [],
'command' => static function (CLI $cli): void {
// 1) find uuids and their pages
$uniqueids = [];
foreach (site()->index(true) as $page) {
/* @var Page $page */
$uniqueids[$page->uuid()->id()][] = $page->contentFiles()[0];
}
// 2) foreach uuid that has more than one page
$duplicates = array_filter($uniqueids, function ($pages) {
return count($pages) > 1;
});
foreach ($duplicates as $uuid => $pages) {
$cli->error($uuid);
foreach ($pages as $page) {
$cli->out('↳ ' . $page);
}
}
$result = [
'status' => 200,
'uuids' => count($uniqueids),
'duplicates' => count($duplicates),
];
$cli->success(print_r($result, true));
janitor()->data($cli->arg('command'), $result);
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment