FEAT_TOKENTIMEOUT_RESET_CRON
This commit is contained in:
parent
74dee4f797
commit
08677485fc
@ -439,6 +439,8 @@ $routes->cli('cli/check_bounce_mail_cli', 'MasterController::testCheckBounceMail
|
|||||||
$routes->cli('cli/app_check_list', 'MasterController::appCheckList');
|
$routes->cli('cli/app_check_list', 'MasterController::appCheckList');
|
||||||
$routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDriveAccessToken');
|
$routes->cli('cli/new_gdrive_token', 'GoogleDriveController::generateNewGoogleDriveAccessToken');
|
||||||
$routes->cli('cli/check_env', 'MasterController::checkEnv');
|
$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');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1962,6 +1962,11 @@ class RestAuthenticationController extends AdminController
|
|||||||
|
|
||||||
public function logout()
|
public function logout()
|
||||||
{
|
{
|
||||||
|
return $this->respond([
|
||||||
|
'status' => true,
|
||||||
|
'message' => 'Logged out successfully'
|
||||||
|
], 200);
|
||||||
|
|
||||||
$authHeader = $this->request->getHeaderLine('Authorization');
|
$authHeader = $this->request->getHeaderLine('Authorization');
|
||||||
|
|
||||||
if (!$authHeader) {
|
if (!$authHeader) {
|
||||||
@ -2009,5 +2014,54 @@ class RestAuthenticationController extends AdminController
|
|||||||
], 200);
|
], 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user