Skip to content

[4.x]: Assets are moved when using {site.handle} in Asset Location #12767

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

Closed
tommysvr opened this issue Mar 2, 2023 · 4 comments
Closed

[4.x]: Assets are moved when using {site.handle} in Asset Location #12767

tommysvr opened this issue Mar 2, 2023 · 4 comments
Assignees

Comments

@tommysvr
Copy link

tommysvr commented Mar 2, 2023

What happened?

Description

Assets are being saved to the wrong folder when uploading to a field with 'Restrict assets to a single location' and {site.handle} inside the Asset Location. Able to reproduce on 3.7.67 and 4.3.10.

Steps to reproduce

  1. On a multisite install with Site A and Site B
  2. Add an Assets field with 'Restrict assets to a single location' checked and the Asset Location {site.handle}
  3. On a new Entry in Site A, upload an image -> save Entry
  4. Asset will be saved to the siteB folder
  5. Switch to Site B, upload another asset
  6. All assets will be moved to siteA folder

Expected behavior

Assets will be saved to the folder corresponding to the site being edited.

Actual behavior

All Assets are moved after saving an Entry.

Here are Composer files and a database dump from a fresh install with the above setup to hopefully help quickly reproduce: composer-db.zip

Craft CMS version

4.3.10 and 3.7.67

PHP version

8.0

Operating system and version

No response

Database type and version

MariaDB 10.4

Image driver and version

No response

Installed plugins and versions

@brandonkelly
Copy link
Member

@i-just We probably should not be moving assets if $element->propagating from Assets::afterElementSave().

@jlawrence-yellostudio
Copy link

@brandonkelly We've been experiencing this on a project we upgraded to craft 4, the majority of our asset fields have {site.handle} as an asset location. The behaviour we are seeing is that for site shared elements often the asset gets 'moved' to the last site in the sites query, which typically is the last site when grouped by the site group (in alphabetical order) same as it is displayed in the sites area of the control panel.

The original motivation behind using {site.handle} in the asset location was to try to prevent people using different sites from seeing the assets from the other sites.

When I say shared elements i mean those that retain the same element ID across multiple sites, e.g. categories, singles, or any entry that is propagated to all sites.

Am i right in assuming that in this scenario (where the same element ID is retained across multiple sites), that the use of {site.handle} in the upload / folder location of the field settings is incompatible because the asset volume folders are not multi site, and the asset itself can only have one folderId?

@brandonkelly
Copy link
Member

Am i right in assuming that in this scenario (where the same element ID is retained across multiple sites), that the use of {site.handle} in the upload / folder location of the field settings is incompatible because the asset volume folders are not multi site, and the asset itself can only have one folderId?

@jlawrence-yellostudio Correct

@brandonkelly
Copy link
Member

Craft 4.14.12 and 5.6.14 are out with a fix for this: assets are no longer relocated for propagated sites. (#16938)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants