From 28bf7bd74722480b7ffe1431c07155e95cf19796 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 15 Sep 2022 08:34:42 +0200 Subject: [PATCH] feat: check general status 'open' to close ticket --- back/methods/osticket/closeTicket.js | 5 +++-- back/models/osticket-config.json | 7 +++++-- db/changes/10481-june/00-osTicketConfig.sql | 7 ++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/back/methods/osticket/closeTicket.js b/back/methods/osticket/closeTicket.js index 1b4eaedbd..17e8d6b91 100644 --- a/back/methods/osticket/closeTicket.js +++ b/back/methods/osticket/closeTicket.js @@ -30,6 +30,7 @@ module.exports = Self => { const sql = `SELECT ot.ticket_id, ot.number FROM osticket.ost_ticket ot + JOIN osticket.ost_ticket_status ots ON ots.id = ot.status_id JOIN osticket.ost_thread ot2 ON ot2.object_id = ot.ticket_id AND ot2.object_type = 'T' JOIN ( SELECT ote.thread_id, MAX(ote.created) created, MAX(ote.updated) updated @@ -38,7 +39,7 @@ module.exports = Self => { GROUP BY ote.thread_id ) sub ON sub.thread_id = ot2.id WHERE ot.isanswered = 1 - AND status_id IN (${config.oldStatusId}) + AND ots.state = '${config.oldStatus}' AND IF(sub.updated > sub.created, sub.updated, sub.created) < DATE_SUB(CURDATE(), INTERVAL ${config.day} DAY)`; let ticketsId = []; @@ -96,7 +97,7 @@ module.exports = Self => { const ostUri = `${config.host}/ajax.php/tickets/${ticketId}/status`; const data = { status_id: config.newStatusId, - comments: undefined, + comments: config.comment, undefined: config.action }; const params = { diff --git a/back/models/osticket-config.json b/back/models/osticket-config.json index db4799e99..529d081c8 100644 --- a/back/models/osticket-config.json +++ b/back/models/osticket-config.json @@ -21,8 +21,8 @@ "password": { "type": "string" }, - "oldStatusId": { - "type": "number" + "oldStatus": { + "type": "string" }, "newStatusId": { "type": "number" @@ -32,6 +32,9 @@ }, "day": { "type": "number" + }, + "comment": { + "type": "string" } } } \ No newline at end of file diff --git a/db/changes/10481-june/00-osTicketConfig.sql b/db/changes/10481-june/00-osTicketConfig.sql index bfe85228e..fa969ccb0 100644 --- a/db/changes/10481-june/00-osTicketConfig.sql +++ b/db/changes/10481-june/00-osTicketConfig.sql @@ -3,13 +3,14 @@ CREATE TABLE `vn`.`osTicketConfig` ( `host` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL, `user` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL, `password` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL, - `oldStatusId` int(11) DEFAULT NULL, + `oldStatus` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL, `newStatusId` int(11) DEFAULT NULL, `action` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL, `day` int(11) DEFAULT NULL, + `comment` varchar(100) COLLATE utf8mb3_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; -INSERT INTO `vn`.`osTicketConfig`(id, host, `user`, password, oldStatusId, newStatusId, `action`, `day`) +INSERT INTO `vn`.`osTicketConfig`(`id`, `host`, `user`, `password`, `oldStatus`, `newStatusId`, `action`, `day`, `comment`) VALUES - (0, 'http://localhost:56596/scp', 'ostadmin', 'Admin1', 1, 3, 'Cerrar', 60); + (0, 'http://localhost:56596/scp', 'ostadmin', 'Admin1', 'open', 3, 'Cerrar', 60, 'Este CAU se ha cerrado automáticamente');