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

[4.x]: Adding new site to a multi site setup gets links and assets messed up. #16936

Closed
pnpaes opened this issue Mar 21, 2025 · 8 comments
Closed
Assignees

Comments

@pnpaes
Copy link

pnpaes commented Mar 21, 2025

What happened?

Description

I have a multi site installation with 6-7 web sites.
I have a rule in my folders that assets that each website can only select assets from their own folders, and that is setup using the site handle. It works fine and the assets upload and selection are properly set to each folder based on the website the user is editing.
When I need to enabled a new site things get all messed up. Since in theory the new site can't access the images from the original site some of them seem to be moved (not cloned) into a folder with the new website handle.
That means that the assets are moved and the original website misses a lot of its images/assets.
Another isse is with links. Some links get broken when duplicating the website and they still get related to the entries int he original website instead of the cloned website (like some links in navigation).
So there is a lot of manual work to fix this every time I need to enable a new website.

Steps to reproduce

  1. Go to settings -> sites
  2. Add a new site
  3. Go to setting -> sections
  4. Enable section in the new website

Expected behavior

I would expect that all links that were created by selecting an entry in the original website, would get changed to the entry in the duplicated site. Either assets would be cloned into the new folder and connections updated (dream scenario) or they would still only in the original folder and wouldn't break the original website. Although th

Actual behavior

As described previously, assets get moved and then losing reference in the original website.
Links are not updated and are linked to the original website.

Craft CMS version

4.14.11

PHP version

8.3.4

Operating system and version

Linux 5.15.0-125-generic

Database type and version

MySQL 8.0.41

Image driver and version

GD 8.3.4

Installed plugins and versions

Plugins
CKEditor 3.11.1
Colour Swatches 4.5.3
Control Panel Nav 4.0.12
Cookie Manager 1.0.11
Cookies 4.0.1
DigitalOcean Spaces Filesystem 2.0.0
Feed Me 5.11.0
Field Manager 3.0.9
Image Resizer 3.0.13
Neo 4.4.1
Redactor 3.1.0
SEOMate 2.3.1
Super Table 3.0.15

@i-just
Copy link
Contributor

i-just commented Mar 21, 2025

Hi, thanks for getting in touch!

I have a rule in my folders that assets that each website can only select assets from their own folders, and that is setup using the site handle. It works fine and the assets upload and selection are properly set to each folder based on the website the user is editing.

Can you please share the details of that setup or send your composer.json, composer.lock and database backup to [email protected] so we can try to replicate and dig deeper?

@pnpaes
Copy link
Author

pnpaes commented Mar 21, 2025

Will do. And I assume you mean [email protected] ;)

@i-just
Copy link
Contributor

i-just commented Mar 21, 2025

Oops, yes!

@i-just
Copy link
Contributor

i-just commented Mar 21, 2025

Thanks again for the files!

In terms of Assets, this sounds like a duplicate of #12767. I raised a new PR for that original issue, so when you enable, e.g. an entry for a new site, the asset won’t get relocated if “Manage relations on a per-site basis” is off.

That said, if you create an entry for siteA and add an asset to an Assets field like yours (with the “restrict assets to a single location” turned on and asset location set to {site.handle}), the asset will get saved in the siteA folder. If you then edit the same entry in site siteB and save, the asset will be relocated to the siteB folder, and this is expected behaviour (additional explanation can be found here).

Another isse is with links. Some links get broken when duplicating the website and they still get related to the entries int he original website instead of the cloned website (like some links in navigation).

Let’s say I added a new site to your installation (handle: test1). After that, I enabled Pages Structure for test1 site, then enabled the Pensjon entry for test1 site and then enabled the “Globals” Single for that site; once the background jobs are complete, if I go to that single for the primary site, the Header Navigation > Menu Item with Submenu > Entries > Fist Link > Internal Link, the navigation will link to the Pensjon entry on the primary site, and when I go to it for the test1 site, it’ll link to the Pensjon for the test1 site. Is this what you’re seeing too? Or have I missed the point on that part?

@i-just i-just self-assigned this Mar 21, 2025
@pnpaes
Copy link
Author

pnpaes commented Mar 24, 2025

Thanks for the feedback.
Regarding images, isn't that weird that they get moved? Because the concern was that it doesn't get the reference updated in the original website and the assets go missing!
For example, i have un uploaded PDF that is on siteA. I clone and create siteB. assets moves from folder /siteA to /siteB but the site A still tries to find the assets on /siteA and ends up without any asset displaying.

As for links, some of my cloning didn't get links from /siteA/entry to /siteB/entry. So I have to manually update the navigation all over again.

@pnpaes
Copy link
Author

pnpaes commented Mar 24, 2025

Another side note.
Most of my content is added inside a NEO matrix field with the propagation method "Only save blocks to the site they were created in". Should I instead change to create in all sites the owner element is saved in? Since my content is unique per site, just cloned when a new site is added but then managed independently, what would be the suggested propagation method?

@brandonkelly
Copy link
Member

Regarding images, isn't that weird that they get moved?

They won’t going forward, thanks to #16938 (assuming your Assets field’s “Manage relations on a per-site basis” setting is disabled).

Because the concern was that it doesn't get the reference updated in the original website and the assets go missing!
For example, i have un uploaded PDF that is on siteA. I clone and create siteB. assets moves from folder /siteA to /siteB but the site A still tries to find the assets on /siteA and ends up without any asset displaying.

Not really following you here. What is your volume’s Base URL set to?

As for links, some of my cloning didn't get links from /siteA/entry to /siteB/entry. So I have to manually update the navigation all over again.

And these are for actual entry selections, right? Are the linked entries in the same section as the Link field, or in a section which was enabled for the new site before the initial queue job was done processing?

@brandonkelly
Copy link
Member

Craft 4.14.12 and 5.6.14 are out with that fix from #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

3 participants