BUGFIX Don't remove translation groups in Translatable->onBeforeDelete() if the decorated record uses Versioned, as other representations of the record might still exist in other tables (e.g. SiteTree_Live) (see #4219)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@79208 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-06-15 05:02:43 +00:00
parent 9c1ef3cd15
commit 20ada72b4d
2 changed files with 28 additions and 2 deletions

View File

@ -737,7 +737,14 @@ class Translatable extends DataObjectDecorator {
* Remove the record from the translation group mapping. * Remove the record from the translation group mapping.
*/ */
function onBeforeDelete() { function onBeforeDelete() {
// @todo Coupling to Versioned, we need to avoid removing
// translation groups if records are just deleted from a stage
// (="unpublished"). Ideally the translation group tables would
// be specific to different Versioned changes, making this restriction unnecessary.
// This will produce orphaned translation group records for SiteTree subclasses.
if(!$this->owner->hasExtension('Versioned')) {
$this->removeTranslationGroup(); $this->removeTranslationGroup();
}
parent::onBeforeDelete(); parent::onBeforeDelete();
} }

View File

@ -136,6 +136,25 @@ class TranslatableTest extends FunctionalTest {
); );
} }
function testTranslationGroupNotRemovedWhenSiteTreeUnpublished() {
$enPage = new Page();
$enPage->Locale = 'en_US';
$enPage->write();
$enPage->publish('Stage', 'Live');
$enTranslationGroup = $enPage->getTranslationGroup();
$frPage = $enPage->createTranslation('fr_FR');
$frPage->write();
$frPage->publish('Stage', 'Live');
$frTranslationGroup = $frPage->getTranslationGroup();
$enPage->doUnpublish();
$this->assertEquals($enPage->getTranslationGroup(), $enTranslationGroup);
$frPage->doUnpublish();
$this->assertEquals($frPage->getTranslationGroup(), $frTranslationGroup);
}
function testGetTranslationOnSiteTree() { function testGetTranslationOnSiteTree() {
$origPage = $this->objFromFixture('Page', 'testpage_en'); $origPage = $this->objFromFixture('Page', 'testpage_en');