Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

“Copy Files” toggle is ignored when duplicating a page #6885

Closed
linusrogge opened this issue Dec 26, 2024 · 4 comments
Closed

“Copy Files” toggle is ignored when duplicating a page #6885

linusrogge opened this issue Dec 26, 2024 · 4 comments
Labels
needs: information ❓ Requires more information to proceed needs: replication 🔬 Requires a sample to reproduce the issue

Comments

@linusrogge
Copy link

Description

When duplicating a page with images, I have to option to set a toggle whether to copy these files or not. But no matter what option it is set to, the files are always copied.

Expected behavior
When the toggle is set to false, no files should appear in the duplicated page.

This looks like the problem. Shouldn’t it be if ($files !== false) { …?

// don't copy files
if ($files === false) {
foreach ($this->files() as $file) {
$ignore[] = $file->root();
// append all content files
array_push($ignore, ...$file->storage()->contentFiles('published'));
array_push($ignore, ...$file->storage()->contentFiles('changes'));
}
}

To reproduce

  1. Create a page and upload an image
  2. Click on “Duplicate” and leave “Copy Files” toggle on false
  3. Click duplicate
  4. See copied files

Your setup

Kirby Version
4.5.0 (but has been around before)

Your system (please complete the following information)

  • Device: MacBook Pro
  • OS: macOS Sequoia, Version 15.2 (24C101)
  • Browser: Chrome
@afbora
Copy link
Member

afbora commented Jan 6, 2025

Hello @linusrogge I've tried on starterkit 4.5.0 and it's working great. Do you have plugins?

Also I just wonder that copy and don't copy actions works for you with $files !== false condition?

@afbora afbora added needs: information ❓ Requires more information to proceed needs: replication 🔬 Requires a sample to reproduce the issue labels Jan 6, 2025
@linusrogge
Copy link
Author

linusrogge commented Jan 17, 2025

So, I have done a bit of testing and things are weirder than I thought.

I tested around with the Starterkit as well and it does work mostly correctly there indeed—however, and this is what I also discovered on my sites: Kirby, when the toggle is set to false, does not copy the files. But in the txt file of the duplicated page, the UUID from the file from the original page is still included. Can you follow me?

Example

  1. I duplicate the “Mountains” album in the Starterkit
  2. I leave the “Copy files” toggle on “off”
  3. I click “Duplicate”
  4. The duplicate opens, and in the “Cover” field, there is still an image visible
Image

However, when I click it, it opens the file from the original page (notice the breadcrumbs at the top: Image above is “Mountains Copy”, image below just says “Mountains” which is the original)

Image

And also in the _drafts/mountains-copy/album.txt file, there is already a value set for “Cover” although I haven’t done anything other than duplicate the page:

Image

Then again: the _drafts/moutains-copy folder is empty (except for the .txt file) and, as to no surprise, when I open the probably-photoshopped.jpg.txt from the original page, it has the UUID that is also linked in the duplicated page.

Now, when I click the “Select” button in the “Cover” field, the dialog is empty

Image

In conclusion: there’s something off with the duplicate logic which does not actually copy the files, but simply persists the value of the field in the newly created .txt file, wrongly showing the image from the original page in its duplicate.

I hope this makes sense, otherwise I am happy to record a loom going through the whole process to showcase it better.

@distantnative
Copy link
Member

This behavior will be changed with Kirby 5 (already present in the beta): #6567

With Kirby 4, duplicating a page would keep all UUID references as they are. So no matter if duplicating files or not, the old UUID references would always point to the files of the old page.

With Kirby 5, we will differentiate between UUID references to files within the page and outside of the page. Those to files outside of the page will always stay the same when duplicating a page. But those to files form within the page (or subpages) will be treated differently: when duplicating files as well, we will replace the UUID references to the files within the old page with those new duplicated files within the new page. When not copying over the files, we will delete any UUID referencing one of those files that didn't get copied.

I think this will solve your expected outcome.

@linusrogge
Copy link
Author

Glad to hear this will be part of Kirby 5. While trying this behaviour using beta-1, I had a different issue where leaving the toggle set to false would not let me duplicate the page at all:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: information ❓ Requires more information to proceed needs: replication 🔬 Requires a sample to reproduce the issue
Development

No branches or pull requests

3 participants