fix diff of empty recordsets
authorPhilipp Schüle <p.schuele@metaways.de>
Fri, 26 Aug 2016 13:37:59 +0000 (15:37 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 29 Aug 2016 07:18:36 +0000 (09:18 +0200)
Change-Id: I3ec2eb4ae5bd6950e6415e612c7cd7472cfdf39d
Reviewed-on: http://gerrit.tine20.com/customers/3487
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Jenkins CI (http://ci.tine20.com/)
tests/tine20/Tinebase/Record/DummyRecord.php
tests/tine20/Tinebase/Record/RecordTest.php
tine20/Tinebase/Record/Abstract.php

index d30f802..ed9a561 100644 (file)
@@ -26,7 +26,6 @@ class Tinebase_Record_DummyRecord extends Tinebase_Record_Abstract
     protected $_filters = array(
         'date_stringtrim' => 'StringTrim',
         'stringtrim'      => 'StringTrim'
-        
     );
 
     /**
@@ -62,6 +61,8 @@ class Tinebase_Record_DummyRecord extends Tinebase_Record_Abstract
         'date_multiple'   => array(),
         'leadstate'       => array('allowEmpty' => false, 'Alpha' ),
         'inarray'         => array(array('InArray', array('value1', 'value2')), 'allowEmpty' => true),
+        'set1'            => array('allowEmpty' => true),
+        'set2'            => array('allowEmpty' => true),
     );
 
     /**
index c8a70da..74bdfe9 100644 (file)
@@ -112,12 +112,14 @@ class Tinebase_Record_RecordTest extends Tinebase_Record_AbstractTest
             'string' => 'test',
             'test_1' => 25,
             'test_2' => 99,
-            'date_single' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG)
+            'date_single' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG),
+            'set1' => new Tinebase_Record_RecordSet('Tinebase_Record_DummyRecord'),
         ), true);
         
         $record2 = clone $record1;
         $record2->string = 'anders';
         $record2->test_1 = 26;
+        $record2->set2 = new Tinebase_Record_RecordSet('Tinebase_Record_DummyRecord');
         $diff = $record1->diff($record2)->diff;
         $this->assertEquals(2, count($diff), 'expected difference in string & test_1: ' . print_r($diff, TRUE));
         $this->assertEquals('anders', $diff['string']);
index 954b00f..98b18c9 100644 (file)
@@ -448,21 +448,21 @@ abstract class Tinebase_Record_Abstract implements Tinebase_Record_Interface
                 $toConvert = $this->_properties[$field];
             }
 
-            foreach ($toConvert as $field => &$value) {
+            foreach ($toConvert as $convertField => &$value) {
                 if (! method_exists($value, 'setTimezone')) {
-                    throw new Tinebase_Exception_Record_Validation($field . 'must be a method setTimezone');
+                    throw new Tinebase_Exception_Record_Validation($convertField . ' must be a method setTimezone');
                 } 
                 $value->setTimezone($_timezone);
             } 
         }
         
         if ($_recursive) {
-            foreach ($this->_properties as $property => $value) {
-                if ($value && is_object($value) && 
-                        (in_array('Tinebase_Record_Interface', class_implements($value)) || 
-                        $value instanceof Tinebase_Record_Recordset) ) {
-                       
-                    $value->setTimezone($_timezone, TRUE);
+            foreach ($this->_properties as $property => $propValue) {
+                if ($propValue && is_object($propValue) &&
+                        (in_array('Tinebase_Record_Interface', class_implements($propValue)) ||
+                            $propValue instanceof Tinebase_Record_Recordset) ) {
+
+                    $propValue->setTimezone($_timezone, TRUE);
                 }
             }
         }
@@ -679,7 +679,7 @@ abstract class Tinebase_Record_Abstract implements Tinebase_Record_Interface
     */
     public function __toString()
     {
-       return print_r($this->toArray(), TRUE);
+       return (string) print_r($this->toArray(), true);
     }
     
     /**
@@ -994,7 +994,14 @@ abstract class Tinebase_Record_Abstract implements Tinebase_Record_Interface
                 continue;
             } else if (empty($ownField) && empty($recordField)) {
                 continue;
+            } else if ((empty($ownField)    && $recordField instanceof Tinebase_Record_RecordSet && count($recordField) == 0)
+                ||     (empty($recordField) && $ownField    instanceof Tinebase_Record_RecordSet && count($ownField) == 0) )
+            {
+                continue;
             }
+
+            if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ .
+                ' Found diff for ' . $fieldName .'(this/other):' . print_r($ownField, true) . '/' . print_r($recordField, true) );
             
             $diff[$fieldName] = $recordField;
         }