cms icon indicating copy to clipboard operation
cms copied to clipboard

Updating a slug of a taxonomy creates a duplicate until Stache is cleared

Open duncanmcclean opened this issue 3 years ago • 2 comments
trafficstars

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

  1. Create a taxonomy term, call it Test one
  2. Edit the term, change the title & slug to Test two
  3. Go back to the taxonomies page in the CP, see that two terms are now displayed: Test one and Test two.
  4. Look at the taxonomies directory, find that a file exists for Test two but not Test one.
  5. Clear the Stache - via php artisan cache:clear
  6. 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

duncanmcclean avatar Mar 10 '22 09:03 duncanmcclean

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 🤔

duncanmcclean avatar Jun 23 '22 08:06 duncanmcclean

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 avatar Aug 04 '22 09:08 duncanmcclean

@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?

sunscreem avatar Dec 23 '22 14:12 sunscreem

@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.

sunscreem avatar Jan 14 '23 14:01 sunscreem

@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.

duncanmcclean avatar Jan 14 '23 14:01 duncanmcclean

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 avatar Jan 19 '23 12:01 mmodler

@mmodler Thanks for sharing. I'll implement this now :)

sunscreem avatar Jan 19 '23 12:01 sunscreem

Thanks for the workaround!

duncanmcclean avatar Jan 26 '23 08:01 duncanmcclean

Anyone knows if the issue still exists in 4.x?

mmodler avatar Sep 15 '23 09:09 mmodler