diff --git a/.travis.yml b/.travis.yml index 6ca80167..06ae9786 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,12 +12,12 @@ php: - 5.3 env: - - DB=MYSQL CORE_RELEASE=3.1 + - DB=MYSQL CORE_RELEASE=3.2 matrix: include: - php: 5.5 - env: DB=PGSQL CORE_RELEASE=3.1 + env: DB=PGSQL CORE_RELEASE=3.2 - php: 5.6 env: DB=MYSQL CORE_RELEASE=3.2 - php: 5.6 diff --git a/code/extensions/FluentExtension.php b/code/extensions/FluentExtension.php index 5a98b8cd..015c7af6 100644 --- a/code/extensions/FluentExtension.php +++ b/code/extensions/FluentExtension.php @@ -503,7 +503,6 @@ protected function localiseSelect($class, $select, $fallback) { } public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) { - // Get locale and translation zone to use $default = Fluent::default_locale(); $locale = $dataQuery->getQueryParam('Fluent.Locale') ?: Fluent::current_locale(); @@ -539,28 +538,46 @@ public function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) { $query->selectField($defaultExpression, $defaultField); } - // Rewrite where conditions - $where = $query->getWhere(); + // Rewrite where conditions with parameterised query (3.2 +) + $where = $query + ->toAppropriateExpression() + ->getWhere(); foreach($where as $index => $condition) { + // Extract parameters from condition + if($condition instanceof SQLConditionGroup) { + $parameters = array(); + $predicate = $condition->conditionSQL($parameters); + } else { + $parameters = array_values(reset($condition)); + $predicate = key($condition); + } // determine the table/column this condition is against - $filterColumn = $this->detectFilterColumn($condition, $includedTables, $locale); - if(empty($filterColumn)) continue; + $filterColumn = $this->detectFilterColumn($predicate, $includedTables, $locale); + if(empty($filterColumn)) { + continue; + } // Duplicate the condition with all localisable fields replaced - $localisedCondition = $this->localiseFilterCondition($condition, $includedTables, $locale); - if($localisedCondition === $condition) continue; + $localisedPredicate = $this->localiseFilterCondition($predicate, $includedTables, $locale); + if($localisedPredicate === $predicate) { + continue; + } // Generate new condition that conditionally executes one of the two conditions // depending on field nullability. // If the filterColumn is null or empty, then it's considered untranslated, and // thus the query should continue running on the default column unimpeded. $castColumn = "COALESCE(CAST($filterColumn AS CHAR), '')"; - $where[$index] = " - ($castColumn != '' AND $castColumn != '0' AND ($localisedCondition)) + $newPredicate = " + ($castColumn != '' AND $castColumn != '0' AND ($localisedPredicate)) OR ( - ($castColumn = '' OR $castColumn = '0') AND ($condition) + ($castColumn = '' OR $castColumn = '0') AND ($predicate) )"; + // Duplicate this condition with parameters duplicated + $where[$index] = array( + $newPredicate => array_merge($parameters, $parameters) + ); } $query->setWhere($where); diff --git a/composer.json b/composer.json index 64d86748..640aacd4 100644 --- a/composer.json +++ b/composer.json @@ -14,13 +14,13 @@ "issues": "http://github.com/tractorcow/silverstripe-fluent/issues" }, "require": { - "silverstripe/framework": ">=3.1.1", - "silverstripe/cms": ">=3.1.1", + "silverstripe/framework": "~3.2", + "silverstripe/cms": "~3.2", "composer/installers": "*" }, "extra": { "branch-alias": { - "dev-master": "3.2.x-dev" + "dev-master": "3.3.x-dev" } }, "extra": {