From ea7b94206d4fd7d1920fc7bab695e595a5fb5894 Mon Sep 17 00:00:00 2001 From: Fred Condo Date: Fri, 3 May 2013 16:29:33 -0700 Subject: [PATCH] FIX: Enable $forceWrite argument of DataObject#write() $forceWrite was being ignored because it was tested in a part of the code that is reachable if and only if there are changes to the object. This patch adds an additional test to correct that logic error. Also, refrain from needlessly checking for changes when $forceWrite is true. Fixes #1687 --- model/DataObject.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/model/DataObject.php b/model/DataObject.php index 6fb408961..b8f26ea6d 100644 --- a/model/DataObject.php +++ b/model/DataObject.php @@ -1123,7 +1123,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity } // No changes made - if($this->changed) { + if($this->changed || $forceWrite) { foreach($this->getClassAncestry() as $ancestor) { if(self::has_own_table($ancestor)) $ancestry[] = $ancestor; @@ -1133,13 +1133,14 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity if(!$forceInsert) unset($this->changed['ID']); $hasChanges = false; - foreach($this->changed as $fieldName => $changed) { - if($changed) { - $hasChanges = true; - break; + if (!$forceWrite) { + foreach ($this->changed as $fieldName => $changed) { + if ($changed) { + $hasChanges = true; + break; + } } } - if($hasChanges || $forceWrite || !$this->record['ID']) { // New records have their insert into the base data table done first, so that they can pass the