You are here

public function TrafficRegistry::getUrls in URLs queuer 8

Collect URLs and paths associated with the given list of tags.

Parameters

string[] $tags: Unassociative list of cache tags that belong to one or more URls/paths.

Return value

string[] Returns an array with URLs/paths associated with the tags.

Throws

\LogicException Thrown when $tags is empty.

Overrides TrafficRegistryInterface::getUrls

File

src/TrafficRegistry.php, line 106

Class

TrafficRegistry
Provides a database-driven traffic registry with URLs and tags.

Namespace

Drupal\purge_queuer_url

Code

public function getUrls(array $tags) {
  if (!$this->connection
    ->schema()
    ->tableExists('purge_queuer_url')) {
    return [];
  }
  if (empty($tags)) {
    throw new \LogicException('$tags cannot be empty!');
  }

  // Retrieve tag IDs but without adding new ones.
  $tag_ids = array_keys($this
    ->getTagIds($tags, FALSE));

  // Don't return any URLs when no tags actually exist.
  if (empty($tag_ids)) {
    return [];
  }

  // Build a OR condition with LIKES on tag_ids for every tag.
  $or = new Condition('OR');
  foreach ($tag_ids as $tag_id) {
    $syntax = '%;' . $this->connection
      ->escapeLike($tag_id) . '%';
    $or
      ->condition('tag_ids', $syntax, 'LIKE');
  }

  // Perform the query and fetch the URLs from its resultset.
  $urls = [];
  $results = $this->connection
    ->select('purge_queuer_url', 'u')
    ->fields('u', [
    'url',
  ])
    ->condition($or)
    ->execute();
  foreach ($results as $url) {
    $urls[] = $url->url;
  }
  return $urls;
}