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
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user