Browse Source

Merge branch 'feature/V8-3979-ajouter-la-date-de-dernire-synch' into develop

Olivier Massot 1 year ago
parent
commit
7601733e65

+ 12 - 1
src/Service/Dolibarr/DolibarrSyncService.php

@@ -27,6 +27,7 @@ use App\Service\Rest\Operation\CreateOperation;
 use App\Service\Rest\Operation\DeleteOperation;
 use App\Service\Rest\Operation\UpdateOperation;
 use App\Service\Utils\ArrayUtils;
+use App\Service\Utils\DatesUtils;
 use libphonenumber\PhoneNumber;
 use libphonenumber\PhoneNumberFormat;
 use libphonenumber\PhoneNumberUtil;
@@ -214,6 +215,8 @@ class DolibarrSyncService
 
             // Add an update operation if some data has to be updated
             if (!empty($newSocietyData)) {
+                $newSocietyData['array_options']['options_2iopen_last_sync_date'] = DatesUtils::new()->format('c');
+
                 $operations[] = new UpdateOperation(
                     'Update society : '.$organization->getName().' ('.$organization->getId().')',
                     'thirdparties',
@@ -274,6 +277,7 @@ class DolibarrSyncService
                 if (null === $dolibarrContact) {
                     // New contact
                     $newContactData['socid'] = $dolibarrSocietyId;
+                    $newContactData['array_options']['options_2iopen_last_sync_date'] = DatesUtils::new()->format('c');
 
                     $operations[] = new CreateOperation(
                         'New contact: '.$person->getName().' '.$person->getGivenName().' ('.$person->getId().')',
@@ -291,6 +295,8 @@ class DolibarrSyncService
 
                     // add an update operation if some data has to be updated
                     if (!empty($newContactData)) {
+                        $newContactData['array_options']['options_2iopen_last_sync_date'] = DatesUtils::new()->format('c');
+
                         $operations[] = new UpdateOperation(
                             'Update contact: '.$person->getName().' '.$person->getGivenName().' ('.$person->getId().')'.
                             ' in '.$organization->getName().' ('.$organization->getId().')',
@@ -314,12 +320,17 @@ class DolibarrSyncService
                 }
                 if (!in_array($personId, $contactsProcessed, true)) {
                     // Ce personId n'existe plus dans les membres Opentalent de cette société, on delete
+                    $newContactData = [
+                        'statut' => '0',
+                        'array_options' => ['options_2iopen_last_sync_date' => DatesUtils::new()->format('c')],
+                    ];
+
                     $operations[] = new UpdateOperation(
                         'Disable contact: '.$contactData['lastname'].' '.$contactData['firstname'].' ('.$personId.')'.
                         ' from  '.$organization->getName().' ('.$organization->getId().')',
                         'contacts',
                         (int) $contactData['id'],
-                        ['statut' => '0'],
+                        $newContactData,
                         $contactData
                     );
                 }

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

@@ -34,6 +34,7 @@ use App\Service\Rest\Operation\CreateOperation;
 use App\Service\Rest\Operation\DeleteOperation;
 use App\Service\Rest\Operation\UpdateOperation;
 use App\Service\Utils\ArrayUtils;
+use App\Service\Utils\DatesUtils;
 use Doctrine\Common\Collections\ArrayCollection;
 use libphonenumber\PhoneNumber;
 use libphonenumber\PhoneNumberUtil;
@@ -165,6 +166,11 @@ class DolibarrSyncServiceTest extends TestCase
         $this->logger->method('error')->willReturnSelf();
     }
 
+    public function tearDown(): void
+    {
+        DatesUtils::clearFakeDatetime();
+    }
+
     private function getMockForMethod(string $method)
     {
         $dolibarrSyncService = $this->getMockBuilder(TestableDolibarrSyncService::class)
@@ -581,6 +587,8 @@ class DolibarrSyncServiceTest extends TestCase
             }
         };
 
+        DatesUtils::setFakeDatetime('2024-01-01T00:00:00+00:00');
+
         $operations = $dolibarrSyncService->scan($progressionCallback);
 
         $this->assertCount(8, $operations);
@@ -596,6 +604,7 @@ class DolibarrSyncServiceTest extends TestCase
                 'parent : `0` => `12098`',
                 'array_options.options_2iopen_software_opentalent : `Opentalent Artist` => `Opentalent School`',
                 "array_options.options_2iopeninfoopentalent : `` => `Nombre d'élèves : 1\nNombre d'adhérents : 2\nNombre d'accès admin : 1`",
+                'array_options.options_2iopen_last_sync_date : (new) => `2024-01-01T00:00:00+00:00`',
                 'status : `0` => `1`',
             ],
             $operations[0]->getChangeLog()
@@ -612,6 +621,7 @@ class DolibarrSyncServiceTest extends TestCase
                 'phone_mobile : `+33682980000` => `0607080910`',
                 'poste : `Secrétaire` => `Président`',
                 'array_options.options_2iopen_person_id : `` => `100`',
+                'array_options.options_2iopen_last_sync_date : (new) => `2024-01-01T00:00:00+00:00`',
             ],
             $operations[1]->getChangeLog()
         );
@@ -620,6 +630,7 @@ class DolibarrSyncServiceTest extends TestCase
             [
                 '[PUT contacts/4]',
                 'statut : `1` => `0`',
+                'array_options.options_2iopen_last_sync_date : (new) => `2024-01-01T00:00:00+00:00`',
             ],
             $operations[2]->getChangeLog()
         );
@@ -651,6 +662,7 @@ class DolibarrSyncServiceTest extends TestCase
                 '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`",
+                'array_options.options_2iopen_last_sync_date : (new) => `2024-01-01T00:00:00+00:00`',
             ],
             $operations[5]->getChangeLog()
         );
@@ -667,6 +679,7 @@ class DolibarrSyncServiceTest extends TestCase
                 'poste : (new) => `Président(e)`',
                 'statut : (new) => `1`',
                 'array_options.options_2iopen_person_id : (new) => `200`',
+                'array_options.options_2iopen_last_sync_date : (new) => `2024-01-01T00:00:00+00:00`',
                 'socid : (new) => `2`',
             ],
             $operations[6]->getChangeLog()