58 lines
2.2 KiB
PHP
58 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace helpers;
|
|
|
|
use Exception;
|
|
|
|
class xlvask_tasks
|
|
{
|
|
public function __construct()
|
|
{
|
|
// Define the error messages if they are not already defined
|
|
/**
|
|
* if (!defined("ERROR_MESSAGE_ECONOMIC_INVOICE_NOT_FOUND")) {
|
|
* define("ERROR_MESSAGE_ECONOMIC_INVOICE_NOT_FOUND", 'ECONOMIC_INVOICE_NOT_FOUND');
|
|
* }
|
|
* if (!defined("ERROR_MESSAGE_ECONOMIC_INVOICE_DRAFT_NOT_FOUND")) {
|
|
* define("ERROR_MESSAGE_ECONOMIC_INVOICE_DRAFT_NOT_FOUND", 'ECONOMIC_INVOICE_DRAFT_NOT_FOUND');
|
|
* }
|
|
*/
|
|
}
|
|
|
|
/**
|
|
* Run the synchronize users task
|
|
* This task fetches the users from XL Vask, and synchronizes them with this system.
|
|
* This includes:
|
|
* - Fetching the users from XL Vask
|
|
* - Checking if the users exist in this system
|
|
* - Creating the users if they do not exist
|
|
* - Add/Remove the associated external id to the users in this system
|
|
* @return null|array['customers'] The customers fetched from XL Vask, null if synchronization is not enabled
|
|
* @throws Exception If the task fails
|
|
*/
|
|
public function runSyncUsers(bool $isSilent = false): array|null
|
|
{
|
|
// Define the XL Vask object
|
|
$xlvask = new \classes\xlvask();
|
|
// Require the module to be enabled
|
|
$xlvask->requireModuleEnabled();
|
|
// Check if synchronization is enabled
|
|
if (!$xlvask->config->synchronization_enabled->isTrue()) {
|
|
if (!$isSilent) {
|
|
throw new Exception('XL Vask synchronization is not enabled.');
|
|
}
|
|
return null; // Synchronization is not enabled, do nothing
|
|
}
|
|
// Get the users from XL Vask
|
|
$customer_objects_raw = $xlvask->getCustomers();
|
|
// Parse the users into customer objects
|
|
$customer_objects = array_map(function ($customer) use ($xlvask) {
|
|
return (new $xlvask->helpers->xlvask_customer())->setProperties($customer);
|
|
}, $customer_objects_raw);
|
|
$tmp_xlvask = [
|
|
'customers' => $customer_objects,
|
|
];
|
|
//echo 'XL Vask users fetched:' . count($tmp_xlvask['customers']) . PHP_EOL;
|
|
return $tmp_xlvask['customers'];
|
|
}
|
|
} |