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

Reorganizing assets in CP don't update any paths (at all) #9701

Closed
axelferdinand opened this issue Mar 11, 2024 · 26 comments · Fixed by #9878
Closed

Reorganizing assets in CP don't update any paths (at all) #9701

axelferdinand opened this issue Mar 11, 2024 · 26 comments · Fixed by #9878

Comments

@axelferdinand
Copy link

Bug description

I just did a major restructuring within my Assets in CP, solely using the CP moving assets. According to the docs, paths to images are supposed to update, but (almost) all my assets are now unlinked in front-end..

I'm using the Assets fieldtype and Bard. I can share repo access, if wanted.

How to reproduce

(see above)

Logs

No logs

Environment

Environment
Application Name: NAC
Laravel Version: 10.47.0
PHP Version: 8.3.3
Composer Version: 2.5.5
Environment: local
Debug Mode: ENABLED
URL: nac.proto
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: postmark
Queue: sync
Session: file

Statamic
Addons: 3
Antlers: runtime
Sites: 3 (Norsk, English, Deutsch)
Stache Watcher: Disabled
Static Caching: Disabled
Version: 4.52.0 PRO

Statamic Addons
aryehraber/statamic-captcha: 1.10.0
doublethreedigital/duplicator: 4.0.1
mitydigital/sitemapamic: 2.3.9

Installation

Existing Laravel app

Antlers Parser

None

Additional details

No response

@theLeroy
Copy link
Contributor

@axelferdinand we are also running into very strange behaviour.. have you found a solution?

@axelferdinand
Copy link
Author

Hey @theLeroy Unfortunately, no. In my case, it's a multisite that I've ran for years, upgrading all the way from early v2 to latest version. Possibly that's the issue – I haven't tried this on a fresh install.

@arcs-
Copy link
Contributor

arcs- commented Mar 19, 2024

In our case the issue is that we've implemented a custom replicator that we called "components", however, we didn't realize that the replicator handle name was hard-coded and necessary for the update of asset paths to work. See line

return in_array($field->type(), ['replicator', 'grid', 'bard']);

The solution for us was to update this array with our custom name and an ugly fix to use the same replicator update function. A warning could be helpful (e.g. "unable to find update function for custom field-type "), although I think of this as an edge case.

@axelferdinand
Copy link
Author

@arcs- Is THAT the case?? So, if I name the replicator field something custom, it wont work?

image

@axelferdinand
Copy link
Author

So to fix this, I need to add my replicator name like this?

return in_array($field->type(), ['modules', 'replicator', 'grid', 'bard']);

@afonic
Copy link

afonic commented Mar 19, 2024

I think what @arcs- meant is that they implemented a custom replicator, meaning a custom fieldtype.

@axelferdinand
Copy link
Author

@afonic Ah, OK. I think I understand. My replicator is 100% Statamic, as far as I can see, and this should work out of the box?

@afonic
Copy link

afonic commented Mar 20, 2024

@axelferdinand, maybe you can replicate your setup in a fresh Statamic install and report here?

Generally this feature works for me.

@axelferdinand
Copy link
Author

@afonic To install my client's theme on a fresh install? I guess I will need to try that. Just wonder if it's my setup that has a problem.

@afonic
Copy link

afonic commented Mar 20, 2024

If you can recreate your replicator setup in a fresh install and it still doesn't work then it's probably a bug and the core team will get to it. If it works fine, then it's probably something wrong with your setup.

There have been quite a few changes in the blueprints' yaml files and if the site is really old it sometimes messed up things.

I'd also try to open the blueprint in question and save it again in the control panel.

@axelferdinand
Copy link
Author

Thanks for the tip with saving the blueprint again – as you said, a lot restructured on save. But unfortunately, when trying to relocate assets, only the asset meta files updates – and none of the md-files with the paths.

@theLeroy
Copy link
Contributor

Maby the fact that i don't works with custom Fieldtypes should be mentioned in the documentation. Or the Recursive function should be updated.

@duncanmcclean
Copy link
Member

Apologies for jumping in a bit late to this discussion.

I've uploaded some assets into my sandbox site, added them to various entries (both in Bard sets & Asset fields in the "root" of entries). Then, when I renamed them or moved them into different folders, I can see that the paths are being updated as expected. 🤔

