Created
September 16, 2023 06:45
-
-
Save bnomei/bf4eef840b7063eac30e36475858aadf to your computer and use it in GitHub Desktop.
Kirby CMS Command to Find duplicate Uuids
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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