You are here

function purge_logging in Purge 7.2

Same name and namespace in other branches
  1. 6 purge.inc \purge_logging()
  2. 7 purge.inc \purge_logging()

Logs successful purges and errors to the watchdog.

Parameters

$purge_request_results: array of url with their http status code

File

includes/purge.inc, line 74
Contains the main purging functionality and error handling.

Code

function purge_logging($purge_request_results) {
  $purge_success = 0;
  $purge_blocking = array();
  $purge_log = array();
  foreach ($purge_request_results as $purge_request_result) {
    switch ($purge_request_result['http_code']) {

      // First check if everything went ok.
      case 200:
        $purge_log[] = $purge_request_result['purge_url'] . ' on ' . $purge_request_result['proxy_name'] . ' Ok';
        $purge_success++;
        break;

      // Notice if the request was not found in the proxy cache
      case 404:
        $purge_log[] = $purge_request_result['purge_url'] . ' on ' . $purge_request_result['proxy_name'] . ' Not Found';
        $purge_success++;
        break;

      // Collect all proxy hosts that are blocking the url requests
      case 405:
        $purge_log[] = $purge_request_result['purge_url'] . ' on ' . $purge_request_result['proxy_name'] . ' Forbidden';
        $purge_blocking[] = parse_url($purge_request_result['proxy_url'], PHP_URL_HOST);
        break;

      // Collect all urls and their http error codes
      default:
        $purge_log[] = $purge_request_result['purge_url'] . ' on ' . $purge_request_result['proxy_name'] . ' ' . $purge_request_result['http_code'];
        break;
    }
  }

  // Watchdog barking
  $purge_errors = count($purge_request_results) - $purge_success;

  // Just a notice when all is ok
  if ($purge_errors == 0) {
    if ($purge_success == 1) {
      watchdog('purge', '1 URL has been successfully purged from the reverse proxy caches: !purge_log', array(
        '!purge_log' => expire_print_r($purge_log),
      ));
    }
    else {
      watchdog('purge', '!purge_success_count URLs have been successfully purged from the reverse proxy caches: !purge_log', array(
        '!purge_success_count' => $purge_success,
        '!purge_log' => expire_print_r($purge_log),
      ));
    }
  }
  else {

    // Report all urls with errors
    if ($purge_errors == 1) {
      watchdog('purge', '1 error has been encountered when purging URLs !purge_log', array(
        '!purge_log' => expire_print_r($purge_log),
      ), $severity = WATCHDOG_ERROR);
    }
    else {
      watchdog('purge', '!purge_errors_count errors have been encountered when purging these URLs. !purge_log', array(
        '!purge_errors_count' => count($purge_errors),
        '!purge_log' => expire_print_r($purge_log),
      ), $severity = WATCHDOG_ERROR);
    }

    // Report on proxy servers that block the purge requests.
    if (!empty($purge_blocking)) {
      foreach ($purge_blocking as $purge_blocking_server) {
        watchdog('purge', 'The proxy server host %blocking_server is blocking purge requests. Please review the proxy configuration.', array(
          '%blocking_server' => $purge_blocking_server,
        ), $severity = WATCHDOG_ERROR);
      }
    }
  }
}