diff --git a/db/changes/234801/03-zoneIncluded_procedure_checkCollisions.sql b/db/changes/234801/03-zoneIncluded_procedure_checkCollisions.sql index ccfb8f3b8..f3649466b 100644 --- a/db/changes/234801/03-zoneIncluded_procedure_checkCollisions.sql +++ b/db/changes/234801/03-zoneIncluded_procedure_checkCollisions.sql @@ -1,33 +1,60 @@ -DROP PROCEDURE IF EXISTS `vn`.`zoneIncluded_checkCollisions`; +DROP PROCEDURE IF EXISTS vn.zoneIncluded_checkCollisions; + DELIMITER $$ - -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneIncluded_checkCollisions`(IN zi_zone INT, IN zi_geo INT) +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneIncluded_checkCollisions`() BEGIN -DECLARE done INT DEFAULT 0; -DECLARE zic_id, zic_zone, zic_geo, zic_action, zic_userFk INT; -DECLARE z_name VARCHAR(255); -DECLARE g_name VARCHAR(255); - -DECLARE my_cur CURSOR FOR - SELECT zic.id, z.name , zg.name , zic.geoFk ,zic.`action` , zic.userFK FROM vn.zoneIncludedCheck zic, vn.`zone` z, vn.zoneGeo zg WHERE zic.zoneFK =z.id AND zic.geoFK = zg.id ; -DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; - -OPEN my_cur; - my_cur_loop: - LOOP FETCH my_cur INTO zic_id, z_name,g_name, zic_geo, zic_action, zic_userFk ; - IF done = 1 THEN - select concat('NO REDCORDS' ) AS '** DEBUG:'; - LEAVE my_cur_loop; - END IF; - SELECT concat('** ', zic_id, '** ',z_name, '** ',g_name,'**',zic_geo,'** ', zic_action,'** ', zic_userFk ) AS '** DEBUG:'; - DELETE FROM vn.zoneIncludedCheck WHERE id =zic_id; - SELECT util.notification_send('zone-included', - JSON_OBJECT('zoneSelected', z_name, 'geoSelected', g_name), - account.myUser_getId() - ); - END LOOP my_cur_loop; -CLOSE my_cur; + DECLARE zic_id, zic_zone, zic_geoFk, zic_action, zic_zoneFk, zic_userFk INT; + DECLARE zic2_geoFk, zic2_zoneFk INT; + DECLARE z_name VARCHAR(255); + DECLARE g_name VARCHAR(255); + DECLARE vDone boolean; -END$$ + DECLARE cur CURSOR FOR + SELECT zic.id, z.name , zg.name ,zic.zoneFK, zic.geoFk ,zic.`action` , zic.userFK + FROM vn.zoneIncludedCheck zic, vn.`zone` z, vn.zoneGeo zg + WHERE zic.zoneFK =z.id AND zic.geoFK = zg.id and zic.action ='insert'; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + SET vDone := FALSE; + OPEN cur; + LOOP1: LOOP + SET vDone := FALSE; + FETCH cur INTO zic_id, z_name, g_name, zic_zoneFk, zic_geoFk, zic_action, zic_userFk ; + IF vDone THEN + select concat('NO RECORDS LOOP 1' ) AS '** DEBUG:'; + CLOSE cur; + LEAVE LOOP1; + END IF; + -- SELECT concat('** ', zic_id, '** ',z_name, '** ',g_name,'**',zic_zoneFk,'**',zic_geoFk,'** ', zic_action,'** ', zic_userFk ) AS '** DEBUG:'; + DELETE FROM vn.zoneIncludedCheck WHERE id =zic_id; + + BLOCK2: BEGIN + DECLARE vDone2 boolean; + DECLARE cur2 CURSOR FOR + SELECT zi.zoneFk,zi.geoFk + FROM vn.zoneIncluded zi, vn.zone z + where z.id = zi.zoneFk and zi.zoneFk=zic_zoneFk and zi.geoFk=zic_geoFk and zi.isIncluded = 1; + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone2 = TRUE; + SET vDone2 := FALSE; + OPEN cur2; + LOOP2: LOOP + FETCH cur2 INTO zic2_zoneFk, zic2_geoFk ; + IF vDone2 THEN + select concat('NO RECORDS LOOP 2' ) AS '** DEBUG:'; + CLOSE cur2; + LEAVE LOOP2; + END IF; + SELECT concat('COLLISION DETECTED', zic2_zoneFk, zic2_geoFk ) AS '** DEBUG:'; + + SELECT util.notification_send('zone-included', + JSON_OBJECT('zoneSelected', z_name, 'geoSelected', g_name), + account.myUser_getId() + ); + END LOOP LOOP2; + END BLOCK2; + END LOOP LOOP1; +END +$$ DELIMITER ; diff --git a/db/changes/234802/00-zoneIncluded_trigger.sql b/db/changes/234802/00-zoneIncluded_trigger.sql deleted file mode 100644 index 4de0416b7..000000000 --- a/db/changes/234802/00-zoneIncluded_trigger.sql +++ /dev/null @@ -1,73 +0,0 @@ -DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterInsert`; -USE `vn`; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterInsert` - AFTER INSERT ON `zoneIncluded` - FOR EACH ROW -BEGIN - INSERT INTO zoneLog - SET `action` = 'insert', - `changedModel` = 'zoneIncluded', - `changedModelId` = NEW.zoneFk, - `userFk` = account.myUser_getId(); - INSERT INTO zoneIncludedCheck - SET - `action`= 'insert', - `zoneFk` = NEW.zoneFk, - `geoFk` = NEW.geoFk, - `userFk` = account.myUser_getId(); - -- CALL `vn`.`zoneIncluded_checkCollisions`(NEW.zoneFk, NEW.geoFk); - -END$$ -DELIMITER ; - -DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterUpdate`; -USE `vn`; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterUpdate` - AFTER UPDATE ON `zoneIncluded` - FOR EACH ROW -BEGIN - INSERT INTO zoneLog - SET `action` = 'update', - `changedModel` = 'zoneIncluded', - `changedModelId` = OLD.zoneFk, - `userFk` = account.myUser_getId(); - INSERT INTO zoneIncludedCheck - SET - `action`= 'update', - `zoneFk` = NEW.zoneFk, - `geoFk` = NEW.geoFk, - `userFk` = account.myUser_getId(); - - -- CALL `vn`.`zoneIncluded_checkCollisions`(); - - -END$$ -DELIMITER ; - -DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterDelete`; -USE `vn`; - -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterDelete` - AFTER DELETE ON `zoneIncluded` - FOR EACH ROW -BEGIN - INSERT INTO zoneLog - SET `action` = 'delete', - `changedModel` = 'zoneIncluded', - `changedModelId` = OLD.zoneFk, - `userFk` = account.myUser_getId(); - INSERT INTO zoneIncludedCheck - SET - `action`= 'delete', - `zoneFk` = OLD.zoneFk, - `geoFk` = OLD.geoFk, - `userFk` = account.myUser_getId(); - - -- CALL `vn`.`zoneIncluded_checkCollisions`(); -END$$ -DELIMITER ; diff --git a/db/changes/234802/01-zoneIncluded_table_zoneincludedCheck.sql b/db/changes/234802/01-zoneIncluded_table_zoneincludedCheck.sql deleted file mode 100644 index ba52f76b0..000000000 --- a/db/changes/234802/01-zoneIncluded_table_zoneincludedCheck.sql +++ /dev/null @@ -1,14 +0,0 @@ -CREATE TABLE `vn`.`zoneIncludedCheck` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `zoneFK` int(11) NOT NULL, - `geoFK` int(11) NOT NULL, - `userFK` int(10) unsigned NOT NULL, - `action`set('insert','update','delete') NOT NULL, - PRIMARY KEY (`id`), - CONSTRAINT `user_FK` FOREIGN KEY (`userFK`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `zone_FK` FOREIGN KEY (`zoneFK`) REFERENCES `vn`.`zone` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `geo_FK` FOREIGN KEY (`geoFK`) REFERENCES `vn`.`zoneGeo` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - UNIQUE INDEX (`zoneFK`, `geoFK`, `userFK`, `action`) -) - -comment 'Table to save temporarily zone changes'; diff --git a/db/changes/234802/02-zoneIncluded_event_checkCollisions.sql b/db/changes/234802/02-zoneIncluded_event_checkCollisions.sql deleted file mode 100644 index 3a6dd32b8..000000000 --- a/db/changes/234802/02-zoneIncluded_event_checkCollisions.sql +++ /dev/null @@ -1,5 +0,0 @@ -USE vn; -CREATE EVENT zoneCollisionsCheck -ON SCHEDULE AT CURRENT_TIMESTAMP -DISABLE ON SLAVE -DO SELECT vn.zoneIncluded_checkCollisions; diff --git a/db/changes/234802/03-zoneIncluded_procedure_checkCollisions.sql b/db/changes/234802/03-zoneIncluded_procedure_checkCollisions.sql deleted file mode 100644 index 8959b3945..000000000 --- a/db/changes/234802/03-zoneIncluded_procedure_checkCollisions.sql +++ /dev/null @@ -1,33 +0,0 @@ -DROP PROCEDURE IF EXISTS `vn`.`zoneIncluded_checkCollisions`; -DELIMITER $$ - -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`zoneIncluded_checkCollisions`() -BEGIN -DECLARE done INT DEFAULT 0; -DECLARE zic_id, zic_zone, zic_geo, zic_action, zic_userFk INT; -DECLARE z_name VARCHAR(255); -DECLARE g_name VARCHAR(255); - -DECLARE my_cur CURSOR FOR - SELECT zic.id, z.name , zg.name , zic.geoFk ,zic.`action` , zic.userFK FROM vn.zoneIncludedCheck zic, vn.`zone` z, vn.zoneGeo zg WHERE zic.zoneFK =z.id AND zic.geoFK = zg.id ; -DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; - -OPEN my_cur; - my_cur_loop: - LOOP FETCH my_cur INTO zic_id, z_name,g_name, zic_geo, zic_action, zic_userFk ; - IF done = 1 THEN - select concat('NO REDCORDS' ) AS '** DEBUG:'; - LEAVE my_cur_loop; - END IF; - SELECT concat('** ', zic_id, '** ',z_name, '** ',g_name,'**',zic_geo,'** ', zic_action,'** ', zic_userFk ) AS '** DEBUG:'; - DELETE FROM vn.zoneIncludedCheck WHERE id =zic_id; - SELECT util.notification_send('zone-included', - JSON_OBJECT('zoneSelected', z_name, 'geoSelected', g_name), - account.myUser_getId() - ); - END LOOP my_cur_loop; -CLOSE my_cur; - - -END$$ -DELIMITER ; diff --git a/db/changes/234802/04-remove-procedure-bs_nightTask.sql b/db/changes/234802/04-remove-procedure-bs_nightTask.sql deleted file mode 100644 index 530dc6ef5..000000000 --- a/db/changes/234802/04-remove-procedure-bs_nightTask.sql +++ /dev/null @@ -1,2 +0,0 @@ -DELETE FROM bs.nightTask - WHERE `procedure` ='zone_getCollisions'; diff --git a/db/changes/234802/05-drop-procedure-zone_getCollisions.sql b/db/changes/234802/05-drop-procedure-zone_getCollisions.sql deleted file mode 100644 index 9d0db5465..000000000 --- a/db/changes/234802/05-drop-procedure-zone_getCollisions.sql +++ /dev/null @@ -1 +0,0 @@ -DROP PROCEDURE vn.zone_getCollisions; diff --git a/db/changes/234802/06-zoneincluded_notification.sql b/db/changes/234802/06-zoneincluded_notification.sql deleted file mode 100644 index 53b2a9189..000000000 --- a/db/changes/234802/06-zoneincluded_notification.sql +++ /dev/null @@ -1,11 +0,0 @@ --- Auto-generated SQL script #202311241021 -INSERT INTO util.notification (name,description) - VALUES ('zone-included','An email to notify zoneCollisions'); - --- Auto-generated SQL script #202311241051 -INSERT INTO util.notificationSubscription (notificationFk,userFk) - SELECT id, account.myUser_getId() FROM util.notification WHERE name= "zone-included" - - -INSERT INTO util.notificationAcl (notificationFk,roleFk) - SELECT id, account.role FROM util.notification WHERE name= "zone-included"