1 select.inc public SelectQuery::preExecute(SelectQueryInterface $query = NULL)

Implements SelectQueryInterface::preExecute().

Overrides SelectQueryInterface::preExecute

File

core/includes/database/select.inc, line 1372

Class

SelectQuery
Query builder for SELECT statements.

Code

public function preExecute(SelectQueryInterface $query = NULL) {
  // If no query object is passed in, use $this.
  if (!isset($query)) {
    $query = $this;
  }

  // Only execute this once.
  if ($query->isPrepared()) {
    return TRUE;
  }

  // Modules may alter all queries or only those having a particular tag.
  if (!empty($this->alterTags)) {
    // Many contrib modules (wrongly) assume that query tags used for
    // access-checking purposes follow the pattern $entity_type . '_access'.
    // But this is not the case for taxonomy terms, since core used to add
    // term_access instead of taxonomy_term_access to its queries. Provide
    // backwards compatibility by adding both tags here instead of attempting
    // to fix all contrib modules in a coordinated effort.
    // TODO:
    // - Extract this mechanism into a hook as part of a public (non-security)
    //   issue.
    // - Emit E_USER_DEPRECATED if term_access is used.
    $term_access_tags = array('term_access' => 1, 'taxonomy_term_access' => 1);
    if (array_intersect_key($this->alterTags, $term_access_tags)) {
      $this->alterTags += $term_access_tags;
    }
    $hooks = array('query');
    foreach ($this->alterTags as $tag => $value) {
      $hooks[] = 'query_' . $tag;
    }
    backdrop_alter($hooks, $query);
  }

  $this->prepared = TRUE;

  // Now also prepare any sub-queries.
  foreach ($this->tables as $table) {
    if ($table['table'] instanceof SelectQueryInterface) {
      $table['table']->preExecute();
    }
  }

  foreach ($this->union as $union) {
    $union['query']->preExecute();
  }

  return $this->prepared;
}