function acquia_purge_expire_cache in Acquia Purge 6
Same name and namespace in other branches
- 7 acquia_purge.module \acquia_purge_expire_cache()
Implements hook_expire_cache().
File
- ./
acquia_purge.module, line 122 - Acquia Purge, Top-notch Varnish purging on Acquia Cloud!
Code
function acquia_purge_expire_cache($paths) {
static $patterns;
// Ask our built-in diagnostics system to preliminary find issues that are so
// risky we can expect problems. Everything with ACQUIA_PURGE_SEVLEVEL_ERROR
// will cause purging to cease and we've got to tell the end user.
if (count($err = _acquia_purge_get_diagnosis(ACQUIA_PURGE_SEVLEVEL_ERROR))) {
// Stack all found error messages (can be one too) in a HTML item list.
$items = array();
foreach ($err as $error) {
$items[] = '<p>' . $error['description'] . '</p>';
}
$items = theme('item_list', array(
'items' => $items,
));
// Warn the user on-screen that purging cannot continue.
if (user_access('purge notification')) {
drupal_set_message(t("<p>The system cannot publicly refresh the changes you just made,\n because of the following error conditions:</p>!items<p>Please\n contact your system administrator or development partner!</p>", array(
'!items' => $items,
)), 'warning');
}
else {
_acquia_purge_get_diagnosis_logged($err);
}
return;
}
// The expire module is unreliable API-wise as it often gives absolute URLs
// in various scenarios. In the past we tested for 'expire_include_base_url'
// but that doesn't always seem to help. We therefore generate a list of
// possible http://domainname patterns to strip out. D.o: #2049235, #2133001.
$schemes = array(
'http://',
'https://',
);
if (is_null($patterns)) {
foreach (_acquia_purge_get_domains() as $domain) {
foreach ($schemes as $scheme) {
$patterns[] = "{$scheme}{$domain}" . base_path();
$patterns[] = "{$scheme}{$domain}";
}
}
}
// Iterate the given paths and strip everything out we can think off.
$new_paths = array();
foreach ($paths as $path) {
foreach ($patterns as $pattern) {
$path = str_replace($pattern, '', $path);
}
$path = ltrim($path, '/');
if (!in_array($path, $new_paths)) {
$new_paths[] = $path;
}
}
$paths = $new_paths;
// This should help for many cases, but not always. Detect if any of the paths
// still contain http:// or https://.
$paths_clean = TRUE;
foreach ($paths as $path) {
if (!$paths_clean) {
break;
}
foreach ($schemes as $scheme) {
if (strpos($path, $scheme) !== FALSE) {
$paths_clean = FALSE;
break;
}
}
}
// If the "cleaned" paths are still dirty we warn the user and abort purging.
if (!$paths_clean) {
drupal_set_message(t("Please disable the 'Include base URL in expires'\n setting as it is incompatible with the Acquia Purge module. "), 'error');
}
else {
acquia_purge_purge_paths($paths);
}
}