public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)
    {
        if (!class_exists(Subsite::class)) {
            return;
        }

        if (Subsite::$disable_subsite_filter) {
            return;
        }

        if ($dataQuery && $dataQuery->getQueryParam('Subsite.filter') === false) {
            return;
        }

        if ($query->filtersOnID()) {
            return;
        }

        if (Subsite::$force_subsite) {
            $subsiteID = Subsite::$force_subsite;
        } else {
            $subsiteID = (int) SubsiteState::singleton()->getSubsiteId();
        }

        // Get the base table name
        $elementTableName = DataObject::getSchema()->baseDataTable(BaseElement::class);

        // The foreach is an ugly way of getting the first key :-)
        foreach ($query->getFrom() as $tableName => $info) {
            // The tableName should be Element or Element_Live...
            if (substr($tableName, 0, strlen($elementTableName)) === $elementTableName) {
                $query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)");
                break;
            }
        }
    }