Commit 6e1f16f0 authored by Spleshka's avatar Spleshka

Added hook_expire_urls_alter() that allows to change urls right before the expiration.

Returned hook_expire_cache_alter() to its default place.
parent 76edb0a2
......@@ -54,6 +54,36 @@ function hook_expire_cache($urls, $wildcards, $object_type, $object) {
* @param $urls
* List of internal paths and/or absolute URLs that should be flushed.
*
* Example of array:
* array(
* 'node-1' => 'node/1',
* 'reference-user-17' => 'user/17',
* );
*
* @param $object_type
* Name of object type ('node', 'comment', 'user', etc).
*
* @param $object
* Object (node, comment, user, etc) for which expiration is executes.
*
* @param $absolute_urls_passed
* Indicates whether absolute urls were passed (TRUE or FALSE).
* Currently this flag can be set to TRUE only from drush command or rules action.
*
* @see expire.api.inc
*/
function hook_expire_cache_alter(&$urls, $object_type, $object, $absolute_urls_passed) {
if (!$absolute_urls_passed && isset($urls['node-1'])) {
unset($urls['node-1']); // Do not expire node with nid 1.
}
}
/**
* Provides possibility to change urls right before they are expired.
*
* @param $urls
* List of internal paths and/or absolute URLs that should be flushed.
*
* Example of array (when base url include option is enabled):
* array(
* 'node/1' => 'http://example.com/node/1',
......@@ -74,9 +104,8 @@ function hook_expire_cache($urls, $wildcards, $object_type, $object) {
*
* @see expire.api.inc
*/
function hook_expire_cache_alter(&$urls, $object_type, $object) {
if ($object_type == 'node') {
unset($urls['node-' . $object->nid]);
$urls['example'] = 'custom_page/' . $object->uid . '/' . $object->nid;
function hook_expire_urls_alter(&$urls, $object_type, $object) {
if ($object_type == 'node' && isset($urls['node-' . $object->nid])) {
$urls['node-' . $object->nid] = 'custom-url';
}
}
......@@ -24,6 +24,9 @@ class ExpireAPI {
*/
public static function executeExpiration($urls, $object_type = '', $object = NULL, $absolute_urls_passed = FALSE) {
// Allow other modules to modify the list prior to expiring.
drupal_alter('expire_cache', $urls, $object_type, $object, $absolute_urls_passed);
// Nothing to expire, so exit.
if (empty($urls)) {
return;
......@@ -68,12 +71,13 @@ class ExpireAPI {
}
}
// Allow other modules to modify the list prior to expiring.
drupal_alter('expire_cache', $urls, $object_type, $object);
// Latest possibility to change urls that should be expired.
drupal_alter('expire_urls', $urls, $object_type, $object);
// Write some debug information.
self::debugLog($urls, $wildcards, $object_type);
// Execute internal or external expiration.
$status = variable_get('expire_status', EXPIRE_STATUS_DISABLED);
if ($status == EXPIRE_STATUS_ENABLED_INTERNAL) {
self::executeInternalExpiration($urls, $wildcards);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment