mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-30 05:09:06 +02:00
BUGFIX Bypassing setters in DataDifferencer to avoid problems with invalid data (e.g. HTML fragment instead of valid classname in SiteTree->setClassname(). Better validation of constructor parameters (AIR-42)
This commit is contained in:
parent
7403056384
commit
8cc1b4c852
@ -42,8 +42,11 @@ class DataDifferencer extends ViewableData {
|
|||||||
/**
|
/**
|
||||||
* Construct a DataDifferencer to show the changes between $fromRecord and $toRecord.
|
* Construct a DataDifferencer to show the changes between $fromRecord and $toRecord.
|
||||||
* If $fromRecord is null, this will represent a "creation".
|
* If $fromRecord is null, this will represent a "creation".
|
||||||
|
*
|
||||||
|
* @param DataObject (Optional)
|
||||||
|
* @param DataObject
|
||||||
*/
|
*/
|
||||||
function __construct($fromRecord, $toRecord) {
|
function __construct($fromRecord, DataObject $toRecord) {
|
||||||
if(!$toRecord) user_error("DataDifferencer constructed without a toRecord", E_USER_WARNING);
|
if(!$toRecord) user_error("DataDifferencer constructed without a toRecord", E_USER_WARNING);
|
||||||
$this->fromRecord = $fromRecord;
|
$this->fromRecord = $fromRecord;
|
||||||
$this->toRecord = $toRecord;
|
$this->toRecord = $toRecord;
|
||||||
@ -77,9 +80,9 @@ class DataDifferencer extends ViewableData {
|
|||||||
if(in_array($field, $this->ignoredFields)) continue;
|
if(in_array($field, $this->ignoredFields)) continue;
|
||||||
|
|
||||||
if(!$this->fromRecord) {
|
if(!$this->fromRecord) {
|
||||||
$diffed->$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->$field = Diff::compareHTML($this->fromRecord->$field, $this->toRecord->$field);
|
$diffed->setField($field, Diff::compareHTML($this->fromRecord->$field, $this->toRecord->$field));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user