BUG Prevent failover / extensions interfering with composite field properties (#7988)

This commit is contained in:
Damian Mooyman 2018-04-06 14:48:24 +12:00 committed by Aaron Carlino
parent ff7e9e5d8e
commit be8287fef8

View File

@ -25,7 +25,6 @@ use SilverStripe\ORM\Queries\SQLSelect;
*/ */
abstract class DBComposite extends DBField abstract class DBComposite extends DBField
{ {
/** /**
* Similiar to {@link DataObject::$db}, * Similiar to {@link DataObject::$db},
* holds an array of composite field names. * holds an array of composite field names.
@ -44,6 +43,27 @@ abstract class DBComposite extends DBField
*/ */
protected $record = array(); protected $record = array();
public function __set($property, $value)
{
// Prevent failover / extensions from hijacking composite field setters
// by intentionally avoiding hasMethod()
if ($this->hasField($property) && !method_exists($this, "set$property")) {
$this->setField($property, $value);
return;
}
parent::__set($property, $value);
}
public function __get($property)
{
// Prevent failover / extensions from hijacking composite field getters
// by intentionally avoiding hasMethod()
if ($this->hasField($property) && !method_exists($this, "get$property")) {
return $this->getField($property);
}
return parent::__get($property);
}
/** /**
* Write all nested fields into a manipulation * Write all nested fields into a manipulation
* *
@ -243,7 +263,7 @@ abstract class DBComposite extends DBField
// Non-db fields get assigned as normal properties // Non-db fields get assigned as normal properties
if (!$this->hasField($field)) { if (!$this->hasField($field)) {
parent::setField($field, $value); parent::setField($field, $value);
return $this; return $this;
} }