cms
cms copied to clipboard
Updating a slug of a taxonomy creates a duplicate until Stache is cleared
Bug description
A client's just reported an issue where a taxonomy is duplicated whenever you change its slug. You end up with a version with the old slug & another with the new slug (the markdown file is named with the new slug). If you clear the Stache, only the new version of the term is found.
Related: #1148
How to reproduce
- Create a taxonomy term, call it
Test one - Edit the term, change the title & slug to
Test two - Go back to the taxonomies page in the CP, see that two terms are now displayed:
Test oneandTest two. - Look at the taxonomies directory, find that a file exists for
Test twobut notTest one. - Clear the Stache - via
php artisan cache:clear - Go back to the taxonomies page in the CP, see that only one of the two terms is displayed:
Test two
Logs
No response
Versions
Statamic 3.2.31 Pro Laravel 8.80.0 PHP 8.0.15 doublethreedigital/static-cache-manager 1.1.1 rias/statamic-redirect 1.10.3 statamic/migrator dev-master withcandour/aardvark-seo 2.0.21
Installation
Other (please explain)
Additional details
Upgraded from Statamic v2
I've just done some digging on this.
Weirdly with a fresh Statamic 3.3 site, I can't reproduce this issue. However, I can if I upgrade the site in question to 3.3, here's the support:details output for that site:
Statamic 3.3.16 Pro
Laravel 8.83.5
PHP 8.1.5
doublethreedigital/static-cache-manager 1.2.1
rias/statamic-redirect 1.10.3
steadfastcollective/statamic-csv-exporter 1.0.1
withcandour/aardvark-seo 2.0.22
Tried a couple of things with @ryanmitchell (when the site as still on 3.2), and managed to get half way there with a fix (see commit).
It would work the first time but if you change the slug again, the problem would reoccur. Also, if you have it set to "Continue Editing" upon save, you wouldn't be redirected to the edit page with the updated slug.
Anyways, I don't want to spend too much time on this but thought I'd share what I've tried. Not quite sure what the cause could be 🤔
Sorry to be one of those people - but is there any chance this could be looked into at some point?
I have a feeling it could be due to the fact we have references to the term elsewhere (which I didn't have in a fresh site when I last tried)
@duncanmcclean Thanks for flagging my issue as a duplicate.
I can confirm that when the stache watcher is set to false, the issue stache isn't getting cleared when changing a taxonomy term slug. I'm guessing an event maybe isn't getting triggered?
@duncanmcclean Sorry to be a pain. Client was asking me if this one is likely to get looked at soon? No problem if not, we'll just need to let a few staff members know how to clear the stache.
@duncanmcclean Sorry to be a pain. Client was asking me if this one is likely to get looked at soon? No problem if not, we'll just need to let a few staff members know how to clear the stache.
I'm not sure - I've looked previously and didn't manage to figure it out. I'm not on the Statamic Team so not sure where it is on their priority list to look at.
I also experienced this issue when working with terms during the same request. The terms queries are returning the old content before my updates.
I have many terms operations within a single request, so my workaround is a TermSaved listener. Not very smart, but working.
class FixTermsStore
{
/**
* Fix terms store
*
* @param TermSaved $event
*/
public function handle(TermSaved $event): void
{
Stache::store('terms')->store($event->term->taxonomyHandle())->clear();
}
}
@mmodler Thanks for sharing. I'll implement this now :)
Thanks for the workaround!
Anyone knows if the issue still exists in 4.x?