mirror of
https://github.com/silverstripe/silverstripe-translatable
synced 2024-10-22 11:05:59 +02:00
FIXED: Issue where $enable_siteconfig_generation flag was not being set correctly, causing failed test cases_
FIXED: Duplicate entries in test database
This commit is contained in:
parent
8e851e3f82
commit
3688af2e7a
@ -1132,13 +1132,6 @@ class Translatable extends DataExtension implements PermissionProvider {
|
||||
return ($translations) ? $translations->First() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables automatic population of SiteConfig fields using createTranslation if
|
||||
* created outside of the Translatable module
|
||||
* @var boolean
|
||||
*/
|
||||
public static $enable_siteconfig_generation = true;
|
||||
|
||||
/**
|
||||
* When the SiteConfig object is automatically instantiated, we should ensure that
|
||||
* 1. All SiteConfig objects belong to the same group
|
||||
@ -1150,12 +1143,14 @@ class Translatable extends DataExtension implements PermissionProvider {
|
||||
* @see SiteConfig
|
||||
*/
|
||||
protected function populateSiteConfig() {
|
||||
// This is required to prevent infinite loop during createTranslation
|
||||
// If createTranslation is called directly on SiteConfig then this function could
|
||||
// be called twice, but it will not cause harm for this to happen.
|
||||
if(!self::$enable_siteconfig_generation)
|
||||
|
||||
// Work-around for population of defaults during test setup (when tables are not created).
|
||||
// When the database is being setup during testing, singleton('SiteConfig') is called.
|
||||
// Singleton objects should not call populateDefault() but a bug seems to be allowing it
|
||||
// to happen anyway. Looking up existing SiteConfig objects without a database crashes horribly
|
||||
// @todo Remove this hack once this bug is fixed
|
||||
if(SapphireTest::using_temp_db() && !DB::getConn()->hasTable($this->owner->class))
|
||||
return;
|
||||
self::$enable_siteconfig_generation = false;
|
||||
|
||||
// Find the best base translation for site config
|
||||
Translatable::disable_locale_filter();
|
||||
@ -1181,19 +1176,28 @@ class Translatable extends DataExtension implements PermissionProvider {
|
||||
|
||||
// Copy fields from translated object (including ID) to the generated object
|
||||
// This is similar to the creation of objects via createTranslation, but we need to
|
||||
// preserve the ID in order to prevent
|
||||
// preserve the ID in order to prevent unnecessary object creation
|
||||
$this->owner->update($stagingConfig->toMap());
|
||||
|
||||
// Re-enable config generation
|
||||
self::$enable_siteconfig_generation = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables automatic population of SiteConfig fields using createTranslation if
|
||||
* created outside of the Translatable module
|
||||
* @var boolean
|
||||
*/
|
||||
public static $enable_siteconfig_generation = true;
|
||||
|
||||
/**
|
||||
* Hooks into the DataObject::populateDefaults() method
|
||||
*/
|
||||
public function populateDefaults() {
|
||||
if (empty($this->owner->ID) && $this->owner instanceof SiteConfig)
|
||||
if (empty($this->owner->ID) && ($this->owner instanceof SiteConfig) && self::$enable_siteconfig_generation)
|
||||
{
|
||||
// Use enable_siteconfig_generation to prevent infinite loop during
|
||||
self::$enable_siteconfig_generation = false;
|
||||
$this->populateSiteConfig();
|
||||
self::$enable_siteconfig_generation = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -41,46 +41,3 @@ SiteConfig:
|
||||
Locale: de_DE
|
||||
CanEditType: OnlyTheseUsers
|
||||
EditorGroups: =>Group.translators_de
|
||||
Permission:
|
||||
cmsmain1:
|
||||
Code: CMS_ACCESS_CMSMain
|
||||
cmsmain2:
|
||||
Code: CMS_ACCESS_CMSMain
|
||||
translate_all1:
|
||||
Code: TRANSLATE_ALL
|
||||
translate_all2:
|
||||
Code: TRANSLATE_ALL
|
||||
Group:
|
||||
translators_de:
|
||||
Code: translators_de
|
||||
Permissions: =>Permission.cmsmain1,=>Permission.translate_all1
|
||||
translators_en:
|
||||
Code: translators_en
|
||||
Permissions: =>Permission.cmsmain2,=>Permission.translate_all2
|
||||
Member:
|
||||
translator_de:
|
||||
Email: translator_de@test.com
|
||||
Password: test
|
||||
Groups: =>Group.translators_de
|
||||
translator_en:
|
||||
Email: translator_en@test.com
|
||||
Password: test
|
||||
Groups: =>Group.translators_en
|
||||
websiteuser:
|
||||
Email: websiteuser@test.com
|
||||
Password: test
|
||||
Page:
|
||||
root_en:
|
||||
URLSegment: root-en
|
||||
Locale: en_US
|
||||
SiteConfig:
|
||||
en_US:
|
||||
Title: My test site
|
||||
Locale: en_US
|
||||
CanEditType: OnlyTheseUsers
|
||||
EditorGroups: =>Group.translators_en
|
||||
de_DE:
|
||||
Title: Meine Test Seite
|
||||
Locale: de_DE
|
||||
CanEditType: OnlyTheseUsers
|
||||
EditorGroups: =>Group.translators_de
|
Loading…
Reference in New Issue
Block a user