diff --git a/sites/all/modules/contrib/cps/cps.module b/sites/all/modules/contrib/cps/cps.module --- a/sites/all/modules/contrib/cps/cps.module +++ b/sites/all/modules/contrib/cps/cps.module @@ -800,8 +800,9 @@ function cps_entity_property_info() { * Implements hook_entitycache_pre_cache_get_alter(). */ function cps_entitycache_pre_cache_get_alter(&$ids, &$conditions, $entity_type) { - if (cps_get_current_changeset() !== CPS_PUBLISHED_CHANGESET) { - // If we are in a changeset, do not let entitycache load things from cache. + if (cps_disable_entitycache() || cps_get_current_changeset() !== CPS_PUBLISHED_CHANGESET) { + // If entitycache is disabled or we are in a changeset, do not let + // entitycache load things from cache. $ids = array(); } } @@ -810,8 +811,9 @@ function cps_entitycache_pre_cache_get_alter(&$ids, &$conditions, $entity_type) * Implements hook_entitycache_pre_cache_set_alter(). */ function cps_entitycache_pre_cache_set_alter(&$entities, $entity_type) { - if (cps_get_current_changeset() !== CPS_PUBLISHED_CHANGESET) { - // If we are in a changeset, do not let entitycache store things in cache. + if (cps_disable_entitycache() || cps_get_current_changeset() !== CPS_PUBLISHED_CHANGESET) { + // If entitycache is disabled or we are in a changeset, do not let + // entitycache store things in cache. $entities = array(); } } @@ -820,20 +822,15 @@ function cps_entitycache_pre_cache_set_alter(&$entities, $entity_type) { * Implements hook_entitycache_pre_reset_cache_alter(). */ function cps_entitycache_pre_reset_cache_alter(&$ids, $entity_type) { - - if (cps_disable_entitycache_reset()) { - // Disable cache clearing if it was disabled at run-time. - $ids = FALSE; - return; - } - - if (cps_get_current_changeset() !== CPS_PUBLISHED_CHANGESET) { - // Disable cache clearing while in a different changeset. + if (cps_disable_entitycache() + || cps_disable_entitycache_reset() + || cps_get_current_changeset() !== CPS_PUBLISHED_CHANGESET) { + // If entitycache is disabled or entitycache reset clearing is disabled or + // we are in a changeset, do not let entitycache reset the cache. $ids = FALSE; } } - // ----------------------------------------------------------------------- // Public API @@ -988,7 +985,12 @@ function cps_get_supported() { * @{inheritdoc} */ function cps_make_revision_published($entity_type, $entity_id, $changeset_id) { + // Disable entitycache during publishing of a revision. + cps_disable_entitycache(TRUE); + + // Now change to the published changeset. cps_override_changeset(CPS_PUBLISHED_CHANGESET); + // Find the revision id. $revision_id = db_query('SELECT revision_id FROM {cps_entity} WHERE entity_type = :entity_type AND entity_id = :entity_id AND changeset_id = :changeset', array( @@ -999,6 +1001,17 @@ function cps_make_revision_published($entity_type, $entity_id, $changeset_id) { drafty()->publishRevision($entity_type, $entity_id, $revision_id); cps_purge_add_to_queue($entity_type, $entity_id, $changeset_id); + + // Re-enable entitycache. + cps_disable_entitycache(FALSE); + + // Clear the cache for the entity. + // @todo This could fail in the edgecase that entity saves are chained + // and the internal entity is not tracked by CPS, but cached in + // entitycache. + entity_get_controller($entity_type)->resetCache([$entity_id]); + + // Now back to the old changeset. cps_override_changeset(NULL); } @@ -2424,6 +2437,22 @@ function cps_move_changeset($changeset_from, $changeset_to, $entity_type, $entit } /** + * Disables or enables the entitycache for CPS purposes like publishing or reverting. + * + * @param bool $new_state + * The new state to set. + */ +function cps_disable_entitycache($new_state = NULL) { + $state = &drupal_static(__FUNCTION__); + + if (isset($new_state)) { + $state = $new_state; + } + + return $state; +} + +/** * Disables or enables the entitycache reset functionality for CPS purposes. * * Note: Callers of this function should reset the state to what it was before.