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,7 +89,10 @@ if (
/** /**
* Persistent (stay logged in) * Persistent (stay logged in)
*/ */
if (isset($_COOKIE[COOKIE_PERSISTENT])) { if (isset($_COOKIE[COOKIE_PERSISTENT]) && $database) {
$table_sessions_exists = $database->tableExists('sessions');
if ($table_sessions_exists) {
$persistent = $database $persistent = $database
->query( ->query(
'SELECT * 'SELECT *
@ -101,6 +104,7 @@ if (isset($_COOKIE[COOKIE_PERSISTENT])) {
if (false !== $persistent) { if (false !== $persistent) {
$_SESSION['user'] = User::getFromID($persistent['user']); $_SESSION['user'] = User::getFromID($persistent['user']);
} }
}
} }
/** /**

View file

@ -50,4 +50,25 @@ class Database
{ {
return $this->lastInsertId; 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;
}
} }