FEAT_TOKENTIMEOUT_RESET_CRON

This commit is contained in:
velz 2026-04-20 15:48:53 +05:30
parent 74dee4f797
commit 08677485fc
2 changed files with 56 additions and 0 deletions

View File

@ -439,6 +439,8 @@ $routes->cli('cli/check_bounce_mail_cli', 'MasterController::testCheckBounceMail
$routes->cli('cli/app_check_list', 'MasterController::appCheckList');
$routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDriveAccessToken');
$routes->cli('cli/check_env', 'MasterController::checkEnv');
$routes->cli('cli/reset-token-timeout', 'RestAuthenticationController::resetTokenTimeOut');
$routes->cli('cli/reset-token-timeout/(:num)', 'RestAuthenticationController::resetTokenTimeOut/$1');

View File

@ -1962,6 +1962,11 @@ class RestAuthenticationController extends AdminController
public function logout()
{
return $this->respond([
'status' => true,
'message' => 'Logged out successfully'
], 200);
$authHeader = $this->request->getHeaderLine('Authorization');
if (!$authHeader) {
@ -2009,5 +2014,54 @@ 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;
}
}