I have a problem where metatags are generated for a draft and when the draft is published the metatags for the published content are not refreshed and show draft data until the cache is next cleared.

This is my problem in more detail:

  1. An existing node has correct meta tags.
  2. Edit an existing node and save in draft state and I end up on the draft page where the metatags are for the draft.
  3. I refresh the published node view page now and it still ahs the correct metatag values.
  4. I publish the new draft and end up on the published node view page viewing the new version. Now the metatags are wrong, they are still the metatags from step 2. For example the canonical link is http://example.com/node/294/draft
  5. I refresh the node view page and the metatags are still wrong.
  6. I clear the cache and the metatags are correct again.

#2199533: Token replacement not updating for workbench drafts seemed like a similar issue but I don't fully understand the explanation of that problem and the patch didn't fix my issue.

Also I'm not sure if the component of this issue is correct or not as I'm not sure what the root of the problem is.

I'm using Workbench 7.x-1.2 and Workbench moderation 7.x-1.4.

CommentFileSizeAuthor
#10 metatag-n2467587-10.patch625 bytesdamienmckenna

Comments

damienmckenna’s picture

Title: Problem with workbench moderation and metatags caching » Problem with Workbench Moderation and Metatag caching
Issue tags: +Workbench Moderation

Odd. I wonder would #2420489: Restructure entity caching so it can be cleared more easily help?

Clearly, though, it needs to hook into WM and clear the cache on a state change.

damienmckenna’s picture

Just to confirm it - what version of Workbench Moderation are you using?

damienmckenna’s picture

rooby’s picture

Issue summary: View changes

Your proposed solution in #1 sounds like it would work.

I'm using Workbench 7.x-1.2 and Workbench moderation 7.x-1.4.

justindodge’s picture

Hey guys, here's a solution as a custom module hook - a temporary workaround for me that takes the approach
of #1.
I could easily roll this into a patch for Metatag, but I wonder if anyone has any input regarding the
cache key being used to wipe cache entries - I'm not intimately familiar with all of the components
of the cid used in cache_metatag. This code seems appropriate to me, but maybe there's a way some keys
are built that makes this either too heavy handed or perhaps misses a scenario.

/**
 * Implements hook_workbench_moderation_transition
 */
function custom_workbench_moderation_transition($node, $previous_state, $new_state) {
  // Clear metatag cache for nodes on any state change (see https://www.drupal.org/node/2467587)
  db_query("DELETE FROM {cache_metatag} WHERE cid LIKE :cid", array(':cid' => 'output:node:' . $node-
>nid . '%'));
}
damienmckenna’s picture

You should use:

metatag_metatags_cache_clear($entity_type, $entity_id);
rooby’s picture

Does that output cache issue you just committed help this or is that different?

damienmckenna’s picture

The other cache thingy is something else, though disabling the output cache would cover up this issue.

damienmckenna’s picture

Not going to do this for 1.5.

damienmckenna’s picture

Status: Active » Needs review
StatusFileSize
new625 bytes

Does this fix the problem?

damienmckenna’s picture

beeradb’s picture

This patch was posted during the time I wrote a nearly identical version. Interesting timing :)

I applied and tested this patch to a 1.4 installation of metatag and it works as intended.

damienmckenna’s picture

Status: Needs review » Fixed

@beeradb: Thanks for the review!

Committed.

  • DamienMcKenna committed dcf028b on 7.x-1.x
    Issue #2467587 by DamienMcKenna: Clear the Metatag cache when a node's...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.