From 8f5932aceccd5791131e9962cafbfd2108cccca0 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 20 Apr 2015 09:11:57 +1200 Subject: [PATCH] Allow empty has_one returns in DataDifferencer Sometimes the has_one getter is incorrectly implemented, resulting in an empty return object. While that's technically a core API validation, there's no checks around it (i.e. no PHP class interface). DataDifferencer has the option to continue here, so we should program it defensively rather than resulting in a fatal error. --- model/DataDifferencer.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/model/DataDifferencer.php b/model/DataDifferencer.php index f5021f77d..cc7e00ae9 100644 --- a/model/DataDifferencer.php +++ b/model/DataDifferencer.php @@ -116,7 +116,11 @@ class DataDifferencer extends ViewableData { $toTitle = ''; if($this->toRecord->hasMethod($relName)) { $relObjTo = $this->toRecord->$relName(); - $toTitle = $relObjTo->hasMethod('Title') || $relObjTo->hasField('Title') ? $relObjTo->Title : ''; + if($relObjTo) { + $toTitle = ($relObjTo->hasMethod('Title') || $relObjTo->hasField('Title')) ? $relObjTo->Title : ''; + } else { + $toTitle = ''; + } } if(!$this->fromRecord) { @@ -134,7 +138,12 @@ class DataDifferencer extends ViewableData { $fromTitle = ''; if($this->fromRecord->hasMethod($relName)) { $relObjFrom = $this->fromRecord->$relName(); - $fromTitle = $relObjFrom->hasMethod('Title') || $relObjFrom->hasField('Title') ? $relObjFrom->Title : ''; + if($relObjFrom) { + $fromTitle = ($relObjFrom->hasMethod('Title') || $relObjFrom->hasField('Title')) ? $relObjFrom->Title : ''; + } else { + $fromTitle = ''; + } + } if(isset($relObjFrom) && $relObjFrom instanceof Image) { // TODO Use CMSThumbnail (see above)