From 1be0e9b7a9a5ebf67a3cd835d4cf8a07d0652cfb Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 19 Jul 2022 12:40:52 +0200 Subject: [PATCH 1/5] feat: delete dms trash file --- back/methods/dms/deleteTrashFiles.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/back/methods/dms/deleteTrashFiles.js b/back/methods/dms/deleteTrashFiles.js index 9d16e9d81..e212c846c 100644 --- a/back/methods/dms/deleteTrashFiles.js +++ b/back/methods/dms/deleteTrashFiles.js @@ -15,7 +15,7 @@ module.exports = Self => { } }); - Self.deleteTrashFiles = async(options) => { + Self.deleteTrashFiles = async options => { const tx = await Self.beginTransaction({}); const myOptions = {}; @@ -33,9 +33,15 @@ module.exports = Self => { where: {code: 'trash'} }, myOptions); + const date = new Date(); + date.setMonth(date.getMonth() - 4); + const dmsToDelete = await models.Dms.find({ where: { - dmsTypeFk: trashDmsType.id + and: [ + {dmsTypeFk: trashDmsType.id}, + {created: {lt: date}} + ] } }, myOptions); @@ -43,14 +49,19 @@ module.exports = Self => { const pathHash = DmsContainer.getHash(dms.id); const dmsContainer = await DmsContainer.container(pathHash); const dstFile = path.join(dmsContainer.client.root, pathHash, dms.file); + const dstFolder = path.join(dmsContainer.client.root, pathHash); await fs.unlink(dstFile); - await dms.destroy(myOptions); + try { + await fs.rmdir(dstFolder); + await dms.destroy(myOptions); + } catch (err) { + await dms.destroy(myOptions); + } } if (tx) await tx.commit(); - } catch (e) { if (tx) await tx.rollback(); - + throw e; } }; From 2a41c1bb93eb53e26733757b30cb69d5a4b116b1 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 19 Jul 2022 12:44:55 +0200 Subject: [PATCH 2/5] update foreign key --- db/changes/10480-june/00-albaran_gestdoc .sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 db/changes/10480-june/00-albaran_gestdoc .sql diff --git a/db/changes/10480-june/00-albaran_gestdoc .sql b/db/changes/10480-june/00-albaran_gestdoc .sql new file mode 100644 index 000000000..a0ba93bd3 --- /dev/null +++ b/db/changes/10480-june/00-albaran_gestdoc .sql @@ -0,0 +1,2 @@ +ALTER TABLE `vn2008`.`albaran_gestdoc` DROP FOREIGN KEY fk_albaran_gestdoc_gestdoc1; +ALTER TABLE `vn2008`.`albaran_gestdoc` ADD CONSTRAINT albaran_gestdoc_FK FOREIGN KEY (gestdoc_id) REFERENCES `vn`.`dms`(id) ON DELETE CASCADE ON UPDATE CASCADE; \ No newline at end of file From 5491fce0c6905024ea3f61346763f09f12becb99 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 21 Jul 2022 13:16:30 +0200 Subject: [PATCH 3/5] fix: musn't delete files on test enviroment --- back/methods/dms/deleteTrashFiles.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/back/methods/dms/deleteTrashFiles.js b/back/methods/dms/deleteTrashFiles.js index e212c846c..9da508285 100644 --- a/back/methods/dms/deleteTrashFiles.js +++ b/back/methods/dms/deleteTrashFiles.js @@ -1,3 +1,4 @@ +const UserError = require('vn-loopback/util/user-error'); const fs = require('fs-extra'); const path = require('path'); @@ -26,6 +27,9 @@ module.exports = Self => { myOptions.transaction = tx; try { + if (process.env.NODE_ENV == 'test') + throw new UserError(`Action not allowed on the test environment`); + const models = Self.app.models; const DmsContainer = models.DmsContainer; From 7809d9dd7e4b41a1d74ec696056505f3bd955db5 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 22 Jul 2022 13:41:18 +0200 Subject: [PATCH 4/5] fix: typo --- .../{00-albaran_gestdoc .sql => 00-albaran_gestdoc.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/10480-june/{00-albaran_gestdoc .sql => 00-albaran_gestdoc.sql} (100%) diff --git a/db/changes/10480-june/00-albaran_gestdoc .sql b/db/changes/10480-june/00-albaran_gestdoc.sql similarity index 100% rename from db/changes/10480-june/00-albaran_gestdoc .sql rename to db/changes/10480-june/00-albaran_gestdoc.sql From 7ad555c73fac1c8f399243e7c7c1e9034f0a75ba Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 22 Jul 2022 13:59:36 +0200 Subject: [PATCH 5/5] restart backTest Jenkins --- db/dump/structure.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/dump/structure.sql b/db/dump/structure.sql index 015b620d1..1f787f864 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -23,6 +23,7 @@ CREATE DATABASE /*!32312 IF NOT EXISTS*/ `account` /*!40100 DEFAULT CHARACTER SE USE `account`; + -- -- Table structure for table `account` --