2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-08-20 08:06:10 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`ticketTracking_afterDelete`
|
2024-01-15 11:31:03 +00:00
|
|
|
AFTER DELETE ON `ticketTracking`
|
|
|
|
FOR EACH ROW
|
|
|
|
BEGIN
|
|
|
|
DECLARE vTicketFk INT;
|
|
|
|
DECLARE vTicketTrackingFk INT;
|
|
|
|
DECLARE vStateName VARCHAR(15);
|
|
|
|
|
|
|
|
DECLARE CONTINUE HANDLER FOR SQLSTATE '23000'
|
|
|
|
BEGIN
|
|
|
|
DELETE FROM vn.ticketLastState
|
|
|
|
WHERE ticketFk = OLD.ticketFk;
|
|
|
|
END;
|
|
|
|
|
|
|
|
INSERT INTO ticketLog
|
|
|
|
SET `action` = 'delete',
|
|
|
|
`changedModel` = 'TicketTracking',
|
|
|
|
`changedModelId` = OLD.id,
|
|
|
|
`userFk` = account.myUser_getId();
|
|
|
|
|
|
|
|
SELECT i.ticketFk, i.id, s.`name`
|
|
|
|
INTO vTicketFk, vTicketTrackingFk, vStateName
|
|
|
|
FROM ticketTracking i
|
|
|
|
JOIN state s ON i.stateFk = s.id
|
|
|
|
WHERE ticketFk = OLD.ticketFk
|
|
|
|
ORDER BY created DESC
|
|
|
|
LIMIT 1;
|
|
|
|
|
|
|
|
IF vTicketFk > 0 THEN
|
|
|
|
REPLACE INTO ticketLastState(ticketFk, ticketTrackingFk,name)
|
|
|
|
VALUES(vTicketFk, vTicketTrackingFk, vStateName);
|
|
|
|
END IF;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|