diff --git a/core/model/Translatable.php b/core/model/Translatable.php index 1616793cd..4335144d9 100755 --- a/core/model/Translatable.php +++ b/core/model/Translatable.php @@ -737,8 +737,15 @@ class Translatable extends DataObjectDecorator { * Remove the record from the translation group mapping. */ function onBeforeDelete() { - $this->removeTranslationGroup(); - + // @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(); + } + parent::onBeforeDelete(); } diff --git a/tests/model/TranslatableTest.php b/tests/model/TranslatableTest.php index 853fac56b..b1c025f92 100644 --- a/tests/model/TranslatableTest.php +++ b/tests/model/TranslatableTest.php @@ -135,6 +135,25 @@ class TranslatableTest extends FunctionalTest { $enPage->ID ); } + + 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() { $origPage = $this->objFromFixture('Page', 'testpage_en');