FIX: Versioned not ignoring obsolete fields

This commit is contained in:
Benjamin R. White 2015-02-08 18:42:36 +13:00 committed by Will Rossiter
parent 85349820e4
commit 6212b4bd4b
2 changed files with 25 additions and 3 deletions

View File

@ -577,9 +577,18 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
// Add any extra, unchanged fields to the version record.
$data = DB::prepared_query("SELECT * FROM \"$table\" WHERE \"ID\" = ?", array($recordID))->record();
if($data) foreach($data as $k => $v) {
if (!isset($newManipulation['fields'][$k])) {
$newManipulation['fields'][$k] = $v;
if ($data) {
$fields = DataObject::database_fields($table);
if (is_array($fields)) {
$data = array_intersect_key($data, $fields);
foreach ($data as $k => $v) {
if (!isset($newManipulation['fields'][$k])) {
$newManipulation['fields'][$k] = $v;
}
}
}
}

View File

@ -720,6 +720,19 @@ class VersionedTest extends SapphireTest {
$this->assertRecordHasLatestVersion($record, 2);
}
public function testVersionedHandlesRenamedDataObjectFields(){
Config::inst()->remove('VersionedTest_RelatedWithoutVersion','db','Name','Varchar');
Config::inst()->update('VersionedTest_RelatedWithoutVersion','db',array(
"NewField" => "Varchar",
));
VersionedTest_RelatedWithoutVersion::add_extension("Versioned('Stage', 'Live')");
$this->resetDBSchema(true);
$testData = new VersionedTest_RelatedWithoutVersion();
$testData->NewField = 'Test';
$testData->write();
}
}