From be8287fef87244f98b0cbdfd89933bd1ec6754f6 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Fri, 6 Apr 2018 14:48:24 +1200 Subject: [PATCH] BUG Prevent failover / extensions interfering with composite field properties (#7988) --- src/ORM/FieldType/DBComposite.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/ORM/FieldType/DBComposite.php b/src/ORM/FieldType/DBComposite.php index a938f242f..781cd200c 100644 --- a/src/ORM/FieldType/DBComposite.php +++ b/src/ORM/FieldType/DBComposite.php @@ -25,7 +25,6 @@ use SilverStripe\ORM\Queries\SQLSelect; */ abstract class DBComposite extends DBField { - /** * Similiar to {@link DataObject::$db}, * holds an array of composite field names. @@ -44,6 +43,27 @@ abstract class DBComposite extends DBField */ 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 * @@ -243,7 +263,7 @@ abstract class DBComposite extends DBField // Non-db fields get assigned as normal properties if (!$this->hasField($field)) { parent::setField($field, $value); - + return $this; }