function akamai_clear_url in Akamai 7.3
Same name and namespace in other branches
- 8 akamai.module \akamai_clear_url()
- 8.2 akamai.module \akamai_clear_url()
- 6.2 akamai.module \akamai_clear_url()
- 6 akamai.module \akamai_clear_url()
- 7 akamai.module \akamai_clear_url()
- 7.2 akamai.module \akamai_clear_url()
Deprecated. Use akamai_purge_path() instead.
Clear one or more paths from Akamai. Clears node/id and any URL aliases.
Parameters
array $paths_in: An array of paths or single path to clear.
array $params: (optional) An array of params for the API call.
object $node: (optional)
Return value
mixed A response object if the purge request was accepted, FALSE otherwise.
Deprecated
Deprecated in 7.x-3.0.
See also
6 calls to akamai_clear_url()
- AkamaiHomepageTestCase::testHomepageClear in ./
akamai.test - Tests clear of homepage and rendering of block
- AkamaiHookTestCase::testEmptyClear in ./
akamai.test - Tests clear with no paths.
- AkamaiHookTestCase::testHookClear in ./
akamai.test - Tests clear with hook provided paths.
- AkamaiTestCase::testAliasClear in ./
akamai.test - Tests clear with 1 alias.
- AkamaiTestCase::testMultipleAliasClear in ./
akamai.test - Tests clear with multiple aliases.
File
- ./
akamai.module, line 531 - Integration with Akamai CDN CCU API.
Code
function akamai_clear_url($paths_in, $params = [], $node = NULL) {
if (variable_get('akamai_disabled', FALSE)) {
watchdog('akamai', 'Request to clear paths ignored because clearing is disabled. Check module settings.');
return FALSE;
}
// Get the system path and all aliases to this url.
$paths = array();
$options = [];
if (!empty($node)) {
$options['entity_type'] = 'node';
$options['entity'] = $node;
}
foreach ($paths_in as $path) {
$paths = array_merge($paths, akamai_get_purge_paths($path, $options));
}
// It is possible to have no paths at this point if other modules have
// altered the paths.
if (empty($paths)) {
watchdog('akamai', 'No resultant paths to clear for %paths', array(
'%paths' => implode(', ', $paths_in),
), WATCHDOG_NOTICE);
return FALSE;
}
// This can cause the array to become non-associative and will cause
// json_encode() to use an object instead of an array when encoding.
$paths = array_unique($paths);
$default_params = array(
'basepath' => akamai_get_hostname(),
'action' => variable_get("akamai_action", "invalidate"),
'domain' => variable_get("akamai_network", ""),
);
$params = array_merge($default_params, $params);
if (!empty($params['basepath'])) {
$parsed = parse_url($params['basepath']);
$hostname = empty($parsed['host']) ? NULL : $parsed['host'];
}
$version = variable_get('akamai_ccu_version', 3);
try {
$client = akamai_get_client($version);
if (!empty($params['domain'])) {
$client
->setNetwork($params['domain']);
}
// v2 of the API uses 'remove', but v3 uses 'delete'.
if ($params['action'] == 'remove') {
$client
->setOperation($client::OPERATION_DELETE);
}
else {
$client
->setOperation($client::OPERATION_INVALIDATE);
}
$response = $client
->postPurgeRequest($hostname, $paths);
return $response;
} catch (AkamaiException $e) {
watchdog_exception('akamai', $e);
return FALSE;
}
}