You are here

function akamai_cache_control_submit in Akamai 7.2

Same name and namespace in other branches
  1. 6.2 akamai.admin.inc \akamai_cache_control_submit()
  2. 6 akamai.admin.inc \akamai_cache_control_submit()
  3. 7 akamai.admin.inc \akamai_cache_control_submit()

Submit handler for akamai_cache_control().

Process the settings and submit to Akamai

File

./akamai.admin.inc, line 183
Akamai is a registered trademark of Akamai Technologies, Inc. Administrative pages for the Akamai module.

Code

function akamai_cache_control_submit($form, &$form_state) {
  $paths = explode("\n", filter_xss($form_state['values']['paths']));
  $action = $form_state['values']['refresh'];
  $overrides = array(
    'action' => $form_state['values']['refresh'],
    'domain' => $form_state['values']['domain_override'],
  );
  if ($result = akamai_clear_url($paths, $overrides)) {
    $message = t("Akamai Cache Request has been made successfully.") . theme("item_list", $paths);
    $status = 'status';
    if (is_object($result) && !empty($result->data)) {
      if ($akamai_response_data = json_decode($result->data)) {
        if (isset($akamai_response_data->httpStatus) && $akamai_response_data->httpStatus > 300) {
          $message = t("There was a problem with your cache clearing request.  The error message returned was '@msg'", array(
            '@msg' => $akamai_response_data->details,
          ));
          $status = 'error';
        }
        else {
          $message = t("Akamai Cache Request has been made successfully.  Akamai reports an estimated time to completion of @time", array(
            '@time' => format_interval($akamai_response_data->estimatedSeconds),
          )) . theme("item_list", $paths);
        }
      }
      else {
        $message = t('There was a problem with your cache clearing request. Please check the watchdog logs for details.');
        $status = 'error';
        watchdog('akamai', 'Unable to parse Akamai API response data: @json_data', array(
          '@json_data' => '<pre>' . print_r($result->data, TRUE) . '</pre>',
        ), WATCHDOG_ERROR);
      }
    }
  }
  else {
    $message = t('There was a problem with your cache clearing request. Please check the watchdog logs for details.');
    $status = 'error';
  }
  drupal_set_message($message, $status);
}