You are here

function akamai_manual_purge_form_submit in Akamai 7.3

Form submission handler for akamai_manual_purge_form().

File

./akamai.admin.inc, line 364
Administrative pages for the Akamai module.

Code

function akamai_manual_purge_form_submit($form, &$form_state) {

  // filter_xss() does not need to be used here as it turns the & symbol into
  // an HTML entity and v3 rejects it. We don't need HTML entities here as this
  // data won't be used in actual HTML, just API requests.
  $paths = explode("\n", $form_state['values']['paths']);
  if ($result = akamai_purge_paths($paths)) {
    $paths['items'] = $paths;
    $message = t("Akamai purge request successful. The estimated completion time is @estimated_seconds seconds and the list of URLs submitted are:", array(
      '@estimated_seconds' => $result->estimatedSeconds,
    )) . theme("item_list", $paths);
    $status = 'status';

    // @todo Overhaul the $akamai_response_data logic, it is currently expecting
    // v2 response and doesn't report correct information.
    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 purge request. The error message returned was '@msg'", array(
            '@msg' => $akamai_response_data->details,
          ));
          $status = 'error';
        }
        else {
          $message = t("Purge request successful. 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 purge 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 purge request. Please check the watchdog logs for details.');
    $status = 'error';
  }
  drupal_set_message($message, $status);
}