|
|
@@ -1,7 +1,7 @@
|
|
|
<?php
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
-namespace App\Service\Dolibarr\DolibarrSync;
|
|
|
+namespace App\Service\Dolibarr;
|
|
|
|
|
|
use App\Entity\Organization\Organization;
|
|
|
use App\Entity\Person\Person;
|
|
|
@@ -17,10 +17,9 @@ use App\Repository\Access\FunctionTypeRepository;
|
|
|
use App\Repository\Core\ContactPointRepository;
|
|
|
use App\Repository\Organization\OrganizationRepository;
|
|
|
use App\Service\Core\AddressPostalUtils;
|
|
|
-use App\Service\Dolibarr\DolibarrApiService;
|
|
|
-use App\Service\Dolibarr\DolibarrSync\SyncOperation\DolibarrCreateOperation;
|
|
|
-use App\Service\Dolibarr\DolibarrSync\SyncOperation\DolibarrSyncOperation;
|
|
|
-use App\Service\Dolibarr\DolibarrSync\SyncOperation\DolibarrUpdateOperation;
|
|
|
+use App\Service\Rest\Operation\BaseRestOperation;
|
|
|
+use App\Service\Rest\Operation\CreateOperation;
|
|
|
+use App\Service\Rest\Operation\UpdateOperation;
|
|
|
use Exception;
|
|
|
use HttpException;
|
|
|
use libphonenumber\PhoneNumber;
|
|
|
@@ -55,7 +54,7 @@ class DolibarrSyncService
|
|
|
*
|
|
|
* Returns an array of DolibarrSyncOperations
|
|
|
*
|
|
|
- * @return array<DolibarrSyncOperation>
|
|
|
+ * @return array<BaseRestOperation>
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public function scan(): array {
|
|
|
@@ -154,7 +153,7 @@ class DolibarrSyncService
|
|
|
|
|
|
// Add an update operation if some data has to be updated
|
|
|
if (!empty($newSocietyData)) {
|
|
|
- $operations[] = new DolibarrUpdateOperation(
|
|
|
+ $operations[] = new UpdateOperation(
|
|
|
'Update society : ' . $organization->getName() . ' (' . $organization->getId() . ')',
|
|
|
'thirdparties',
|
|
|
$dolibarrSociety,
|
|
|
@@ -211,7 +210,7 @@ class DolibarrSyncService
|
|
|
];
|
|
|
|
|
|
if ($dolibarrContact === null) {
|
|
|
- $operations[] = new DolibarrCreateOperation(
|
|
|
+ $operations[] = new CreateOperation(
|
|
|
'New contact: ' . $person->getName() . ' ' . $person->getGivenName() . ' (' . $person->getId() . ')',
|
|
|
'contacts',
|
|
|
$newContactData
|
|
|
@@ -226,7 +225,7 @@ class DolibarrSyncService
|
|
|
|
|
|
// add an update operation if some data has to be updated
|
|
|
if (!empty($newContactData)) {
|
|
|
- $operations[] = new DolibarrUpdateOperation(
|
|
|
+ $operations[] = new UpdateOperation(
|
|
|
'Update contact: ' . $person->getName() . ' ' . $person->getGivenName() . ' (' . $person->getId() . ')' .
|
|
|
' in ' . $organization->getName() . ' (' . $organization->getId() . ')',
|
|
|
'contacts',
|
|
|
@@ -249,7 +248,7 @@ class DolibarrSyncService
|
|
|
}
|
|
|
if (!in_array($personId, $contactsProcessed)) {
|
|
|
// Ce personId n'existe plus dans les membres Opentalent de cette société, on delete
|
|
|
- $operations[] = new DolibarrUpdateOperation(
|
|
|
+ $operations[] = new UpdateOperation(
|
|
|
'Disable contact: ' . $contactData['lastname'] . ' ' . $contactData['firstname'] . ' (' . $personId . ')' .
|
|
|
' from ' . $organization->getName() . ' (' . $organization->getId() . ')',
|
|
|
'contacts',
|
|
|
@@ -277,8 +276,8 @@ class DolibarrSyncService
|
|
|
*
|
|
|
* Returns an array of DolibarrSyncOperations
|
|
|
*
|
|
|
- * @param array<DolibarrSyncOperation> $operations
|
|
|
- * @return array<DolibarrSyncOperation>
|
|
|
+ * @param array<BaseRestOperation> $operations
|
|
|
+ * @return array<BaseRestOperation>
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public function execute(array $operations): array
|
|
|
@@ -288,21 +287,21 @@ class DolibarrSyncService
|
|
|
$done = 0; $errors = 0; $unknown = 0;
|
|
|
|
|
|
foreach ($operations as $operation) {
|
|
|
- if ($operation->getStatus() !== DolibarrSyncOperation::STATUS_READY) {
|
|
|
+ if ($operation->getStatus() !== BaseRestOperation::STATUS_READY) {
|
|
|
// operation has already been treated
|
|
|
$this->logger->warning('Tried to execute an operation that was not marked as ready : ' . $operation);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- $operation->execute(
|
|
|
- $this->dolibarrApiService
|
|
|
+ $operation = $this->dolibarrApiService->execute(
|
|
|
+ $operation
|
|
|
);
|
|
|
|
|
|
- if ($operation->getStatus() === DolibarrSyncOperation::STATUS_ERROR) {
|
|
|
+ if ($operation->getStatus() === BaseRestOperation::STATUS_ERROR) {
|
|
|
$this->logger->error('Error while executing operation : ' . $operation);
|
|
|
$this->logger->error($operation->getErrorMessage());
|
|
|
$errors++;
|
|
|
- } elseif ($operation->getStatus() === DolibarrSyncOperation::STATUS_DONE) {
|
|
|
+ } elseif ($operation->getStatus() === BaseRestOperation::STATUS_DONE) {
|
|
|
$done++;
|
|
|
} else {
|
|
|
$unknown++;
|
|
|
@@ -321,8 +320,8 @@ class DolibarrSyncService
|
|
|
/**
|
|
|
* Scan and execute the sync process
|
|
|
*
|
|
|
+ * @return array<BaseRestOperation>
|
|
|
* @throws HttpException
|
|
|
- * @return array<DolibarrSyncOperation>
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public function run(): array
|