diff --git a/.travis.yml b/.travis.yml index f397015..2026403 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ php: - 5.4 env: - - DB=MYSQL CORE_RELEASE=3.1 + - DB=MYSQL CORE_RELEASE=3.2 before_script: - pear -q install --onlyreqdeps pear/PHP_CodeSniffer diff --git a/README.md b/README.md index 26f3493..8dccd13 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,7 @@ Note: This module was originally part of the SilverStripe CMS 2.x codebase. ## Requirements ## - * SilverStripe Framework 3.1+ and CMS 3.1+ - * Note: For SilverStripe 2.3/2.4 support, please use the core built-in version (no module required) + * SilverStripe Framework 3.2+ and CMS 3.2+ ## Maintainers ## diff --git a/code/model/Translatable.php b/code/model/Translatable.php index ddcb11d..5380a09 100755 --- a/code/model/Translatable.php +++ b/code/model/Translatable.php @@ -590,7 +590,7 @@ class Translatable extends DataExtension implements PermissionProvider { * * Use {@link disable_locale_filter()} to temporarily disable this "auto-filtering". */ - function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) { + public function augmentSQL(SQLQuery &$query, DataQuery $dataQuery = null) { // If the record is saved (and not a singleton), and has a locale, // limit the current call to its locale. This fixes a lot of problems // with other extensions like Versioned @@ -612,13 +612,19 @@ class Translatable extends DataExtension implements PermissionProvider { // the query contains this table // @todo Isn't this always the case?! && array_search($baseTable, array_keys($query->getFrom())) !== false - // or we're already filtering by Lang (either from an earlier augmentSQL() - // call or through custom SQL filters) - && !preg_match('/("|\'|`)Locale("|\'|`)/', implode(' ', $query->getWhere())) //&& !$query->filtersOnFK() ) { - $qry = sprintf('"%s"."Locale" = \'%s\'', $baseTable, Convert::raw2sql($locale)); - $query->addWhere($qry); + // Or we're already filtering by Lang (either from an earlier augmentSQL() + // call or through custom SQL filters) + $filtersOnLocale = array_filter($query->getWhere(), function($predicates) { + foreach($predicates as $predicate => $params) { + if(preg_match('/("|\'|`)Locale("|\'|`)/', $predicate)) return true; + } + }); + if(!$filtersOnLocale) { + $qry = sprintf('"%s"."Locale" = \'%s\'', $baseTable, Convert::raw2sql($locale)); + $query->addWhere($qry); + } } } diff --git a/composer.json b/composer.json index 27295fa..f75f0fd 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,8 @@ "require": { "php": ">=5.3.2", - "silverstripe/framework": "~3.1", - "silverstripe/cms": "~3.1" + "silverstripe/framework": "~3.2", + "silverstripe/cms": "~3.2" }, "require-dev": { "silverstripe/postgresql": "*",