From 9790c4832a6a2701858b0878690444a0115cfde8 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 14 May 2009 21:05:48 +0000 Subject: [PATCH] BUGFIX Fixed default locale setting in SiteTree_Live through Translatable->requireDefaultRecords() BUGFIX Added translation groups for existing entries the first time Translatable is switched on through Translatable->requireDefaultRecords() (see #4051) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@76866 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/Translatable.php | 42 ++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/core/model/Translatable.php b/core/model/Translatable.php index f975de989..0155fa305 100755 --- a/core/model/Translatable.php +++ b/core/model/Translatable.php @@ -529,18 +529,27 @@ class Translatable extends DataObjectDecorator { ClassInfo::baseDataClass($this->owner->class) ))->column(); if($idsWithoutLocale) { - foreach($idsWithoutLocale as $id) { - $obj = DataObject::get_by_id($this->owner->class, $id); - $obj->Locale = Translatable::default_locale(); - $obj->write(); - $obj->destroy(); - unset($obj); + foreach(array('Stage', 'Live') as $stage) { + foreach($idsWithoutLocale as $id) { + $obj = Versioned::get_one_by_stage( + $this->owner->class, + $stage, + sprintf('"SiteTree"."ID" = %d', $id) + ); + if(!$obj) continue; + + $obj->Locale = Translatable::default_locale(); + $obj->writeToStage($stage); + $obj->addTranslationGroup($obj->ID); + $obj->destroy(); + unset($obj); + } + Database::alteration_message(sprintf( + "Added default locale '%s' to table %s","changed", + Translatable::default_locale(), + $this->owner->class + )); } - Database::alteration_message(sprintf( - "Added default locale '%s' to table %s","changed", - Translatable::default_locale(), - $this->owner->class - )); } } @@ -928,16 +937,21 @@ class Translatable extends DataObjectDecorator { $baseDataClass, $baseDataClass ); - $currentStage = Versioned::current_stage(); if($this->owner->hasExtension("Versioned")) { if($stage) Versioned::reading_stage($stage); - $translations = Versioned::get_by_stage($this->owner->class, Versioned::current_stage(), $filter, null, $join); + $translations = Versioned::get_by_stage( + $this->owner->class, + Versioned::current_stage(), + $filter, + null, + $join + ); if($stage) Versioned::reading_stage($currentStage); } else { $translations = DataObject::get($this->owner->class, $filter, null, $join); } - + self::$enable_lang_filter = true; return $translations;