Browse Source

ignore empty phones, emails or addresses

Olivier Massot 1 year ago
parent
commit
e83dc72f4f

+ 6 - 6
src/Service/Dolibarr/DolibarrSyncService.php

@@ -152,15 +152,15 @@ class DolibarrSyncService
                 $newSocietyData['address'] = $streetAddress;
                 $newSocietyData['zip'] = $mainAddress->getPostalCode();
                 $newSocietyData['town'] = $mainAddress->getAddressCity();
-            } else {
-                $newSocietyData['address'] = null;
-                $newSocietyData['zip'] = null;
-                $newSocietyData['town'] = null;
             }
 
             // Sync contact
-            $newSocietyData['email'] = $this->getOrganizationEmail($organization);
-            $newSocietyData['phone'] = $this->getOrganizationPhone($organization);
+            if (!empty($this->getOrganizationEmail($organization))) {
+                $newSocietyData['email'] = $this->getOrganizationEmail($organization);
+            }
+            if (!empty($this->getOrganizationPhone($organization))) {
+                $newSocietyData['phone'] = $this->getOrganizationPhone($organization);
+            }
 
             // Sync Network
             if (!in_array($organization->getId(), [NetworkEnum::CMF, NetworkEnum::FFEC], true)) {

+ 0 - 7
tests/Unit/Service/Dolibarr/DolibarrSyncServiceTest.php

@@ -366,7 +366,6 @@ class DolibarrSyncServiceTest extends TestCase
         $addressPostal->method('getAddressCity')->willReturn($organizationData1['city']);
 
         $dolibarrSyncService
-            ->expects(self::exactly(2))
             ->method('getOrganizationEmail')
             ->willReturnMap([
                 [$organization1, $organizationData1['email']],
@@ -374,7 +373,6 @@ class DolibarrSyncServiceTest extends TestCase
             ]);
 
         $dolibarrSyncService
-            ->expects(self::exactly(2))
             ->method('getOrganizationPhone')
             ->willReturnMap([
                 [$organization1, $organizationData1['phone']],
@@ -588,14 +586,9 @@ class DolibarrSyncServiceTest extends TestCase
         $this->assertEqualsCanonicalizing(
             [
                 '[PUT thirdparties/2]',
-                'address : (new) => ``',
-                'email : (new) => ``',
                 'name : (new) => `Organization 20`',
                 'parent : (new) => ``',
-                'phone : (new) => ``',
                 'status : (new) => `1`',
-                'town : (new) => ``',
-                'zip : (new) => ``',
                 'array_options.options_2iopen_software_opentalent : (new) => `Opentalent Artist`',
                 "array_options.options_2iopeninfoopentalent : (new) => `Nombre d'adhérents : 0\nNombre d'accès admin : 2`",
             ],