mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
FIX: Saving null values to the _versions table.
This commit is contained in:
parent
5776a03141
commit
6d835a64ad
@ -788,7 +788,8 @@ class Versioned extends DataExtension implements TemplateGlobalProvider {
|
|||||||
$data = array_intersect_key($data, $fields);
|
$data = array_intersect_key($data, $fields);
|
||||||
|
|
||||||
foreach ($data as $k => $v) {
|
foreach ($data as $k => $v) {
|
||||||
if (!isset($newManipulation['fields'][$k])) {
|
// If the value is not set at all in the manipulation currently, use the existing value from the database
|
||||||
|
if (is_array($newManipulation['fields']) && !array_key_exists($k, $newManipulation['fields'])) {
|
||||||
$newManipulation['fields'][$k] = $v;
|
$newManipulation['fields'][$k] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1036,6 +1036,29 @@ class VersionedTest extends SapphireTest {
|
|||||||
$this->assertTrue($public->canViewStage('Live'));
|
$this->assertTrue($public->canViewStage('Live'));
|
||||||
$this->assertTrue($private->canViewStage('Live'));
|
$this->assertTrue($private->canViewStage('Live'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Values that are overwritten with null are saved to the _versions table correctly.
|
||||||
|
*/
|
||||||
|
public function testWriteNullValueToVersion()
|
||||||
|
{
|
||||||
|
$record = VersionedTest_Subclass::create();
|
||||||
|
$record->Title = "Test A";
|
||||||
|
$record->write();
|
||||||
|
|
||||||
|
$version = Versioned::get_latest_version($record->ClassName, $record->ID);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $version->Version);
|
||||||
|
$this->assertEquals($record->Title, $version->Title);
|
||||||
|
|
||||||
|
$record->Title = null;
|
||||||
|
$record->write();
|
||||||
|
|
||||||
|
$version = Versioned::get_latest_version($record->ClassName, $record->ID);
|
||||||
|
|
||||||
|
$this->assertEquals(2, $version->Version);
|
||||||
|
$this->assertEquals($record->Title, $version->Title);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user