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.
This commit is contained in:
Ingo Schommer 2014-08-01 15:39:11 +12:00
parent 7d8de22d47
commit 07937a20f9
3 changed files with 15 additions and 11 deletions

View File

@ -5,7 +5,6 @@ php:
- 5.3
env:
- DB=MYSQL CORE_RELEASE=3.1
- DB=MYSQL CORE_RELEASE=master
- DB=PGSQL CORE_RELEASE=master

View File

@ -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 ##

View File

@ -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