MINOR: use ENUM hack for dealing with SET legacy values (from r98042)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102569 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-04-13 01:49:58 +00:00
parent 92a25a3e68
commit a2055d1d67

View File

@ -475,15 +475,15 @@ abstract class SS_Database {
Profiler::unmark('createField');
$this->alterationMessage("Field $table.$field: created as $spec_orig","created");
} else if($fieldValue != $specValue) {
// If enums are being modified, then we need to fix existing data in the table.
// If enums/sets are being modified, then we need to fix existing data in the table.
// Update any records where the enum is set to a legacy value to be set to the default.
// One hard-coded exception is SiteTree - the default for this is Page.
if(substr($specValue, 0, 4) == "enum") {
$newStr = preg_replace("/(^enum\s*\(')|('$\).*)/i","",$spec_orig);
foreach(array('enum','set') as $enumtype) {
if(preg_match("/^$enumtype/i",$specValue)) {
$newStr = preg_replace("/(^$enumtype\s*\(')|('$\).*)/i","",$spec_orig);
$new = preg_split("/'\s*,\s*'/", $newStr);
$oldStr = preg_replace("/(^enum\s*\(')|('$\).*)/i","", $fieldValue);
$oldStr = preg_replace("/(^$enumtype\s*\(')|('$\).*)/i","", $fieldValue);
$old = preg_split("/'\s*,\s*'/", $newStr);
$holder = array();
@ -506,6 +506,7 @@ abstract class SS_Database {
$this->alterationMessage("Changed $amount rows to default value of field $field (Value: $default)");
}
}
}
Profiler::mark('alterField');
$this->transAlterField($table, $field, $spec_orig);
Profiler::unmark('alterField');