|
|
@@ -54,10 +54,12 @@ class DolibarrSyncService
|
|
|
*
|
|
|
* Returns an array of DolibarrSyncOperations
|
|
|
*
|
|
|
+ * @var callable | null $progressionCallback A callback method for indicating the current progression of the process;
|
|
|
+ * Shall accept two integer arguments: current progression, and total.
|
|
|
* @return array<BaseRestOperation>
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public function scan(): array {
|
|
|
+ public function scan($progressionCallback = null): array {
|
|
|
$this->logger->info("-- Scan started --");
|
|
|
|
|
|
// Index the dolibarr clients by organization ids
|
|
|
@@ -79,6 +81,7 @@ class DolibarrSyncService
|
|
|
|
|
|
// Loop over the Opentalent organizations, and fill up the operations list
|
|
|
$operations = [];
|
|
|
+ $i = 0; $total = count($dolibarrClientsIndex);
|
|
|
foreach ($dolibarrClientsIndex as $organizationId => $dolibarrSociety) {
|
|
|
$dolibarrSociety = $this->sanitizeDolibarrData($dolibarrSociety);
|
|
|
|
|
|
@@ -247,6 +250,12 @@ class DolibarrSyncService
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // Next society
|
|
|
+ $i++;
|
|
|
+ if ($progressionCallback !== null) {
|
|
|
+ $progressionCallback($i, $total);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$this->logger->info('Scan done, ' . count($operations) . ' required operations listed');
|
|
|
@@ -267,15 +276,18 @@ class DolibarrSyncService
|
|
|
* Returns an array of DolibarrSyncOperations
|
|
|
*
|
|
|
* @param array<BaseRestOperation> $operations
|
|
|
+ * @var callable | null $progressionCallback A callback method for indicating the current progression of the process;
|
|
|
+ * Shall accept two integer arguments: current progression, and total.
|
|
|
* @return array<BaseRestOperation>
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public function execute(array $operations): array
|
|
|
+ public function execute(array $operations, $progressionCallback = null): array
|
|
|
{
|
|
|
$this->logger->info('-- Execution started --');
|
|
|
$this->logger->info(count($operations) . ' operations pending...');
|
|
|
$done = 0; $errors = 0; $unknown = 0;
|
|
|
|
|
|
+ $i = 0; $total = count($operations);
|
|
|
foreach ($operations as $operation) {
|
|
|
if ($operation->getStatus() !== BaseRestOperation::STATUS_READY) {
|
|
|
// operation has already been treated
|
|
|
@@ -296,6 +308,11 @@ class DolibarrSyncService
|
|
|
} else {
|
|
|
$unknown++;
|
|
|
}
|
|
|
+
|
|
|
+ $i++;
|
|
|
+ if ($progressionCallback !== null) {
|
|
|
+ $progressionCallback($i, $total);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$this->logger->info('Execution ended');
|