Merge branch '2016.11-develop' into 2017.02
[tine20] / tine20 / Tinebase / Record / Abstract.php
index c23c797..bf91c85 100644 (file)
@@ -1312,7 +1312,18 @@ abstract class Tinebase_Record_Abstract implements Tinebase_Record_Interface
 
         foreach((array)($diff->oldData) as $property => $oldValue)
         {
-            if (in_array($property, $this->_datetimeFields) && ! is_object($oldValue)) {
+            if ('customfields' === $property) {
+                if (!is_array($oldValue)) {
+                    $oldValue = array();
+                }
+                if (isset($diff->diff['customfields']) && is_array($diff->diff['customfields'])) {
+                    foreach (array_keys($diff->diff['customfields']) as $unSetProperty) {
+                        if (!isset($oldValue[$unSetProperty])) {
+                            $oldValue[$unSetProperty] = null;
+                        }
+                    }
+                }
+            } elseif (in_array($property, $this->_datetimeFields) && ! is_object($oldValue)) {
                 $oldValue = new Tinebase_DateTime($oldValue);
             }
             $this->$property = $oldValue;
@@ -1346,7 +1357,11 @@ abstract class Tinebase_Record_Abstract implements Tinebase_Record_Interface
                         is_array($this->$property)?$this->$property:array());
                 }
 
-                $this->$property->applyRecordSetDiff($recordSetDiff);
+                /** @var Tinebase_Record_Abstract $model */
+                $model = $recordSetDiff->model;
+                if (true !== $model::applyRecordSetDiff($this->$property, $recordSetDiff)) {
+                    $this->$property->applyRecordSetDiff($recordSetDiff);
+                }
             } else {
                 if (in_array($property, $this->_datetimeFields) && ! is_object($oldValue)) {
                     $oldValue = new Tinebase_DateTime($oldValue);
@@ -1357,6 +1372,16 @@ abstract class Tinebase_Record_Abstract implements Tinebase_Record_Interface
     }
 
     /**
+     * @param Tinebase_Record_RecordSet $_recordSet
+     * @param Tinebase_Record_RecordSetDiff $_recordSetDiff
+     * @return bool
+     */
+    public static function applyRecordSetDiff(Tinebase_Record_RecordSet $_recordSet, Tinebase_Record_RecordSetDiff $_recordSetDiff)
+    {
+        return false;
+    }
+
+    /**
      * returns true if this record should be replicated
      *
      * @return boolean
@@ -1373,7 +1398,7 @@ abstract class Tinebase_Record_Abstract implements Tinebase_Record_Interface
      */
     public function getPathPart(Tinebase_Record_Interface $_parent = null, Tinebase_Record_Interface $_child = null)
     {
-        /** @var Tinebase_Record_Abstract_GetPathPartDecorator $delegate */
+        /** @var Tinebase_Record_Abstract_GetPathPartDelegatorInterface $delegate */
         $delegate = Tinebase_Core::getDelegate($this->_application, 'getPathPartDelegate_' . get_called_class() ,
                                                 'Tinebase_Record_Abstract_GetPathPartDelegatorInterface');
         if (false !== $delegate) {
@@ -1434,7 +1459,7 @@ abstract class Tinebase_Record_Abstract implements Tinebase_Record_Interface
      * extended properties getter
      *
      * @param string $_property
-     * @return &array
+     * @return array
      */
     public function &xprops($_property = 'xprops')
     {
@@ -1446,4 +1471,14 @@ abstract class Tinebase_Record_Abstract implements Tinebase_Record_Interface
 
         return $this->_properties[$_property];
     }
+
+    /**
+     * @param Tinebase_Record_RecordSet $_recordSetOne
+     * @param Tinebase_Record_RecordSet $_recordSetTwo
+     * @return null|Tinebase_Record_RecordSetDiff
+     */
+    public static function recordSetDiff(Tinebase_Record_RecordSet $_recordSetOne, Tinebase_Record_RecordSet $_recordSetTwo)
+    {
+        return null;
+    }
 }