FIX DataDifferencer was trying to compare fields, even if the fields didn't exist causing an error.

This commit is contained in:
micmania1 2014-11-24 22:45:21 +00:00
parent 3b3478136d
commit 7384d011e9

View File

@ -78,7 +78,7 @@ class DataDifferencer extends ViewableData {
$fields = array_keys($this->toRecord->toMap());
}
$hasOnes = $this->fromRecord->has_one();
$hasOnes = array_merge($this->fromRecord->has_one(), $this->toRecord->has_one());
// Loop through properties
foreach($fields as $field) {
@ -96,8 +96,13 @@ class DataDifferencer extends ViewableData {
foreach($hasOnes as $relName => $relSpec) {
if(in_array($relName, $this->ignoredFields)) continue;
// Create the actual column name
$relField = "{$relName}ID";
$toTitle = '';
if($this->toRecord->hasMethod($relName)) {
$relObjTo = $this->toRecord->$relName();
$toTitle = $relObjTo->hasMethod('Title') || $relObjTo->hasField('Title') ? $relObjTo->Title : '';
}
if(!$this->fromRecord) {
if($relObjTo) {
@ -107,12 +112,16 @@ class DataDifferencer extends ViewableData {
// not playing nice with mocked images
$diffed->setField($relName, "<ins>" . $relObjTo->getTag() . "</ins>");
} else {
$diffed->setField($relField, "<ins>" . $relObjTo->Title() . "</ins>");
$diffed->setField($relField, "<ins>" . $toTitle . "</ins>");
}
}
} else if($this->fromRecord->$relField != $this->toRecord->$relField) {
$fromTitle = '';
if($this->fromRecord->hasMethod($relName)) {
$relObjFrom = $this->fromRecord->$relName();
if($relObjFrom instanceof Image) {
$fromTitle = $relObjFrom->hasMethod('Title') || $relObjFrom->hasField('Title') ? $relObjFrom->Title : '';
}
if(isset($relObjFrom) && $relObjFrom instanceof Image) {
// TODO Use CMSThumbnail (see above)
$diffed->setField(
// Using relation name instead of database column name, because of FileField etc.
@ -120,12 +129,12 @@ class DataDifferencer extends ViewableData {
Diff::compareHTML($relObjFrom->getTag(), $relObjTo->getTag())
);
} else {
// Set the field.
$diffed->setField(
$relField,
Diff::compareHTML($relObjFrom->getTitle(), $relObjTo->getTitle())
Diff::compareHTML($fromTitle, $toTitle)
);
}
}
}