⚙ settings saving improvements + refactor - DB lock v0.1 #685
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
// DB File Path
|
||||
$DBFILE = dirname(__FILE__).'/../../../db/app.db';
|
||||
|
||||
$db_locked = false;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Connect DB
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -20,12 +22,21 @@ function SQLite3_connect ($trytoreconnect) {
|
||||
try
|
||||
{
|
||||
// connect to database
|
||||
|
||||
global $db_locked;
|
||||
|
||||
$db_locked = false;
|
||||
|
||||
// return new SQLite3($DBFILE, SQLITE3_OPEN_READONLY);
|
||||
return new SQLite3($DBFILE, SQLITE3_OPEN_READWRITE);
|
||||
}
|
||||
catch (Exception $exception)
|
||||
{
|
||||
// sqlite3 throws an exception when it is unable to connect
|
||||
global $db_locked;
|
||||
|
||||
$db_locked = true;
|
||||
|
||||
// try to reconnect one time after 3 seconds
|
||||
|
||||
if($trytoreconnect)
|
||||
|
||||
@@ -269,16 +269,26 @@ function delete($columnName, $id, $dbtable)
|
||||
// check if the database is locked
|
||||
//------------------------------------------------------------------------------
|
||||
function checkLock() {
|
||||
global $db;
|
||||
try {
|
||||
$db->exec('BEGIN EXCLUSIVE TRANSACTION');
|
||||
$db->exec('COMMIT');
|
||||
echo 0; // Not locked
|
||||
return 0;
|
||||
} catch (Exception $e) {
|
||||
echo 1; // Locked
|
||||
return 1;
|
||||
global $DBFILE, $db_locked;
|
||||
|
||||
$file = fopen($DBFILE, 'r+');
|
||||
|
||||
if (!$file or $db_locked) {
|
||||
echo 1; // Could not open the file
|
||||
return;
|
||||
}
|
||||
|
||||
if (flock($file, LOCK_EX | LOCK_NB)) {
|
||||
// Lock acquired, meaning the database is not locked by another process
|
||||
flock($file, LOCK_UN); // Release the lock
|
||||
echo 0; // Not locked
|
||||
} else {
|
||||
// Could not acquire lock, meaning the database is locked
|
||||
echo 1; // Locked
|
||||
}
|
||||
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -387,8 +387,10 @@ function saveSettings()
|
||||
// Replace the original file with the temporary file
|
||||
rename($tempConfPath, $fullConfPath);
|
||||
|
||||
displayMessage("<br/>Settings saved to the <code>app.conf</code> file.<br/><br/>A time-stamped backup of the previous file created. <br/><br/> Reloading...<br/>",
|
||||
FALSE, TRUE, TRUE, TRUE);
|
||||
// displayMessage(lang('settings_saved'),
|
||||
// FALSE, TRUE, TRUE, TRUE);
|
||||
|
||||
echo "OK";
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -657,7 +657,7 @@
|
||||
"settings_imported": "Last time settings were imported from the app.conf file",
|
||||
"settings_imported_label": "Settings imported",
|
||||
"settings_missing": "Not all settings loaded! High load on the database or app startup sequence. Click the 🔄 reload button in the top.",
|
||||
"settings_missing_block": "Not all settings were loaded correctly. This is probably caused by a high load on the database. Click the 🔄 reload button in the top.",
|
||||
"settings_missing_block": "Error: Settings not loaded correctly. Click the reload button 🔄 at the top, alternatively, check the browser log for details (F12).",
|
||||
"settings_old": "Importing settings and re-initializing...",
|
||||
"settings_other_scanners": "Other, non-device scanner plugins that are currently enabled.",
|
||||
"settings_other_scanners_icon": "fa-solid fa-recycle",
|
||||
@@ -665,7 +665,7 @@
|
||||
"settings_publishers": "Enabled notification gateways - publishers, that will send a notification depending on your settings.",
|
||||
"settings_publishers_icon": "fa-solid fa-comment-dots",
|
||||
"settings_publishers_label": "Publishers",
|
||||
"settings_saved": "<br/>Settings saved to the <code>app.conf</code> file.<br/><br/>A time-stamped backup of the previous file created. <br/><br/> Reloading...<br/>",
|
||||
"settings_saved": "<br/>Settings saved. <br/><br/> Reloading... <br/><br/> <i class=\"ion ion-ios-loop-strong fa-spin fa-2x fa-fw\"></i> <br/>",
|
||||
"settings_system_icon": "fa-solid fa-gear",
|
||||
"settings_system_label": "System",
|
||||
"settings_update_item_warning": "Update the value below. Be careful to follow the previous format. <b>Validation is not performed.</b>",
|
||||
|
||||
@@ -147,7 +147,7 @@
|
||||
|
||||
|
||||
<!-- Alert float -->
|
||||
<div id="notification" class="alert alert-dimissible pa_alert_notification">
|
||||
<div id="notification" >
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<div id="alert-message"> Alert message </div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user