Migration Autoid to Kirby UUIDs

If anybody wants to migrate from kirby-autoid to native UUIDs this worked quite well for me.

<?php

return [
    'description' => 'Autoid>uuid bruteforce replacer',
    'args' => [],
    'command' => static function ($cli): void {
        $index = site()->index();
        $replacements = 0;
        foreach($index as $autoidPage) {
            if($autoidPage->autoid()->isNotEmpty()) {

                $autoid = $autoidPage->autoid()->value();

                foreach($index->not($autoidPage) as $page) {
                    $str=file_get_contents($page->contentFile());

                    if(str_contains($str, $autoid)) {

                        $replaced = str_replace($autoid, $autoidPage->uuid()->toString(), $str);
                        file_put_contents($page->contentFile(), $replaced);
                        $replacements++;
                    }
                }
            }
        }
        $cli->success($replacements . ' Autoids found and replaced!');
    }
];

It is in form of Kirby cli plugin but you can run it as you require. It only replaces PAGE AUTOIDs. Watch out as native Kirby UUIDs don’t suport structure fields yet.

1 Like