0012224: diff for customfields wrong
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 22 Sep 2016 14:12:51 +0000 (16:12 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 27 Sep 2016 12:45:02 +0000 (14:45 +0200)
improve customfields diff: unset keys of empty values

... before diff as they equal absent keys

https://forge.tine20.org/view.php?id=12224

Change-Id: Id69fc67db2f40aca096822127396cb662f3fa857
Reviewed-on: http://gerrit.tine20.com/customers/3606
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Addressbook/Import/CsvTest.php
tests/tine20/Addressbook/Import/files/adb_import_csv_duplicate.xml
tests/tine20/Addressbook/Import/files/import_duplicate_1_cf.csv
tests/tine20/Addressbook/Import/files/import_duplicate_2_cf.csv
tine20/Tinebase/Record/Abstract.php

index d9a63ad..7482e7d 100644 (file)
@@ -294,7 +294,7 @@ class Addressbook_Import_CsvTest extends ImportTestCase
         $result = $this->_doImport(array(), $definition);
         
         $this->assertEquals(1, $result['updatecount'], 'should have updated 1 contact');
-        $this->assertEquals(0, $result['totalcount']);
+        $this->assertEquals(0, $result['totalcount'], 'should have imported 0 records: ' . print_r($result['results']->toArray(), true));
         $this->assertEquals(0, $result['failcount']);
         $this->assertEquals('joerg@home.com', $result['results'][0]->email_home, 'duplicates resolving did not work: ' . print_r($result['results']->toArray(), true));
         $this->assertEquals('Jörg', $result['results'][0]->n_given, 'wrong encoding: ' . print_r($result['results']->toArray(), true));
@@ -309,6 +309,8 @@ class Addressbook_Import_CsvTest extends ImportTestCase
     {
         $this->_createCustomField('customfield1');
         $this->_createCustomField('customfield2');
+        // empty values: should not trigger record updates
+        $this->_createCustomField('customfield3');
 
         $result = $this->testImportDuplicateResolve(/* $withCustomfields */ true);
 
@@ -361,12 +363,6 @@ class Addressbook_Import_CsvTest extends ImportTestCase
         $this->assertEquals('Straßbough', $result['results'][1]['adr_one_locality'],
                 'should have changed the locality of contact #2: ' . print_r($result['results'][1]->toArray(), true));
         $this->assertEquals('Gartencenter Röhr & Vater', $result['results'][3]['n_family']);
-
-        // TODO this should be researched, imho the relation should not trigger an update of the record
-//        $this->assertEquals(1, $result['results'][3]['seq'], 'Wolfer has been updated - relations changed');
-//        $this->assertEquals('Weixdorf DD', $result['results'][0]['adr_one_locality'], 'locality should persist');
-//        $this->assertEquals('Gartencenter Röhr & Vater', $result['results'][4]['n_fileas']);
-//        $this->assertEquals('Straßback', $result['results'][5]['adr_one_locality']);
     }
 
     public function testSplitField()
index ed0b14f..80994f6 100644 (file)
             <source>customfield2</source>
             <destination>customfield2</destination>
         </field>
+        <field>
+            <source>customfield3</source>
+            <destination>customfield3</destination>
+        </field>
     </mapping>
 </config>
\ No newline at end of file
index f71acac..3066ef8 100644 (file)
@@ -1,3 +1,3 @@
-"org_name","salutation","title","n_given","n_family","role","adr_one_street","adr_one_postalcode","adr_one_locality","adr_one_countryname","tel_work","tel_fax","tel_cell","email","tel_fax_home","tel_home","email_home","customfield1","customfield2"\r
-"effect gmbh","Herr","Dr.","Jörg","Heinz","Geschäftsführer","Str. 25","21222","Köln","DE","022324321","","","joerg.heinz@honk.com","","","","cf1","cf2"\r
-"effect gmbh","Herr","","Hans","Fritz","Technical Lead","Str. 25","21222","Köln","DE","022324321","","","hans.fritz@honk.com","","","","cf1","cf2"\r
+"org_name","salutation","title","n_given","n_family","role","adr_one_street","adr_one_postalcode","adr_one_locality","adr_one_countryname","tel_work","tel_fax","tel_cell","email","tel_fax_home","tel_home","email_home","customfield1","customfield2","customfield3"
+"effect gmbh","Herr","Dr.","Jörg","Heinz","Geschäftsführer","Str. 25","21222","Köln","DE","022324321","","","joerg.heinz@honk.com","","","","cf1","cf2",""
+"effect gmbh","Herr","","Hans","Fritz","Technical Lead","Str. 25","21222","Köln","DE","022324321","","","hans.fritz@honk.com","","","","cf1","cf2",""
index 784eeb2..8651f2e 100644 (file)
@@ -1,3 +1,3 @@
-"org_name","salutation","title","n_given","n_family","role","adr_one_street","adr_one_postalcode","adr_one_locality","adr_one_countryname","tel_work","tel_fax","tel_cell","email","tel_fax_home","tel_home","email_home","customfield1","customfield2"\r
-"effect gmbh","Herr","Dr.","Jörg","Heinz","Geschäftsführer","Str. 25","21222","Köln","DE","022324321","","","joerg.heinz@honk.com","022324322","022324323","joerg@home.com","","cf2-2"\r
-"effect gmbh","Herr","","Hans","Fritz","Technical Lead","Str. 25","21222","Köln","DE","022324321","","","hans.fritz@honk.com","","","","cf1","cf2"\r
+"org_name","salutation","title","n_given","n_family","role","adr_one_street","adr_one_postalcode","adr_one_locality","adr_one_countryname","tel_work","tel_fax","tel_cell","email","tel_fax_home","tel_home","email_home","customfield1","customfield2","customfield3"
+"effect gmbh","Herr","Dr.","Jörg","Heinz","Geschäftsführer","Str. 25","21222","Köln","DE","022324321","","","joerg.heinz@honk.com","022324322","022324323","joerg@home.com","","cf2-2",""
+"effect gmbh","Herr","","Hans","Fritz","Technical Lead","Str. 25","21222","Köln","DE","022324321","","","hans.fritz@honk.com","","","","cf1","cf2",""
index 98b18c9..cdd9490 100644 (file)
@@ -950,7 +950,17 @@ abstract class Tinebase_Record_Abstract implements Tinebase_Record_Interface
             
             $ownField = $this->__get($fieldName);
             $recordField = $_record->$fieldName;
-            
+
+            if ($fieldName == 'customfields' && is_array($ownField) && is_array($recordField)) {
+                // special handling for customfields, remove empty customfields from array
+                foreach (array_keys($recordField, '', true) as $key) {
+                    unset($recordField[$key]);
+                }
+                foreach (array_keys($ownField, '', true) as $key) {
+                    unset($ownField[$key]);
+                }
+            }
+
             if (in_array($fieldName, $this->_datetimeFields)) {
                 if ($ownField instanceof DateTime
                     && $recordField instanceof DateTime) {