mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #3675 from micmania1/fix-datadifferencer-comparison
FIX DataDifferencer was trying to compare fields, even if the fields did...
This commit is contained in:
commit
9155eb5802
@ -77,28 +77,33 @@ class DataDifferencer extends ViewableData {
|
|||||||
$diffed = clone $this->toRecord;
|
$diffed = clone $this->toRecord;
|
||||||
$fields = array_keys($this->toRecord->toMap());
|
$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
|
// Loop through properties
|
||||||
foreach($fields as $field) {
|
foreach($fields as $field) {
|
||||||
if(in_array($field, $this->ignoredFields)) continue;
|
if(in_array($field, $this->ignoredFields)) continue;
|
||||||
if(in_array($field, array_keys($hasOnes))) continue;
|
if(in_array($field, array_keys($hasOnes))) continue;
|
||||||
|
|
||||||
if(!$this->fromRecord) {
|
if(!$this->fromRecord) {
|
||||||
$diffed->setField($field, "<ins>" . $this->toRecord->$field . "</ins>");
|
$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));
|
$diffed->setField($field, Diff::compareHTML($this->fromRecord->$field, $this->toRecord->$field));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through has_one
|
// Loop through has_one
|
||||||
foreach($hasOnes as $relName => $relSpec) {
|
foreach($hasOnes as $relName => $relSpec) {
|
||||||
if(in_array($relName, $this->ignoredFields)) continue;
|
if(in_array($relName, $this->ignoredFields)) continue;
|
||||||
|
|
||||||
|
// Create the actual column name
|
||||||
$relField = "{$relName}ID";
|
$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(!$this->fromRecord) {
|
||||||
if($relObjTo) {
|
if($relObjTo) {
|
||||||
if($relObjTo instanceof Image) {
|
if($relObjTo instanceof Image) {
|
||||||
@ -107,28 +112,32 @@ class DataDifferencer extends ViewableData {
|
|||||||
// not playing nice with mocked images
|
// not playing nice with mocked images
|
||||||
$diffed->setField($relName, "<ins>" . $relObjTo->getTag() . "</ins>");
|
$diffed->setField($relName, "<ins>" . $relObjTo->getTag() . "</ins>");
|
||||||
} else {
|
} else {
|
||||||
$diffed->setField($relField, "<ins>" . $relObjTo->Title() . "</ins>");
|
$diffed->setField($relField, "<ins>" . $toTitle . "</ins>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if($this->fromRecord->$relField != $this->toRecord->$relField) {
|
} else if($this->fromRecord->$relField != $this->toRecord->$relField) {
|
||||||
$relObjFrom = $this->fromRecord->$relName();
|
$fromTitle = '';
|
||||||
if($relObjFrom instanceof Image) {
|
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)
|
// TODO Use CMSThumbnail (see above)
|
||||||
$diffed->setField(
|
$diffed->setField(
|
||||||
// Using relation name instead of database column name, because of FileField etc.
|
// Using relation name instead of database column name, because of FileField etc.
|
||||||
$relName,
|
$relName,
|
||||||
Diff::compareHTML($relObjFrom->getTag(), $relObjTo->getTag())
|
Diff::compareHTML($relObjFrom->getTag(), $relObjTo->getTag())
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
// Set the field.
|
||||||
$diffed->setField(
|
$diffed->setField(
|
||||||
$relField,
|
$relField,
|
||||||
Diff::compareHTML($relObjFrom->getTitle(), $relObjTo->getTitle())
|
Diff::compareHTML($fromTitle, $toTitle)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $diffed;
|
return $diffed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user