Fix error during install

This commit is contained in:
grandeljay 2022-10-31 13:11:35 +01:00
parent 57825a2a1c
commit d76d66be20
2 changed files with 35 additions and 10 deletions

View file

@ -89,17 +89,21 @@ if (
/**
* Persistent (stay logged in)
*/
if (isset($_COOKIE[COOKIE_PERSISTENT])) {
$persistent = $database
->query(
'SELECT *
FROM `sessions`
WHERE `session` = "' . $_COOKIE[COOKIE_PERSISTENT] . '";'
)
->fetch();
if (isset($_COOKIE[COOKIE_PERSISTENT]) && $database) {
$table_sessions_exists = $database->tableExists('sessions');
if (false !== $persistent) {
$_SESSION['user'] = User::getFromID($persistent['user']);
if ($table_sessions_exists) {
$persistent = $database
->query(
'SELECT *
FROM `sessions`
WHERE `session` = "' . $_COOKIE[COOKIE_PERSISTENT] . '";'
)
->fetch();
if (false !== $persistent) {
$_SESSION['user'] = User::getFromID($persistent['user']);
}
}
}

View file

@ -50,4 +50,25 @@ class Database
{
return $this->lastInsertId;
}
public function tableExists(string $table_to_check): bool
{
$tables = $this
->query('SHOW TABLES;')
->fetchAll();
if (!is_iterable($tables)) {
return false;
}
foreach ($tables as $table_kv) {
$table = reset($table_kv);
if ($table === $table_to_check) {
return true;
}
}
return false;
}
}