summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSpleshka2014-02-20 13:44:55 (GMT)
committerSpleshka2014-02-20 13:44:55 (GMT)
commit6e1f16f052e8c665ed6a1a58de697d62164af4c1 (patch)
treee5cf0ffd6607f40b5b6e4e90482426955670dce7
parent76edb0a29240d5f9a3e1719a8b0178e8d019a51e (diff)
Added hook_expire_urls_alter() that allows to change urls right before the expiration.7.x-2.0-rc2
Returned hook_expire_cache_alter() to its default place.
-rw-r--r--expire.api.php37
-rw-r--r--includes/expire.api.inc8
2 files changed, 39 insertions, 6 deletions
diff --git a/expire.api.php b/expire.api.php
index 9c811e3..ea89183 100644
--- a/expire.api.php
+++ b/expire.api.php
@@ -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';
}
}
diff --git a/includes/expire.api.inc b/includes/expire.api.inc
index 464843d..6966bb4 100644
--- a/includes/expire.api.inc
+++ b/includes/expire.api.inc
@@ -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);