Checking for static $enabled when processing $versionableExtensions,

as db/build was failing when Translatable::$enabled=false 
Fixed indentation in augumentDatabase() 
(merged from branches/gsoc)


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@42154 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2007-09-16 17:24:51 +00:00
parent 53016680d5
commit c4ab634207

View File

@ -107,9 +107,8 @@ class Versioned extends DataObjectDecorator {
}
/**
* An array of DataObject extensions that may require versioning for extra tables
* The array value is a set of suffixes to form these table names, assuming a preceding '_'
*
* e.g. if Extension1 creates a new table 'Class_suffix1'
* The array value is a set of suffixes to form these table names, assuming a preceding '_'.
* E.g. if Extension1 creates a new table 'Class_suffix1'
* and Extension2 the tables 'Class_suffix2' and 'Class_suffix3':
*
* $versionableExtensions = array(
@ -117,6 +116,9 @@ class Versioned extends DataObjectDecorator {
* 'Extension2' => array('suffix2', 'suffix3'),
* );
*
* Make sure your extension has a static $enabled-property that determines if it is
* processed by Versioned.
*
* @var array
*/
protected static $versionableExtensions = array('Translatable' => 'lang');
@ -127,7 +129,7 @@ class Versioned extends DataObjectDecorator {
// Build a list of suffixes whose tables need versioning
$allSuffixes = array();
foreach (Versioned::$versionableExtensions as $versionableExtension => $suffixes) {
if ($this->owner->hasExtension($versionableExtension)) {
if ($this->owner->hasExtension($versionableExtension) && singleton($versionableExtension)->stat('enabled')) {
$allSuffixes = array_merge($allSuffixes, (array)$suffixes);
foreach ((array)$suffixes as $suffix) {
$allSuffixes[$suffix] = $versionableExtension;
@ -135,7 +137,7 @@ class Versioned extends DataObjectDecorator {
}
}
// Add the zero-suffix table to the list (table name = class name)
// Add the default table with an empty suffix to the list (table name = class name)
array_push($allSuffixes,'');
foreach ($allSuffixes as $key => $suffix) {
@ -150,14 +152,12 @@ class Versioned extends DataObjectDecorator {
if($this->owner->parentClass() == "DataObject") {
$rootTable = true;
}
if ($suffix && ($ext = $this->owner->getExtension($allSuffixes[$suffix]))) {
if (!$ext->isVersionedTable($table)) continue;
$fields = $ext->fieldsInExtraTables($suffix);
$indexes = $fields['indexes'];
$fields = $fields['db'];
} else if (!$ext) continue;
}
// Create tables for other stages
foreach($this->stages as $stage) {