Write threads db in a transaction to avoid losing thread data.
This commit is contained in:
parent
4f95842cec
commit
993183eb84
|
@ -95,16 +95,21 @@ function thread_cache_save($headers, $group)
|
|||
$database = $spooldir . '/' . $group . '-data.db3';
|
||||
$table = "threads";
|
||||
if ($dbh = threads_db_open($database, $table)) {
|
||||
$drop = 'DROP TABLE IF EXISTS '. $table;
|
||||
$drop = 'DROP TABLE IF EXISTS threads';
|
||||
$drop_stmt = $dbh->prepare($drop);
|
||||
$insert_sql = 'INSERT INTO ' . $table . '(headers) VALUES(?)';
|
||||
$insert_stmt = $dbh->prepare($insert_sql);
|
||||
|
||||
$dbh->beginTransaction();
|
||||
$drop_stmt->execute();
|
||||
$dbh = null;
|
||||
$dbh = threads_db_open($database, $table);
|
||||
$sql = 'INSERT INTO ' . $table . '(headers) VALUES(?)';
|
||||
$stmt = $dbh->prepare($sql);
|
||||
$stmt->execute([
|
||||
$dbh->exec("CREATE TABLE IF NOT EXISTS $table(
|
||||
id INTEGER PRIMARY KEY,
|
||||
headers TEXT,
|
||||
unique (headers))");
|
||||
$insert_stmt->execute([
|
||||
serialize($headers)
|
||||
]);
|
||||
$dbh->commit();
|
||||
$dbh = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1498,8 +1498,6 @@ function threads_db_open($database, $table = "threads")
|
|||
id INTEGER PRIMARY KEY,
|
||||
headers TEXT,
|
||||
unique (headers))");
|
||||
$stmt = $dbh->query('CREATE INDEX IF NOT EXISTS id_headers on ' . $table . '(headers)');
|
||||
$stmt->execute();
|
||||
return ($dbh);
|
||||
}
|
||||
|
||||
|
@ -1823,7 +1821,8 @@ function add_to_history($group, $number, $msgid, $status, $statusdate, $statusre
|
|||
$history_dbh = null;
|
||||
}
|
||||
|
||||
function clear_history_by_group($group) {
|
||||
function clear_history_by_group($group)
|
||||
{
|
||||
global $spooldir;
|
||||
$history = $spooldir . '/history.db3';
|
||||
$history_dbh = history_db_open($history);
|
||||
|
|
Loading…
Reference in New Issue