Copying txt files in a code editor and UUIDs

I’m new to Kirby and just discovered the UUID stuff.
Now I’m wondering if I will run into problems if I copy the txt file from one page via a code editor to another page and edit some fields. The copy will initially have the same UUID. Will that get magically changed somehow or do I need to manually generate a new UUID for the file?

No, if there is a UUID, Kirby will not generate a new one (so that manual UUIDs work as well). So you have to change this manually/programmatically.

You can use the Kirby CLI to remove / regenerate UUIDs accross the site, Just be careful in places where you have refered to a UUID in your code or fields as this will likely need to updated afterwards.

That’s not quite true. For all I know, the generate command only creates missing UUIDs, so existing UUIDs are not messed with.

My understanding is you can use the remove command to get rid of them globally and then use the generate command will put them even in content files that didnt have one. So you need to do the remove first and then generate.

I will point out again that its a destructive command that can cause bits of your site to break until up update references to the new UUIDs in your code. Just go careful :slight_smile:

Thanks for the clarification.

So to manually generate a new UUID for a file that I had copied I just need to delete the UUID line in the file and run the CLI command?

Is there a way to generate a UUID for a particular file?

I would not recommend that, at least not for existing installations with relations. Just generate without removing will only create the missing ones.

‘description’ => ‘Creates all missing UUIDs’,

1 Like

You can maniually write your own UUID in there. The CLI way is a bit of a bulldozer.

Quite frankly this is all a little confusing and I think it would be a good idea to clarify this in the documentation. The Guide doesn’t properly cover this.

I don’t feel safe just editing some characters in the UUID field. It should be generated via the same algorithm that is used by Kirby. So a CLI command to work on a particular file would be a solution.

UUIDs are basically meant to be an automatic process, they are generated automatically when you create a new page in the Panel. When doing stuff manually, that’s another story and you can either generate them then via the CLI or programmatically, or, just add something manually.

You can update a page or file with a new UUID, example for page (command needs authentication):

$page->update(['Uuid' => Uuid::generate()]);

OK, so for manually copying a txt file in a code editor, I should best delete the UUID field in the copied file and then Kirby will automatically generate a new UUID when it’s first accessed, right?

in the Panel, yes.

Perfect. Thanks!

If you use the the Panel to duplicate the page rather then doing it manually in the filesystem, Kirby will generate a new UUID for you in the duplicated page.

Understood.
The problem is that as a newbie you can easily get the impression from watching the video tutorials and skimming through the docs that you can happily switch between doing things in a code editor or via the panel and it doesn’t make a difference. This is true but the UUID stuff seems to be an exception.

Therefore I think it really would be a good idea to highlight this.

I updated the UUID guide, hope that makes it clearer.

Wow, that was quick!
Are the changes already online?

They are now, forgot to push.

Yep, that blue box clarifies it.
Thank you!