root/contributed_modules/modules/customcontexts/install.php

Revision 9931, 5.8 kB (checked in by p_lindheimer, 2 years ago)

remove route migrations from module now that done in framework update, I was wrong, doing them again could create problems here, re #4369

Line 
1 <?php /* $Id: install.php $ */
2 /*
3  * This program is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU General Public License
5  * as published by the Free Software Foundation; either version 2
6  * of the License, or (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13  
14 global $db;
15 global $amp_conf;
16
17 if (! function_exists("out")) {
18   function out($text) {
19     echo $text."<br />";
20   }
21 }
22
23 if (! function_exists("outn")) {
24   function outn($text) {
25     echo $text;
26   }
27 }
28
29 // TODO: returning false will fail the install with #4345 checked in
30 //
31 if (!function_exists('timeconditions_timegroups_add_group_timestrings')) {
32   out(_('Time Conditions Module required and not present .. aborting install'));
33   return false;
34 }
35
36 $sql[] ="CREATE TABLE IF NOT EXISTS `customcontexts_contexts` (
37         `context` varchar(100) NOT NULL default '',
38         `description` varchar(100) NOT NULL default '',
39         PRIMARY KEY  (`context`),
40         UNIQUE KEY `description` (`description`)
41       )";
42
43
44 $sql[] ="CREATE TABLE IF NOT EXISTS `customcontexts_contexts_list` (
45         `context` varchar(100) NOT NULL default '',
46         `description` varchar(100) NOT NULL default '',
47         `locked` tinyint(1) NOT NULL default '0',
48         PRIMARY KEY  (`context`),
49         UNIQUE KEY `description` (`description`)
50         )";
51
52 $sql[] ="INSERT IGNORE INTO `customcontexts_contexts_list`
53         (`context`, `description`, `locked`)
54         VALUES ('from-internal', 'Default Internal Context', 1),
55         ('from-internal-additional', 'Internal Dialplan', 0),
56         ('outbound-allroutes', 'Outbound Routes', 0)";
57
58 $sql[] ="CREATE TABLE IF NOT EXISTS `customcontexts_includes` (
59         `context` varchar(100) NOT NULL default '',
60         `include` varchar(100) NOT NULL default '',
61         `timegroupid` int(11) default NULL,
62         `sort` int(11) NOT NULL default '0',
63         PRIMARY KEY  (`context`,`include`),
64         KEY `sort` (`sort`)
65 )";
66
67 $sql[] ="ALTER IGNORE TABLE `customcontexts_includes` ADD `timegroupid` INT NULL AFTER `include`";
68
69 $sql[] ="CREATE TABLE IF NOT EXISTS `customcontexts_includes_list` (
70         `context` varchar(100) NOT NULL default '',
71         `include` varchar(100) NOT NULL default '',
72         `description` varchar(100) NOT NULL default '',
73         PRIMARY KEY  (`context`,`include`)
74         )";
75
76 $sql[] ="ALTER IGNORE TABLE `customcontexts_includes_list` ADD `missing` BOOL NOT NULL DEFAULT '0'";
77
78
79 $sql[] ="INSERT IGNORE INTO `customcontexts_includes_list` (`context`, `include`, `description`) VALUES ('from-internal', 'parkedcalls', 'Call Parking'),
80         ('from-internal', 'from-internal-custom', 'Custom Internal Dialplan')";
81
82 $sql[] ="INSERT IGNORE INTO `customcontexts_includes_list`
83           (`context`, `include`, `description`)
84           VALUES ('from-internal-additional', 'outbound-allroutes', 'ALL OUTBOUND ROUTES'),
85           ('from-internal', 'from-internal-additional', 'ENTIRE Basic Internal Dialplan')";
86
87 $sql[] ="UPDATE `customcontexts_includes_list` SET `description` = 'ALL OUTBOUND ROUTES' WHERE  `context` = 'from-internal-additional' AND `include` = 'outbound-allroutes'";
88
89 $sql[] ="CREATE TABLE IF NOT EXISTS `customcontexts_module` (
90         `id` varchar(50) NOT NULL default '',
91         `value` varchar(100) NOT NULL default '',
92         PRIMARY KEY  (`id`)
93         )";
94
95 $sql[] ="INSERT IGNORE INTO `customcontexts_module` (`id`, `value`) VALUES ('modulerawname', 'customcontexts'),
96         ('moduledisplayname', 'Custom Contexts'),
97         ('moduleversion', '0.3.2'),
98         ('displaysortforincludes', 1)";
99
100 $sql[] ="UPDATE `customcontexts_module` set `value` = '0.3.2' where `id` = 'moduleversion';";
101
102 foreach ($sql as $q){
103   $db->query($q);
104     if(DB::IsError($q)) {
105       out("FATAL: ".$q->getDebugInfo()."\n");
106     }
107 }
108
109 customcontexts_updatedb();
110
111 //bring db up to date on install/upgrade
112 function customcontexts_updatedb() {
113   global $db;
114   $sql = "ALTER IGNORE TABLE `customcontexts_includes` ADD `timegroupid` INT NULL AFTER `include` ;";
115   $db->query($sql);
116   $sql = "ALTER IGNORE TABLE `customcontexts_includes_list` ADD `missing` BOOL NOT NULL DEFAULT '0';";
117   $db->query($sql);
118   $sql = "ALTER IGNORE TABLE `customcontexts_contexts` ADD `dialrules` VARCHAR( 1000 ) NULL;";
119   $db->query($sql);
120   $sql = "ALTER IGNORE TABLE `customcontexts_includes` ADD `userules` VARCHAR( 10 ) NULL ;";
121   $db->query($sql);
122   $sql = "ALTER IGNORE TABLE `customcontexts_contexts` ADD `faildestination` VARCHAR( 250 ) NULL , ADD `featurefaildestination` VARCHAR( 250 ) NULL ;";
123   $db->query($sql);
124 //0.3.0
125   $sql = "ALTER IGNORE TABLE `customcontexts_contexts` ADD `failpin` VARCHAR( 100 ) NULL , ADD `failpincdr` BOOL NOT NULL DEFAULT '0', ADD `featurefailpin` VARCHAR( 100 ) NULL , ADD `featurefailpincdr` BOOL NOT NULL DEFAULT '0';";
126   $db->query($sql);
127 //0.3.2
128   $sql = "ALTER IGNORE TABLE `customcontexts_includes_list` ADD `sort` INT NOT NULL DEFAULT '0';";
129   $db->query($sql);
130 }
131
132 $tgs = $db->getAll('SELECT * FROM customcontexts_timegroups',DB_FETCHMODE_ASSOC);
133 if(!DB::IsError($tgs)) {
134   outn(_("migrating customcontexts_timegroups if needed.."));         
135   foreach ($tgs as $tg) {
136     $tg_strings = sql('SELECT time FROM customcontexts_timegroups_detail WHERE timegroupid = '.$tg['id'].' ORDER BY id','getCol','time');
137     $tg_id = timeconditions_timegroups_add_group_timestrings($tg['description'],$tg_strings);
138     sql("UPDATE customcontexts_includes set timegroupid = $tg_id WHERE timegroupid = {$tg['id']}");
139   }
140   out(_("done"));         
141   outn(_("removing customcontexts_timegroups and customcontexts_tiemgroups_detail tables.."));         
142   unset($sql);
143   $sql[] = "DROP TABLE IF EXISTS `customcontexts_timegroups`";
144   $sql[] = "DROP TABLE IF EXISTS `customcontexts_timegroups_detail`";
145   foreach ($sql as $q){
146     $db->query($q);
147   }
148   out(_("done"));         
149 }
150 ?>
Note: See TracBrowser for help on using the browser.