root/modules/branches/2.9/cidlookup/install.php

Revision 11109, 3.7 kB (checked in by p_lindheimer, 2 years ago)

remove functions now always included by utility.functions.php

  • Property svn:mime-type set to text/plain
  • Property svn:eol-style set to native
Line 
1 <?php
2 //This file is part of FreePBX.
3 //
4 //    FreePBX is free software: you can redistribute it and/or modify
5 //    it under the terms of the GNU General Public License as published by
6 //    the Free Software Foundation, either version 2 of the License, or
7 //    (at your option) any later version.
8 //
9 //    FreePBX is distributed in the hope that it will be useful,
10 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //    GNU General Public License for more details.
13 //
14 //    You should have received a copy of the GNU General Public License
15 //    along with FreePBX.  If not, see <http://www.gnu.org/licenses/>.
16 //
17
18 global $db;
19 global $amp_conf;
20
21 $autoincrement = (($amp_conf["AMPDBENGINE"] == "sqlite") || ($amp_conf["AMPDBENGINE"] == "sqlite3")) ? "AUTOINCREMENT":"AUTO_INCREMENT";
22
23 // create the tables
24 $sql = "CREATE TABLE IF NOT EXISTS cidlookup (
25   cidlookup_id INTEGER NOT NULL PRIMARY KEY $autoincrement,
26   description varchar(50) NOT NULL,
27   sourcetype varchar(100) NOT NULL,
28   cache tinyint(1) NOT NULL default '0',
29   deptname varchar(30) default NULL,
30   http_host varchar(30) default NULL,
31   http_port varchar(30) default NULL,
32   http_username varchar(30) default NULL,
33   http_password varchar(30) default NULL,
34   http_path varchar(100) default NULL,
35   http_query varchar(100) default NULL,
36   mysql_host varchar(60) default NULL,
37   mysql_dbname varchar(60) default NULL,
38   mysql_query text,
39   mysql_username varchar(30) default NULL,
40   mysql_password varchar(30) default NULL
41 );";
42 $check = $db->query($sql);
43 if (DB::IsError($check)) {
44         die_freepbx( "Can not create `cidlookup` table: " . $check->getMessage() .  "\n");
45 }
46
47
48 $sql = "CREATE TABLE IF NOT EXISTS cidlookup_incoming (
49   cidlookup_id INT NOT NULL,
50   extension VARCHAR(50),
51   cidnum VARCHAR(30)
52 );";
53 $check = $db->query($sql);
54 if (DB::IsError($check)) {
55         die_freepbx( "Can not create `cidlookup_incomming` table: " . $check->getMessage() .  "\n");
56 }
57
58 // first update
59 $sql = "SELECT cache FROM cidlookup";
60 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
61 if (DB::IsError($check)) {
62   // add new field
63   $sql = "ALTER TABLE cidlookup ADD cache INTEGER NOT NULL DEFAULT 0;";
64   $result = $db->query($sql);
65   if(DB::IsError($result)) {
66     die_freepbx($result->getMessage());
67   }
68 }
69
70 outn(_("Migrating channel routing to Zap DID routing.."));
71 $sql = "SELECT channel FROM cidlookup_incoming";
72 $check = @$db->query($sql);
73 if (!DB::IsError($check)) {
74   $chan_prefix = 'zapchan';
75   $sql = "UPDATE cidlookup_incoming SET extension=CONCAT('$chan_prefix',channel), channel='' WHERE channel != ''";
76   $results = $db->query($sql);
77   if (DB::IsError($results)) {
78     out(_("FATAL: failed to transform old routes: ").$results->getMessage());
79   } else {
80     out(_("OK"));
81     // ALTER...DROP is not supported by sqlite3.  This table was setup properly in the CREATE anyway
82     if($amp_conf["AMPDBENGINE"] != "sqlite3")  {
83       outn(_("Removing deprecated channel field from incoming.."));
84       $sql = "ALTER TABLE cidlookup_incoming DROP channel";
85       $results = $db->query($sql);
86       if (DB::IsError($results)) {
87       out(_("ERROR: failed: ").$results->getMessage());
88       } else {
89         out(_("OK"));
90       }
91     }
92   }
93 } else {
94   out(_("Not Needed"));
95 }
96
97 // This field had been wrongfully added to incoming quite some time ago
98 // this should maybe be added to core as well
99 //
100 // ALTER...DROP is not supported by sqlite3.  This table was setup properly in the CREATE anyway
101 if($amp_conf["AMPDBENGINE"] != "sqlite3")  {
102
103   outn(_("Checking for cidlookup field in core's incoming table.."));
104   $sql = "ALTER TABLE incoming DROP cidlookup";
105   $results = $db->query($sql);
106   if (DB::IsError($results)) {
107     out(_("not present"));
108   } else {
109   out(_("removed"));
110   }
111 }
112 ?>
113
Note: See TracBrowser for help on using the browser.