Greakz
September 2, 2024, 9:34am
1
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?
opened 10:32AM - 14 Nov 22 UTC
needs: discussion 🗣
type: bug 🐛
(I've already written a bit about this in a different bug #4831, posting here fo… r visibility)
## Description
While duplicating a page, setting 'copy files?' to false used to generate a new page with only text content and no images. Now, it still copies the file-UUIDs from the original content file, and keeps the connection to the images from the original page.
This can be confusing for the user, because it is not obvious where those images are coming from.
I think that's bad UX:
Some clients might keep using these images, then at some point delete the original page and will be suprised that all the images are gone.
**Expected behavior**
Duplicating a page without files should remove links to file UUIDs not belonging to the new page.
I realise this is more complicated now with UUIDs.
With Kirby <= 3.7, the content.txt was simply copied, and no images, pointing to an image that didn't exist anymore in that folder:
```
Cover: - monster-trees-in-the-fog.jpg
```
The panel handled that invalid link nicely by just not showing any image.
Now with UUIDs, the panel still can find that image from the original page and displays it.
Just an idea: Since the file links have a very distinctive pattern, wouldn't it be possible to use regex
(maybe `file:\/\/[\w]{16}`) to invalidate file links during duplication?
```
Cover: - file://soTV5M2PG5DJfuHw
```
becomes
```
Cover: - file://
```
Or is that replacement operation too risky?
I would just be nice to be able to use file UUIDs while still having the old, more natural duplication behaviour:
When duplication without images -> no images on new, duplicated page.
## To reproduce
- Create a page with images
- Duplicate that page, "copy files?" -> no
- The panel still shows linked images
## Your setup
**Kirby Version**
3.8.1.1
opened 11:35PM - 26 Nov 22 UTC
type: bug 🐛
## Description
Related to #4831.
Duplicating pages with files now regenerates… file UUIDs, but the files linked in the content.txt still point towards the original page (the duplication source).
**Expected behavior**
Duplicated files should be linked correctly in the content.txt.
## To reproduce
1. Create a page with images, with UUIDs active
2. Duplicate that page, with files
3. File UUIDs get regenerated, but linked are still the parent files, not the newly generated ones.
## Your setup
**Kirby Version**
3.8.2
**Additional context**
See also dicussion here #4844
Greakz
September 9, 2024, 7:38am
3
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