diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index afb10094b8..5dde66f6e4 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -2048,13 +2048,6 @@ INSERT IGNORE 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'), @@ -4002,10 +3995,11 @@ 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"; INSERT INTO vn.workerRelatives (workerFk, isDescendant, disabilityGradeFk, birthed, adoptionYear, isDependend, isJointCustody, updated) VALUES @@ -4041,4 +4035,4 @@ INSERT INTO vn.workerIrpf (workerFk,spouseNif, geographicMobilityDate) INSERT IGNORE INTO vn.inventoryConfig SET id = 1, - supplierFk = 4; \ No newline at end of file + supplierFk = 4; diff --git a/db/routines/pbx/procedures/sip_isValid.sql b/db/routines/pbx/procedures/sip_isValid.sql deleted file mode 100644 index 4a0182bcce..0000000000 --- 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 8322321196..0000000000 --- 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 e23b8e22e0..0000000000 --- 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 5af44da4f6..15d1d31964 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 24adbdbb64..5fe10808e7 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/11380-maroonPaniculata/00-firstScript.sql b/db/versions/11380-maroonPaniculata/00-firstScript.sql new file mode 100644 index 0000000000..5172f956e8 --- /dev/null +++ b/db/versions/11380-maroonPaniculata/00-firstScript.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 tmp.tSipReg + SELECT * FROM pbx.sipReg; + +CREATE OR REPLACE TEMPORARY TABLE tmp.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 tmp.tSipReg tsr + JOIN vn.worker w ON tsr.userId = w.id; + +UPDATE pbx.queueMember qm + JOIN tmp.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 tmp.tSipReg; +DROP TEMPORARY TABLE IF EXISTS tmp.tOldSip; \ No newline at end of file