From fb6d64a8ed3e20623fed5c219bed701dba3b854e Mon Sep 17 00:00:00 2001 From: ralf Date: Mon, 29 Jan 2024 14:09:05 +0200 Subject: [PATCH] * Account Import: if deleting or deactivating of deleted accounts is configured, run first import as a non-incremental one to do so --- api/src/Accounts/Import.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/api/src/Accounts/Import.php b/api/src/Accounts/Import.php index af1b790be7..cb0c93de65 100644 --- a/api/src/Accounts/Import.php +++ b/api/src/Accounts/Import.php @@ -937,7 +937,9 @@ class Import const LOG_FILE = 'setup/account-import.log'; /** - * Run incremental import via async job + * Run import via async job + * + * First daily run is a full import, if deleting or deactivating accounts is configured, all others are incremental imports * * @return void */ @@ -946,7 +948,8 @@ class Import try { $import = new self(); $import->logger(date('Y-m-d H:i:s O').' LDAP account import started', 'info'); - $import->run(false); + $import->run(in_array($GLOBALS['egw_info']['server']['account_import_delete'] ?? 'no', ['yes', 'deactivate']) && + self::firstRunToday()); $import->logger(date('Y-m-d H:i:s O').' LDAP account import finished', 'info'); } catch (\InvalidArgumentException $e) { @@ -961,6 +964,21 @@ class Import } } + /** + * Check if current time / run is the first one for today + * + * @return bool + */ + public static function firstRunToday() + { + if (empty($frequency=$GLOBALS['egw_info']['server']['account_import_frequency'])) + { + return false; + } + // check current time <= time of first run today (frequency is in hours) + return time() <= mktime(ceil($frequency), round((60*$frequency)%60), 60); // 60 seconds grace time + } + /** * Tail the async import log *