From 48f6d0fccc4ff75741b97aff25043fec64ce777a Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 15 Oct 2024 16:47:58 +0200 Subject: [PATCH] feat: refs #6452 add sip on create worker --- db/dump/fixtures.before.sql | 13 +----- db/routines/pbx/procedures/sip_isValid.sql | 21 ---------- db/routines/pbx/triggers/sip_beforeInsert.sql | 8 ---- db/routines/pbx/triggers/sip_beforeUpdate.sql | 8 ---- .../vn/procedures/queueMember_updateQueue.sql | 3 ++ .../vn/triggers/worker_beforeInsert.sql | 5 +++ .../00-useIdAsSip.vn.sql | 40 +++++++++++++++++++ 7 files changed, 50 insertions(+), 48 deletions(-) delete mode 100644 db/routines/pbx/procedures/sip_isValid.sql delete mode 100644 db/routines/pbx/triggers/sip_beforeInsert.sql delete mode 100644 db/routines/pbx/triggers/sip_beforeUpdate.sql create mode 100644 db/versions/11301-turquoiseOrchid/00-useIdAsSip.vn.sql diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 7f7e50dd3..c28bdb584 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -2039,13 +2039,6 @@ INSERT INTO `pbx`.`prefix` (country, prefix) ('fr', '0033'), ('pt', '00351'); -INSERT INTO `pbx`.`sip`(`user_id`, `extension`) - VALUES - (1, 1010), - (3, 1101), - (5, 1102), - (9, 1201); - INSERT INTO `vn`.`professionalCategory` (`id`, `description`) VALUES (1, 'employee'), @@ -4005,9 +3998,7 @@ INSERT INTO pbx.queue (description, name, config) INSERT IGNORE INTO pbx.queueMember SET queue = '1000', - extension = '1010'; + extension = '1111'; UPDATE vn.department SET pbxQueue = '1000' WHERE name = "CAMARA"; -UPDATE vn.department SET pbxQueue = '2000' WHERE name = "VENTAS"; - - +UPDATE vn.department SET pbxQueue = '2000' WHERE name = "VENTAS"; \ No newline at end of file diff --git a/db/routines/pbx/procedures/sip_isValid.sql b/db/routines/pbx/procedures/sip_isValid.sql deleted file mode 100644 index 4a0182bcc..000000000 --- a/db/routines/pbx/procedures/sip_isValid.sql +++ /dev/null @@ -1,21 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `pbx`.`sip_isValid`(vExtension VARCHAR(255)) -BEGIN -/** - * Check if an extension has the correct format and - * throws an exception if it hasn't. - * - * @param vExtension The extension - */ - DECLARE vIsValid BOOL; - - SET vIsValid = vExtension IS NULL - OR (vExtension REGEXP '^[0-9]{4}$' - AND MOD(vExtension, 100) != 0); - - IF NOT vIsValid THEN - SIGNAL SQLSTATE '45000' - SET MESSAGE_TEXT = 'Extension format is invalid'; - END IF; -END$$ -DELIMITER ; diff --git a/db/routines/pbx/triggers/sip_beforeInsert.sql b/db/routines/pbx/triggers/sip_beforeInsert.sql deleted file mode 100644 index 832232119..000000000 --- a/db/routines/pbx/triggers/sip_beforeInsert.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `pbx`.`sip_beforeInsert` - BEFORE INSERT ON `sip` - FOR EACH ROW -BEGIN - CALL sip_isValid(NEW.extension); -END$$ -DELIMITER ; diff --git a/db/routines/pbx/triggers/sip_beforeUpdate.sql b/db/routines/pbx/triggers/sip_beforeUpdate.sql deleted file mode 100644 index e23b8e22e..000000000 --- a/db/routines/pbx/triggers/sip_beforeUpdate.sql +++ /dev/null @@ -1,8 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `pbx`.`sip_beforeUpdate` - BEFORE UPDATE ON `sip` - FOR EACH ROW -BEGIN - CALL sip_isValid(NEW.extension); -END$$ -DELIMITER ; diff --git a/db/routines/vn/procedures/queueMember_updateQueue.sql b/db/routines/vn/procedures/queueMember_updateQueue.sql index 5af44da4f..15d1d3196 100644 --- a/db/routines/vn/procedures/queueMember_updateQueue.sql +++ b/db/routines/vn/procedures/queueMember_updateQueue.sql @@ -23,7 +23,10 @@ BEGIN DELETE FROM pbx.queueMember WHERE extension = vExtension COLLATE utf8_general_ci; + IF vNewQueue IS NOT NULL THEN INSERT IGNORE INTO pbx.queueMember (queue, extension) VALUES (vNewQueue, vExtension); + END IF; + END$$ DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn/triggers/worker_beforeInsert.sql b/db/routines/vn/triggers/worker_beforeInsert.sql index 24adbdbb6..5fe10808e 100644 --- a/db/routines/vn/triggers/worker_beforeInsert.sql +++ b/db/routines/vn/triggers/worker_beforeInsert.sql @@ -4,5 +4,10 @@ CREATE OR REPLACE DEFINER=`vn`@`localhost` TRIGGER `vn`.`worker_beforeInsert` FOR EACH ROW BEGIN SET NEW.editorFk = account.myUser_getId(); + + INSERT INTO pbx.sip + SET user_id = NEW.id, + extension = NEW.id; + END$$ DELIMITER ; diff --git a/db/versions/11301-turquoiseOrchid/00-useIdAsSip.vn.sql b/db/versions/11301-turquoiseOrchid/00-useIdAsSip.vn.sql new file mode 100644 index 000000000..7d84e74a9 --- /dev/null +++ b/db/versions/11301-turquoiseOrchid/00-useIdAsSip.vn.sql @@ -0,0 +1,40 @@ +ALTER TABLE pbx.followme DROP FOREIGN KEY followme_ibfk_1; +ALTER TABLE pbx.queueMember DROP FOREIGN KEY queueMember_ibfk_2; +ALTER TABLE pbx.sipReg DROP FOREIGN KEY sipReg_ibfk_1; + +CREATE OR REPLACE TEMPORARY TABLE tSipReg + SELECT * FROM pbx.sipReg; + +CREATE OR REPLACE TEMPORARY TABLE tOldSip + SELECT * FROM pbx.sip; + +TRUNCATE TABLE pbx.sipReg; + +TRUNCATE TABLE pbx.sip; + +INSERT INTO pbx.sip (user_id, extension) + SELECT w.id, w.id FROM vn.worker w; + +REPLACE INTO pbx.sipReg + SELECT tsr.* FROM tSipReg tsr + JOIN vn.worker w ON tsr.userId = w.id; + +UPDATE pbx.queueMember qm + JOIN tOldSip tos ON tos.extension = qm.extension + LEFT JOIN pbx.sip s ON s.user_id = tos.user_id + SET qm.extension = s.extension; + +ALTER TABLE pbx.followme + ADD CONSTRAINT followme_ibfk_1 + FOREIGN KEY (extension) REFERENCES pbx.sip(extension); + +ALTER TABLE pbx.queueMember + ADD CONSTRAINT queueMember_ibfk_2 + FOREIGN KEY (extension) REFERENCES pbx.sip(extension); + +ALTER TABLE pbx.sipReg + ADD CONSTRAINT sipReg_ibfk_1 + FOREIGN KEY (userId) REFERENCES pbx.sip(user_id); + +DROP TEMPORARY TABLE IF EXISTS tSipReg; +DROP TEMPORARY TABLE IF EXISTS tOldSip; \ No newline at end of file