transactions

This commit is contained in:
Shish 2020-10-27 22:03:56 +00:00
parent a4ff796b35
commit 81fe37de50
2 changed files with 8 additions and 4 deletions

View File

@ -281,14 +281,18 @@ function create_tables(Database $db)
$db->execute("CREATE INDEX images_tags_tag_id_idx ON image_tags(tag_id)", []);
$db->execute("INSERT INTO config(name, value) VALUES('db_version', 11)");
$db->commit();
// mysql auto-commits when creating a table, so the transaction
// is closed; other databases need to commit
if($db->is_transaction_open()) {
$db->commit();
}
} catch (PDOException $e) {
throw new InstallerException(
"PDO Error:",
"<p>An error occurred while trying to create the database tables necessary for Shimmie.</p>
<p>Please check and ensure that the database configuration options are all correct.</p>
<p>{$e->getMessage()}</p>
<!-- {$e->getTraceAsString()} -->
",
3
);

View File

@ -83,7 +83,7 @@ try {
$page->display();
}
if ($database->transaction===true) {
if ($database->is_transaction_open()) {
$database->commit();
}
@ -92,7 +92,7 @@ try {
fastcgi_finish_request();
}
} catch (Exception $e) {
if ($database && $database->transaction===true) {
if ($database && $database->is_transaction_open()) {
$database->rollback();
}
_fatal_error($e);