@axelferdinand @theLeroy I have a couple of questions for you both...

  • Were you renaming / moving the assets locally or on a server? Do you have queue workers configured for either of these environments?
    • You can tell by checking your .env to see if QUEUE_CONNECTION is set to anything other than sync.
    • If you are using a queue worker, was that queue worker actually running when you reorganised the assets?
  • Where are your assets stored?
    • Locally or in a remote filesystem, like S3 or DO Spaces?

If either of you are able to reproduce the issue in a fresh Statamic site or share access to the code, that might be helpful in us getting to the bottom of the issue. Thanks.

@duncanmcclean
Copy link
Member

duncanmcclean commented Mar 26, 2024

In fact... I've just tested this in a larger project and I can reproduce it there.

I'm using a queue worker and UpdateAssetReferences job failed due to this error: foreach() argument must be of type array|object, string given.

I wonder if that's the same error either of you were running into... can you see that error at all in your logs?

@JorisOrangeStudio
Copy link

JorisOrangeStudio commented Mar 27, 2024

  • Were you renaming / moving the assets locally or on a server? Do you have queue workers configured for either of these environments?

    • You can tell by checking your .env to see if QUEUE_CONNECTION is set to anything other than sync.
    • If you are using a queue worker, was that queue worker actually running when you reorganised the assets?
  • Where are your assets stored?

    • Locally or in a remote filesystem, like S3 or DO Spaces?

I'm experiencing the same issue on different installs with Multi-site enabled. My assets are configured in DO Spaces filesystem and not updating the references on renaming/moving within the CP. I have tested it on multiple ways, looks like it is working fine on 'first level' fields, but once it is inside a Replicator field it doesn't update the references. Queue worker is set to Redis (with database queue it also doesn't update) and outputting the following after changing asset that is linked inside a replicator field:

  2024-03-27 12:56:47 Statamic\Listeners\UpdateAssetReferences ....... 2s DONE
  2024-03-27 12:56:45 Statamic\Listeners\UpdateAssetReferences ....... RUNNING

Maybe this helps a bit in debugging. Already experiencing this issue for 1 or 2 months, or even longer. Thought it was something in my own installs, but then I found this issue :)

addition: I'm also using Glide & a Glide Redis cache, I'm not sure if that can also impact this.

@axelferdinand
Copy link
Author

axelferdinand commented Mar 27, 2024

@duncanmcclean Thanks for looking into this!!

Were you renaming / moving the assets locally or on a server?
Locally.

Do you have queue workers configured for either of these environments?
QUEUE_CONNECTION=sync

Where are your assets stored?
Locally, nothing fancy.

Logs
Nothing is logged, what so ever.

@duncanmcclean
Copy link
Member

duncanmcclean commented Mar 27, 2024

Sounds like the issue I ran into (& PR'd a fix for) is different to the one your facing.

Is anyone able to reproduce this on a fresh site OR share their site with us for testing? That would make it much easier for us to find the cause issue.

@axelferdinand
Copy link
Author

Just shared repo access with you, Duncan :)

@duncanmcclean
Copy link
Member

Just shared repo access with you, Duncan :)

Thanks!

@duncanmcclean
Copy link
Member

duncanmcclean commented Mar 28, 2024

@axelferdinand Thanks for providing the repository!

I've managed to figure out why Statamic wasn't updating any references. The update_references option in your config/statamic/system.php config file was set to false.

It should be set to true if you want references to be updated when renaming/moving assets or taxonomy terms.

https://github.com/statamic/cms/blob/4.x/config/system.php#L142-L153

As far as I can tell, the config option has defaulted to true since it was introduced in August 2022 (#6504).

Once you enable it and try to rename or move an asset, you might run into the error I noticed the other day (foreach() argument must be of type array|object, string given.). I've opened a PR to fix it (#9790), which seems to fix it in my testing - hopefully it should be reviewed soonish.

I'll leave this issue to be closed when that PR is merged.

@JorisOrangeStudio
Copy link

@duncanmcclean I have update_references set to true and assets are still not updating its references after renaming/moving.

@duncanmcclean
Copy link
Member

I have update_references set to true and assets are still not updating its references after renaming/moving.

Are you able to share your repository or reproduce the same issue on a fresh site?

@JorisOrangeStudio
Copy link

Yes, but I can share it probably after the weekend. I will have to make a fresh site with our default setup and see if it is also happening there.

@axelferdinand
Copy link
Author

After updating, I still get the following error when reorganizing assets:

image

@axelferdinand
Copy link
Author

...on first attempt, this error:
image

@duncanmcclean
Copy link
Member

We haven't tagged a release with the fix yet. The fix will be part of the next release.

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