You are here

function _acquia_purge_action_flush_url in Acquia Purge 7

Purge URL(s) and Path(s), directly using Acquia Purge's APIs.

Parameters

string $urls_and_paths: User input string with absolute URL(s) or Drupal paths.

1 call to _acquia_purge_action_flush_url()
_acquia_purge_action_purge in ./acquia_purge.rules.inc
Action callback to the "Purge a path from Varnish on Acquia Cloud" rule.
1 string reference to '_acquia_purge_action_flush_url'
acquia_purge_rules_action_info_alter in ./acquia_purge.rules.inc
Implements hook_rules_action_info_alter().

File

./acquia_purge.rules.inc, line 91
Rules integration that provides a purge action as rule action.

Code

function _acquia_purge_action_flush_url($urls_and_paths) {
  $paths = array();

  // Propagate the $paths array based on anything we found that made sense.
  foreach (explode("\n", $urls_and_paths) as $path) {

    // Trim both the start and end, as else parse_url() will add underscores.
    $path = trim($path);

    // Attempt to parse absolute URLs, and to extract paths when possible.
    if ($url = parse_url($path)) {
      $path = $url['path'];
      if (isset($url['query'])) {
        $path .= '?' . $url['query'];
      }
    }

    // Validate the path after it was cleaned. Duplicates and empty paths will
    // still be added as AcquiaPurgeService::addPaths() deduplicates for us and
    // because empty paths usually represent frontpage wipes.
    $path = _acquia_purge_input_clean($path);
    if ($msg = _acquia_purge_input_validate($path)) {
      switch ($msg) {
        case _acquia_purge_input_validate_msgs('empty'):
        case _acquia_purge_input_validate_msgs('double'):
          $paths[] = $path;
          break;

        // Anything still triggering validation certainly needs attention.
        default:
          watchdog('acquia_purge', "Rule action failure on path '%path': !msg", array(
            '%path' => $path,
            '!msg' => $msg,
          ), WATCHDOG_ERROR);
          break;
      }
    }
    else {
      $paths[] = $path;
    }
  }
  _acquia_purge_service()
    ->addPaths($paths);
}