/**
  * Update any requests to limit the results to the current site
  */
 public function augmentSQL(SQLSelect $query)
 {
     if (Subsite::$disable_subsite_filter) {
         return;
     }
     // If you're querying by ID, ignore the sub-site - this is a bit ugly... (but it was WAYYYYYYYYY worse)
     //@TODO I don't think excluding if SiteTree_ImageTracking is a good idea however because of the SS 3.0 api and ManyManyList::removeAll() changing the from table after this function is called there isn't much of a choice
     $from = $query->getFrom();
     if (isset($from['SiteTree_ImageTracking']) || $query->filtersOnID()) {
         return;
     }
     $subsiteID = (int) Subsite::currentSubsiteID();
     // The foreach is an ugly way of getting the first key :-)
     foreach ($query->getFrom() as $tableName => $info) {
         $where = "\"{$tableName}\".\"SubsiteID\" IN (0, {$subsiteID})";
         $query->addWhere($where);
         break;
     }
     $sect = array_values($query->getSelect());
     $isCounting = strpos($sect[0], 'COUNT') !== false;
     // Ordering when deleting or counting doesn't apply
     if (!$isCounting) {
         $query->addOrderBy("\"SubsiteID\"");
     }
 }
 /**
  * Set the ORDER BY clause of this query
  *
  * @see SQLSelect::orderby()
  *
  * @param String $sort Column to sort on (escaped SQL statement)
  * @param String $direction Direction ("ASC" or "DESC", escaped SQL statement)
  * @param Boolean $clear Clear existing values
  * @return DataQuery
  */
 public function sort($sort = null, $direction = null, $clear = true)
 {
     if ($clear) {
         $this->query->setOrderBy($sort, $direction);
     } else {
         $this->query->addOrderBy($sort, $direction);
     }
     return $this;
 }