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
This commit is contained in:
Ingo Schommer 2009-05-14 21:05:48 +00:00
parent fdcaba515c
commit 9790c4832a

View File

@ -529,10 +529,18 @@ class Translatable extends DataObjectDecorator {
ClassInfo::baseDataClass($this->owner->class)
))->column();
if($idsWithoutLocale) {
foreach(array('Stage', 'Live') as $stage) {
foreach($idsWithoutLocale as $id) {
$obj = DataObject::get_by_id($this->owner->class, $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->write();
$obj->writeToStage($stage);
$obj->addTranslationGroup($obj->ID);
$obj->destroy();
unset($obj);
}
@ -543,6 +551,7 @@ class Translatable extends DataObjectDecorator {
));
}
}
}
/**
* Add a record to a "translation group",
@ -928,11 +937,16 @@ 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);