Skip to content

Commit

Permalink
MINOR Merged from trunk
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@76867 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu authored and Sam Minnee committed Feb 2, 2011
1 parent dfa9f98 commit 42972ec
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions core/model/Translatable.php
Expand Up @@ -529,18 +529,27 @@ function requireDefaultRecords() {
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
));
}
}

Expand Down Expand Up @@ -927,16 +936,21 @@ function getTranslations($locale = null, $stage = null) {
$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;
Expand Down

0 comments on commit 42972ec

Please sign in to comment.