Browse Source

add the last sync date to structures and contacts on dolibarr sync

Olivier Massot 1 năm trước cách đây
mục cha
commit
9603c87a50
1 tập tin đã thay đổi với 12 bổ sung1 xóa
  1. 12 1
      src/Service/Dolibarr/DolibarrSyncService.php

+ 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
                     );
                 }