Skip to content

Commit 02ce717

Browse files
committed
fix: prevent sql error when updating to admidio 5.0 and no changelog table is present
1 parent 9705655 commit 02ce717

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Infrastructure/Database.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,25 @@ public function getVersion(): string
487487
return $version;
488488
}
489489

490+
/**
491+
* Method checks if a table exists in the current database.
492+
* @param string $tableName
493+
* @return bool
494+
* @throws Exception
495+
*/
496+
public function tableExists(string $tableName): bool
497+
{
498+
$tableExists = false;
499+
500+
$sql = 'SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ? AND table_name = ?';
501+
$statement = $this->queryPrepared($sql, array(DB_NAME, $tableName));
502+
if ($statement->fetchColumn() > 0) {
503+
$tableExists = true;
504+
}
505+
506+
return $tableExists;
507+
}
508+
490509
/**
491510
* Method gets all columns and their properties from the database table.
492511
*

system/common.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,14 @@
232232

233233
// update session recordset (i.a. refresh timestamp)
234234
$gCurrentSession->setValue('ses_reload', 0);
235-
$gCurrentSession->save();
235+
if ($gCurrentSession->isNewRecord() && !$gDb->tableExists(TBL_LOG)) {
236+
//temporary disable logging cause log table doesn't exist yet
237+
$gCurrentSession->setLoggingEnabled(false);
238+
$gCurrentSession->save();
239+
$gCurrentSession->setLoggingEnabled(true);
240+
} else {
241+
$gCurrentSession->save();
242+
}
236243

237244
// create the necessary objects and parameters
238245

0 commit comments

Comments
 (0)