Skip to content

Commit ee15326

Browse files
committed
fix: solve issues with unclosed connections (#1310)
1 parent 605ee46 commit ee15326

File tree

7 files changed

+42
-18
lines changed

7 files changed

+42
-18
lines changed

app/back-end/app.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,12 @@ class App {
212212
return { status: false };
213213
}
214214

215-
if (this.db && this.db.isOpen) {
216-
this.db.close();
215+
if (this.db) {
216+
try {
217+
this.db.close();
218+
} catch (e) {
219+
console.log('[SWITCH WEBSITE] DB already closed');
220+
}
217221
}
218222

219223
this.db = new DBUtils(new Database(dbPath));

app/back-end/events/app.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ class AppEvents {
4444
if (appInstance.appConfig.sitesLocation) {
4545
let appFilesHelper = new AppFiles(appInstance);
4646

47-
if (appInstance.db && appInstance.db.isOpen) {
48-
appInstance.db.close();
47+
if (appInstance.db) {
48+
try {
49+
appInstance.db.close();
50+
} catch (e) {
51+
console.log('[SITE LOCATION CHANGE] DB already closed');
52+
}
4953
}
5054

5155
setTimeout(() => {

app/back-end/events/site.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@ class SiteEvents {
7070
!fs.existsSync(path.join(appInstance.sitesDir, config.settings.name)) &&
7171
slug(config.settings.displayName) === config.settings.name
7272
) {
73-
if (appInstance.db && appInstance.db.isOpen) {
74-
appInstance.db.close();
73+
if (appInstance.db) {
74+
try {
75+
appInstance.db.close();
76+
} catch (e) {
77+
console.log('[SITE NAME CHANGE] DB already closed');
78+
}
7579
}
7680

7781
// If yes - rename the dir
@@ -431,8 +435,12 @@ class SiteEvents {
431435
let siteDir = path.join(appInstance.sitesDir, config.name);
432436
let dbPath = path.join(siteDir, 'input', 'db.sqlite');
433437

434-
if (appInstance.db && appInstance.db.isOpen) {
435-
appInstance.db.close();
438+
if (appInstance.db) {
439+
try {
440+
appInstance.db.close();
441+
} catch (e) {
442+
console.log('[SITE CREATION] DB already closed');
443+
}
436444
}
437445

438446
appInstance.db = new DBUtils(new Database(dbPath));

app/back-end/modules/backup/backup.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,12 @@ class Backup {
277277
}
278278

279279
// Close DB connection and remove site dir contents
280-
if (appInstance.db && appInstance.db.isOpen) {
281-
appInstance.db.close();
280+
if (appInstance.db) {
281+
try {
282+
appInstance.db.close();
283+
} catch (e) {
284+
console.log('[BACKUP RESTORE] DB already closed');
285+
}
282286
}
283287

284288
fs.emptyDirSync(destinationPath);

app/back-end/modules/import/import.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ class Import {
3636

3737
const dbPath = path.join(this.appInstance.sitesDir, this.siteName, 'input', 'db.sqlite');
3838

39-
if (this.appInstance.db && this.appInstance.db.isOpen) {
40-
this.appInstance.db.close();
39+
if (this.appInstance.db) {
40+
try {
41+
this.appInstance.db.close();
42+
} catch (e) {
43+
console.log('[WP IMPORT] DB already closed');
44+
}
4145
}
4246

4347
this.appInstance.db = new DBUtils(new Database(dbPath));

app/back-end/site.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,12 @@ class Site {
434434
static delete(appInstance, name) {
435435
let sitePath = path.join(appInstance.sitesDir, name);
436436

437-
if (appInstance.db && appInstance.db.isOpen) {
438-
appInstance.db.close();
437+
if (appInstance.db) {
438+
try {
439+
appInstance.db.close();
440+
} catch (e) {
441+
console.log('[SITE DELETE] DB already closed');
442+
}
439443
}
440444

441445
setTimeout(async () => {

app/src/components/Backups.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@
115115
</p-button>
116116

117117
<p-button
118-
v-if="!isWin"
119118
:type="operationInProgress ? 'disabled secondary small' : 'secondary small'"
120119
:onClick="restoreFile.bind(this, item.name)"
121120
:disabled="operationInProgress">
@@ -148,9 +147,6 @@ export default {
148147
};
149148
},
150149
computed: {
151-
isWin () {
152-
return document.body.getAttribute('data-os') === 'win';
153-
},
154150
noBackups () {
155151
return this.items.length === 0;
156152
}

0 commit comments

Comments
 (0)