From 07937a20f9f753f87e76259dd3622f2da4d6fd01 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 1 Aug 2014 15:39:11 +1200 Subject: [PATCH 1/2] Fix unit tests for 3.2 compatibility Exclude 'Version' from createTranslation(): Causes inconsistencies in Versioned->augmentWrite() because it doesn't write a SiteTree_versions record, since the Version is already set on the record. In fact, its just copied from the original record, so there's no SiteTree_versions row correlating to this new record yet. --- .travis.yml | 1 - README.md | 3 +-- code/model/Translatable.php | 22 ++++++++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2d8364b..5833dcc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ php: - 5.3 env: - - DB=MYSQL CORE_RELEASE=3.1 - DB=MYSQL CORE_RELEASE=master - DB=PGSQL CORE_RELEASE=master diff --git a/README.md b/README.md index d0ca4d7..aa23421 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+ (master) and CMS 3.2+ (master) ## Maintainers ## diff --git a/code/model/Translatable.php b/code/model/Translatable.php index a7a9551..0df9087 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) { + function augmentSQL(SQLSelect $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,17 +612,23 @@ 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); + } } } - function augmentDataQueryCreation(SQLQuery &$sqlQuery, DataQuery &$dataQuery) { + function augmentDataQueryCreation(SQLSelect $sqlQuery, DataQuery $dataQuery) { $enabled = self::locale_filter_enabled(); $dataQuery->setQueryParam(self::QUERY_LOCALE_FILTER_ENABLED, $enabled); } @@ -1420,7 +1426,7 @@ class Translatable extends DataExtension implements PermissionProvider { $newTranslation = new $class; // copy all fields from owner (apart from ID) - $newTranslation->update($this->owner->toMap()); + $newTranslation->update(array_diff_key($this->owner->toMap(), array('Version' => null))); // If the object has Hierarchy extension, // check for existing translated parents and assign From eb1917abbf166342b67bb63f13acf7caf8f48795 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 4 Aug 2014 09:06:38 +1200 Subject: [PATCH 2/2] Updated composer core dep to 3.2 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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": "*",