From d790d9106b81dcaa37f93bb8fff580cca70b5ab6 Mon Sep 17 00:00:00 2001 From: velz Date: Mon, 20 Apr 2026 15:44:29 +0530 Subject: [PATCH] FEAT_CRON_REST_TOKEN_TIMEOUT --- app/Config/Routes.php | 2 + .../RestAuthenticationController.php | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 1531645b..15c4aa0a 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -560,6 +560,8 @@ $routes->cli('cli/send_mail_cli', 'MasterController::testGmailAPIViaCLI'); $routes->cli('cli/sendZeptoMail', 'MasterController::testZeptoSMTP'); $routes->cli('cli/check_bounce_mail_cli', 'MasterController::testCheckBounceMails'); $routes->cli('cli/app_check_list', 'MasterController::appCheckList'); +$routes->cli('cli/reset-token-timeout', 'RestAuthenticationController::resetTokenTimeOut'); +$routes->cli('cli/reset-token-timeout/(:num)', 'RestAuthenticationController::resetTokenTimeOut/$1'); $routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDriveAccessToken'); $routes->cli('cli/list-sheet-folder-files', 'GoogleSheetController::listFolderSheetFilesCli'); $routes->cli('cli/list-sheet-folder-files/(:any)', 'GoogleSheetController::listFolderSheetFilesCli/$1'); diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 2265bd1b..ae85137b 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -2377,4 +2377,52 @@ class RestAuthenticationController extends AdminController ], 200); } + public function resetTokenTimeOut($bufferSeconds = null) + { + if (!is_cli()) { + return $this->respond([ + 'status' => false, + 'message' => 'This endpoint is CLI only.' + ], 403); + } + + $envBuffer = (int) (getenv('TOKEN_TIMEOUT_RESET_BUFFER_SECONDS') ?: 300); + $buffer = is_numeric($bufferSeconds) ? (int) $bufferSeconds : $envBuffer; + if ($buffer < 0) { + $buffer = 0; + } + + $cutoffEpoch = time() - $buffer; + $db = db_connect(); + + $db->table('level_contacts') + ->where('token_time_out IS NOT NULL', null, false) + ->where('token_time_out <=', $cutoffEpoch) + ->set(['token_time_out' => null]) + ->update(); + $levelContactsUpdated = $db->affectedRows(); + + $db->table('employees') + ->where('token_time_out IS NOT NULL', null, false) + ->where('token_time_out <=', $cutoffEpoch) + ->set(['token_time_out' => null]) + ->update(); + $employeesUpdated = $db->affectedRows(); + + $result = [ + 'status' => true, + 'message' => 'Token timeout reset completed.', + 'buffer_seconds' => $buffer, + 'cutoff_epoch' => $cutoffEpoch, + 'updated' => [ + 'level_contacts' => $levelContactsUpdated, + 'employees' => $employeesUpdated, + 'total' => $levelContactsUpdated + $employeesUpdated, + ], + ]; + + echo json_encode($result, JSON_UNESCAPED_SLASHES) . PHP_EOL; + return; + } + } \ No newline at end of file