mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX #4325: Fixed publishing of empty values by fixing DataObject::forceChange()
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@80934 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
57bb3c09d7
commit
2b61c12adc
@ -713,8 +713,13 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
* if they are not already marked as changed.
|
||||
*/
|
||||
public function forceChange() {
|
||||
foreach($this->record as $fieldName => $fieldVal) {
|
||||
// $this->record might not contain the blank values so we loop on $this->inheritedDatabaseFields() as well
|
||||
$fieldNames = array_unique(array_merge(array_keys($this->record), array_keys($this->inheritedDatabaseFields())));
|
||||
|
||||
foreach($fieldNames as $fieldName) {
|
||||
if(!isset($this->changed[$fieldName])) $this->changed[$fieldName] = 1;
|
||||
// Populate the null values in record so that they actually get written
|
||||
if(!isset($this->record[$fieldName])) $this->record[$fieldName] = null;
|
||||
}
|
||||
|
||||
// @todo Find better way to allow versioned to write a new version after forceChange
|
||||
|
@ -45,6 +45,25 @@ class SiteTreeTest extends SapphireTest {
|
||||
$this->assertEquals($obj->ID, $createdID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that field which are set and then cleared are also transferred to the published site.
|
||||
*/
|
||||
function testPublishDeletedFields() {
|
||||
$obj = $this->fixture->objFromFixture('Page', 'about');
|
||||
$obj->MetaTitle = "asdfasdf";
|
||||
$obj->write();
|
||||
$obj->doPublish();
|
||||
|
||||
$this->assertEquals('asdfasdf', DB::query("SELECT \"MetaTitle\" FROM \"SiteTree_Live\" WHERE \"ID\" = '$obj->ID'")->value());
|
||||
|
||||
$obj->MetaTitle = null;
|
||||
$obj->write();
|
||||
$obj->doPublish();
|
||||
|
||||
$this->assertNull(DB::query("SELECT \"MetaTitle\" FROM \"SiteTree_Live\" WHERE \"ID\" = '$obj->ID'")->value());
|
||||
|
||||
}
|
||||
|
||||
function testParentNodeCachedInMemory() {
|
||||
$parent = new SiteTree();
|
||||
$parent->Title = 'Section Title';
|
||||
|
Loading…
Reference in New Issue
Block a user