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:
Sam Minnee 2009-07-03 01:21:48 +00:00
parent 57bb3c09d7
commit 2b61c12adc
2 changed files with 25 additions and 1 deletions

View File

@ -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

View File

@ -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';