public function Api::purgeAll in Fastly 8.3
Purge whole site/service.
Parameters
bool $siteOnly: Set to FALSE if you want to purge entire service otherwise it will purge entire site only.
Return value
bool FALSE if purge failed, TRUE is successful.
File
- src/
Api.php, line 302
Class
- Api
- Fastly API for Drupal.
Namespace
Drupal\fastlyCode
public function purgeAll($siteOnly = TRUE) {
if ($siteOnly) {
// This will return only hash from FASTLY SITE ID and purge only site id hash.
$siteId = $this->cacheTagsHash
->getSiteId();
$siteIdHash = $this->cacheTagsHash
->hashInput($siteId);
return $this
->purgeKeys([
$siteIdHash,
]);
}
else {
if ($this->state
->getPurgeCredentialsState()) {
try {
$response = $this
->query('service/' . $this->serviceId . '/purge_all', [], 'POST');
$result = $this
->json($response);
if ($result->status === 'ok') {
if ($this->purgeLogging) {
$this->logger
->info('Successfully purged all on Fastly.');
}
$this->webhook
->sendWebHook($this
->t("Successfully purged / invalidated all content on @base_url.", [
'@base_url' => $this->baseUrl,
]), "purge_all");
return TRUE;
}
else {
$this->logger
->critical('Unable to purge all on Fastly. Response status: %status.', [
'%status' => $result['status'],
]);
}
} catch (RequestException $e) {
$this->logger
->critical($e
->getMessage());
}
}
return FALSE;
}
}