mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX: Versioned not ignoring obsolete fields
This commit is contained in:
parent
85349820e4
commit
6212b4bd4b
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user