From 0ca1db76331a45d59ffd4f8fdf4e0405a9b8e45e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 2 Sep 2024 17:57:39 +0200 Subject: [PATCH 1/5] feat: ref#7902 Triggers vn.ticketRefund to control deleted tickets --- .../vn/procedures/ticketRefund_upsert.sql | 26 +++++++++++++++++++ .../vn/triggers/ticketRefund_beforeInsert.sql | 2 ++ .../vn/triggers/ticketRefund_beforeUpdate.sql | 2 ++ 3 files changed, 30 insertions(+) create mode 100644 db/routines/vn/procedures/ticketRefund_upsert.sql diff --git a/db/routines/vn/procedures/ticketRefund_upsert.sql b/db/routines/vn/procedures/ticketRefund_upsert.sql new file mode 100644 index 000000000..504ce950e --- /dev/null +++ b/db/routines/vn/procedures/ticketRefund_upsert.sql @@ -0,0 +1,26 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketRefund_upsert`( + vRefundTicketFk INT, + vOriginalTicketFk INT + +) + READS SQL DATA +BEGIN +/** + * Common code for ticketRefund triggers + * + * @param vRefundTicketFk + * @param vOriginalTicketFk + */ + DECLARE vIsDeleted BOOL; + + SELECT SUM(ABS(isDeleted)) INTO vIsDeleted + FROM ticket + WHERE id IN (vRefundTicketFk, vOriginalTicketFk); + + IF vIsDeleted THEN + CALL util.throw('The refund ticket can not be deleted tickets'); + END IF; + +END$$ +DELIMITER ; diff --git a/db/routines/vn/triggers/ticketRefund_beforeInsert.sql b/db/routines/vn/triggers/ticketRefund_beforeInsert.sql index ff8ce634a..7f3facb55 100644 --- a/db/routines/vn/triggers/ticketRefund_beforeInsert.sql +++ b/db/routines/vn/triggers/ticketRefund_beforeInsert.sql @@ -3,6 +3,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketRefund_beforeIn BEFORE INSERT ON `ticketRefund` FOR EACH ROW BEGIN + CALL ticketRefund_upsert(NEW.refundTicketFk, NEW.originalTicketFk); + SET NEW.editorFk = account.myUser_getId(); END$$ DELIMITER ; diff --git a/db/routines/vn/triggers/ticketRefund_beforeUpdate.sql b/db/routines/vn/triggers/ticketRefund_beforeUpdate.sql index d809b5d99..7ec093c36 100644 --- a/db/routines/vn/triggers/ticketRefund_beforeUpdate.sql +++ b/db/routines/vn/triggers/ticketRefund_beforeUpdate.sql @@ -3,6 +3,8 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`ticketRefund_beforeUp BEFORE UPDATE ON `ticketRefund` FOR EACH ROW BEGIN + CALL ticketRefund_upsert(NEW.refundTicketFk, NEW.originalTicketFk); + SET NEW.editorFk = account.myUser_getId(); END$$ DELIMITER ; From 08c7bd2c423866ce1d081407b4a88d2c91e18915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 2 Sep 2024 17:59:31 +0200 Subject: [PATCH 2/5] feat: ref#7902 Triggers vn.ticketRefund to control deleted tickets --- db/routines/vn/procedures/ticketRefund_upsert.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/db/routines/vn/procedures/ticketRefund_upsert.sql b/db/routines/vn/procedures/ticketRefund_upsert.sql index 504ce950e..2f07d9d25 100644 --- a/db/routines/vn/procedures/ticketRefund_upsert.sql +++ b/db/routines/vn/procedures/ticketRefund_upsert.sql @@ -2,7 +2,6 @@ DELIMITER $$ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketRefund_upsert`( vRefundTicketFk INT, vOriginalTicketFk INT - ) READS SQL DATA BEGIN @@ -21,6 +20,5 @@ BEGIN IF vIsDeleted THEN CALL util.throw('The refund ticket can not be deleted tickets'); END IF; - END$$ DELIMITER ; From 41af80991744eb530330144b0966216051720342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Andr=C3=A9s?= Date: Mon, 30 Sep 2024 14:33:58 +0200 Subject: [PATCH 3/5] feat: ref#7902 Triggers vn.ticketRefund to control deleted tickets --- db/routines/vn/procedures/ticketRefund_upsert.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/ticketRefund_upsert.sql b/db/routines/vn/procedures/ticketRefund_upsert.sql index 2f07d9d25..ec37d71f0 100644 --- a/db/routines/vn/procedures/ticketRefund_upsert.sql +++ b/db/routines/vn/procedures/ticketRefund_upsert.sql @@ -13,9 +13,10 @@ BEGIN */ DECLARE vIsDeleted BOOL; - SELECT SUM(ABS(isDeleted)) INTO vIsDeleted + SELECT COUNT(*) INTO vIsDeleted FROM ticket - WHERE id IN (vRefundTicketFk, vOriginalTicketFk); + WHERE id IN (vRefundTicketFk, vOriginalTicketFk) + AND isDeleted; IF vIsDeleted THEN CALL util.throw('The refund ticket can not be deleted tickets'); From 9ba017d352a8ea70f74ea22c0b6986c7bb1ded9d Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 2 Oct 2024 09:06:21 +0200 Subject: [PATCH 4/5] feat: refs #7902 Changed definer and throw msg --- db/routines/vn/procedures/ticketRefund_upsert.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/ticketRefund_upsert.sql b/db/routines/vn/procedures/ticketRefund_upsert.sql index ec37d71f0..ef5993361 100644 --- a/db/routines/vn/procedures/ticketRefund_upsert.sql +++ b/db/routines/vn/procedures/ticketRefund_upsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketRefund_upsert`( +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticketRefund_upsert`( vRefundTicketFk INT, vOriginalTicketFk INT ) @@ -19,7 +19,7 @@ BEGIN AND isDeleted; IF vIsDeleted THEN - CALL util.throw('The refund ticket can not be deleted tickets'); + CALL util.throw('Refund tickets cannot be deleted'); END IF; END$$ DELIMITER ; From b556903d6d707746f65fb9ebb29f333e0b8a9a87 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 2 Oct 2024 09:09:04 +0200 Subject: [PATCH 5/5] feat: refs #7902 Changed definer and throw msg --- db/routines/vn/procedures/ticketRefund_upsert.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/ticketRefund_upsert.sql b/db/routines/vn/procedures/ticketRefund_upsert.sql index ef5993361..fb22e6e8c 100644 --- a/db/routines/vn/procedures/ticketRefund_upsert.sql +++ b/db/routines/vn/procedures/ticketRefund_upsert.sql @@ -19,7 +19,7 @@ BEGIN AND isDeleted; IF vIsDeleted THEN - CALL util.throw('Refund tickets cannot be deleted'); + CALL util.throw('The refund ticket cannot be deleted tickets'); END IF; END$$ DELIMITER ;