Files
api/services/nginx/app/modules/xlvask/helpers/xlvask_tasks.php
T

53 lines
1.8 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 void
* @throws Exception If the task fails
*/
public function runSyncUsers(bool $isSilent = false): void
{
// 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; // Synchronization is not enabled, do nothing
}
// Get the users from XL Vask
$tmp_xlvask = [
'customers' => $xlvask->getCustomers()
];
//echo 'XL Vask users fetched: ' . count($tmp_xlvask['customers']) . PHP_EOL;
//print_r($tmp_xlvask['customers']);
}
}