28 lines
719 B
MySQL
28 lines
719 B
MySQL
|
DELIMITER $$
|
||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticket_setProblemRequest`(
|
||
|
vSelf INT
|
||
|
)
|
||
|
BEGIN
|
||
|
/**
|
||
|
* Update the problems of tickets that have a pending ticketRequest or no longer have it
|
||
|
*
|
||
|
* @param vSelf Id ticket, if NULL ALL tickets
|
||
|
*/
|
||
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||
|
(INDEX(ticketFk))
|
||
|
ENGINE = MEMORY
|
||
|
SELECT t.id ticketFk, FALSE hasProblem
|
||
|
FROM ticket t
|
||
|
WHERE t.shipped >= util.midnight()
|
||
|
AND (vSelf IS NULL OR t.id = vSelf);
|
||
|
|
||
|
UPDATE tmp.ticket t
|
||
|
JOIN ticketRequest tr ON tr.ticketFk = t.ticketFk
|
||
|
SET t.hasProblem = TRUE
|
||
|
WHERE tr.isOK IS NULL;
|
||
|
|
||
|
CALL ticket_setProblem('hasTicketRequest');
|
||
|
|
||
|
DROP TEMPORARY TABLE tmp.ticket;
|
||
|
END$$
|
||
|
DELIMITER ;
|