fix: [CLI] Authkey valid - reconnect in case of failure

pull/8072/head
Jakub Onderka 2022-01-04 10:40:54 +01:00
parent b2343fc95d
commit 281b6e837f
1 changed files with 20 additions and 4 deletions

View File

@ -187,11 +187,27 @@ class UserShell extends AppShell
continue;
}
if (Configure::read('Security.advanced_authkeys')) {
$user = $this->User->AuthKey->getAuthUserByAuthKey($authkey);
} else {
$user = $this->User->getAuthUserByAuthkey($authkey);
$user = false;
for ($i = 0; $i < 5; $i++) {
try {
if (Configure::read('Security.advanced_authkeys')) {
$user = $this->User->AuthKey->getAuthUserByAuthKey($authkey);
} else {
$user = $this->User->getAuthUserByAuthkey($authkey);
}
break;
} catch (PDOException $e) {
$this->log($e->getMessage());
// Reconnect in case of failure and try again
try {
$this->User->getDataSource()->connect();
} catch (MissingConnectionException $e) {
sleep(1);
$this->log($e->getMessage());
}
}
}
$user = (bool)$user;
// Cache results for 5 seconds
$cache[$keyHash] = [$user, $time + 5];