Remove app from backup sites when uninstalled

This commit is contained in:
Girish Ramakrishnan
2025-09-30 16:17:19 +02:00
parent 1e599731b8
commit edcffd3417
+4 -1
View File
@@ -171,6 +171,7 @@ const appTaskManager = require('./apptaskmanager.js'),
logs = require('./logs.js'),
mail = require('./mail.js'),
manifestFormat = require('@cloudron/manifest-format'),
mysql = require('mysql2'),
notifications = require('./notifications.js'),
once = require('./once.js'),
path = require('node:path'),
@@ -1133,11 +1134,13 @@ async function del(id) {
{ query: 'DELETE FROM appEnvVars WHERE appId = ?', args: [ id ] },
{ query: 'DELETE FROM appPasswords WHERE identifier = ?', args: [ id ] },
{ query: 'DELETE FROM appMounts WHERE appId = ?', args: [ id ] },
// this removes double quoted "appId" with optional trailing comma from the JSON
{ query: `UPDATE backupSites SET contentsJson = REGEXP_REPLACE(contentsJson, ${mysql.escape('"' + id + '"(,)?')}, '') WHERE contentsJson LIKE ${mysql.escape('%"' + id + '"%')}`, args: [] },
{ query: 'DELETE FROM apps WHERE id = ?', args: [ id ] }
];
const results = await database.transaction(queries);
if (results[5].affectedRows !== 1) throw new BoxError(BoxError.NOT_FOUND, 'App not found');
if (results[6].affectedRows !== 1) throw new BoxError(BoxError.NOT_FOUND, 'App not found');
}
async function clear() {