mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX DataDifferencer was trying to compare fields, even if the fields didn't exist causing an error.
This commit is contained in:
parent
3b3478136d
commit
7384d011e9
@ -77,28 +77,33 @@ class DataDifferencer extends ViewableData {
|
||||
$diffed = clone $this->toRecord;
|
||||
$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) {
|
||||
if(in_array($field, $this->ignoredFields)) continue;
|
||||
if(in_array($field, array_keys($hasOnes))) continue;
|
||||
|
||||
|
||||
if(!$this->fromRecord) {
|
||||
$diffed->setField($field, "<ins>" . $this->toRecord->$field . "</ins>");
|
||||
} else if($this->fromRecord->$field != $this->toRecord->$field) {
|
||||
} else if($this->fromRecord->$field != $this->toRecord->$field) {
|
||||
$diffed->setField($field, Diff::compareHTML($this->fromRecord->$field, $this->toRecord->$field));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Loop through has_one
|
||||
foreach($hasOnes as $relName => $relSpec) {
|
||||
if(in_array($relName, $this->ignoredFields)) continue;
|
||||
|
||||
|
||||
// Create the actual column name
|
||||
$relField = "{$relName}ID";
|
||||
$relObjTo = $this->toRecord->$relName();
|
||||
|
||||
$toTitle = '';
|
||||
if($this->toRecord->hasMethod($relName)) {
|
||||
$relObjTo = $this->toRecord->$relName();
|
||||
$toTitle = $relObjTo->hasMethod('Title') || $relObjTo->hasField('Title') ? $relObjTo->Title : '';
|
||||
}
|
||||
|
||||
if(!$this->fromRecord) {
|
||||
if($relObjTo) {
|
||||
if($relObjTo instanceof Image) {
|
||||
@ -107,28 +112,32 @@ 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) {
|
||||
$relObjFrom = $this->fromRecord->$relName();
|
||||
if($relObjFrom instanceof Image) {
|
||||
$fromTitle = '';
|
||||
if($this->fromRecord->hasMethod($relName)) {
|
||||
$relObjFrom = $this->fromRecord->$relName();
|
||||
$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.
|
||||
$relName,
|
||||
// Using relation name instead of database column name, because of FileField etc.
|
||||
$relName,
|
||||
Diff::compareHTML($relObjFrom->getTag(), $relObjTo->getTag())
|
||||
);
|
||||
} else {
|
||||
// Set the field.
|
||||
$diffed->setField(
|
||||
$relField,
|
||||
Diff::compareHTML($relObjFrom->getTitle(), $relObjTo->getTitle())
|
||||
$relField,
|
||||
Diff::compareHTML($fromTitle, $toTitle)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $diffed;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user