Using the $file->copy(...) function don't always relink file-uuids in the content fields of the copied page

Hello,

I have implemented a method which is using the $page->copy.

The code calling the copy method is

$newPage = $originalPage->copy([
    'slug' => $data['newSlug'],
    'parent' => $parent,
    'isDraft' => true,
    'files' => true
]);

so I always try to copy the files too.

For some folders all copies work as expected, that the files are getting new uuids and every appearance in the content-fields (blocks, selected-file-lists, etc.) of the copied file is replaced, so that the files link to their copied version.
However, in another folder this isn’t the case. The code copies the files over, but in the content fields of the page all files are linked to the original-page file instead of the files in the copied one (again in blocks, selected-file-lists, coverimage, etc.).

Are there any restrictions i am missing, that would explain such behaviour?
I tried to read a bit of the native kirby code but did not find the part where files get relinked, only where they get their new uuids.

Kirby Version is 4.3.1

Thanks for any hints to clearify the behaviour.

1 Like

Could this be related to one of these?

Yes, this might be related to those issues.
The only thing i don’t understand: I thought, sometimes it worked es expected: that the uuids were replaced. But i can’t reproduce it at the moment. So it might, that I have missed something and they never got replaced.

However, I was able to create a code snippet that will do the work in my case. It basically does partially what you suggested in Duplicating pages does regenerate file UUIDs, but does not update content file with new UUIDs · Issue #4867 · getkirby/kirby · GitHub (creating a map, and replace occurrences in the copied content file. It is the only relevant step for me and I don’t have a multilanguage setup. So I don’t have to deal with multiple content files in the copied page. That made it relatively simple)

Thank you for your reply :slight_smile: