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

Revision 7903, 3.8 kB (checked in by mickecarlsson, 4 years ago)

Added license text to various files, fixed spelling errors

  • 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 if (! function_exists("out")) {
22   function out($text) {
23     echo $text."<br />";
24   }
25 }
26
27 if (! function_exists("outn")) {
28   function outn($text) {
29     echo $text;
30   }
31 }
32
33 $autoincrement = (($amp_conf["AMPDBENGINE"] == "sqlite") || ($amp_conf["AMPDBENGINE"] == "sqlite3")) ? "AUTOINCREMENT":"AUTO_INCREMENT";
34
35 // create the tables
36 $sql = "CREATE TABLE IF NOT EXISTS cidlookup (
37   cidlookup_id INTEGER NOT NULL PRIMARY KEY $autoincrement,
38   description varchar(50) NOT NULL,
39   sourcetype varchar(100) NOT NULL,
40   cache tinyint(1) NOT NULL default '0',
41   deptname varchar(30) default NULL,
42   http_host varchar(30) default NULL,
43   http_port varchar(30) default NULL,
44   http_username varchar(30) default NULL,
45   http_password varchar(30) default NULL,
46   http_path varchar(100) default NULL,
47   http_query varchar(100) default NULL,
48   mysql_host varchar(60) default NULL,
49   mysql_dbname varchar(60) default NULL,
50   mysql_query text,
51   mysql_username varchar(30) default NULL,
52   mysql_password varchar(30) default NULL
53 );";
54 $check = $db->query($sql);
55 if (DB::IsError($check)) {
56         die_freepbx( "Can not create `cidlookup` table: " . $check->getMessage() .  "\n");
57 }
58
59
60 $sql = "CREATE TABLE IF NOT EXISTS cidlookup_incoming (
61   cidlookup_id INT NOT NULL,
62   extension VARCHAR(50),
63   cidnum VARCHAR(30)
64 );";
65 $check = $db->query($sql);
66 if (DB::IsError($check)) {
67         die_freepbx( "Can not create `cidlookup_incomming` table: " . $check->getMessage() .  "\n");
68 }
69
70 // first update
71 $sql = "SELECT cache FROM cidlookup";
72 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
73 if (DB::IsError($check)) {
74   // add new field
75   $sql = "ALTER TABLE cidlookup ADD cache INTEGER NOT NULL DEFAULT 0;";
76   $result = $db->query($sql);
77   if(DB::IsError($result)) {
78     die_freepbx($result->getMessage());
79   }
80 }
81
82 outn("Migrating channel routing to Zap DID routing..");
83 $sql = "SELECT channel FROM cidlookup_incoming";
84 $check = @$db->query($sql);
85 if (!DB::IsError($check)) {
86   $chan_prefix = 'zapchan';
87   $sql = "UPDATE cidlookup_incoming SET extension=CONCAT('$chan_prefix',channel), channel='' WHERE channel != ''";
88   $results = $db->query($sql);
89   if (DB::IsError($results)) {
90     out("FATAL: failed to transform old routes: ".$results->getMessage());
91   } else {
92     out("OK");
93     // ALTER...DROP is not supported by sqlite3.  This table was setup properly in the CREATE anyway
94     if($amp_conf["AMPDBENGINE"] != "sqlite3")  {
95       outn("Removing deprecated channel field from incoming..");
96       $sql = "ALTER TABLE cidlookup_incoming DROP channel";
97       $results = $db->query($sql);
98       if (DB::IsError($results)) {
99       out("ERROR: failed: ".$results->getMessage());
100       } else {
101         out("OK");
102       }
103     }
104   }
105 } else {
106   out("Not Needed");
107 }
108
109 // This field had been wrongfully added to incoming quite some time ago
110 // this should maybe be added to core as well
111 //
112 // ALTER...DROP is not supported by sqlite3.  This table was setup properly in the CREATE anyway
113 if($amp_conf["AMPDBENGINE"] != "sqlite3")  {
114
115   outn("Checking for cidlookup field in core's incoming table..");
116   $sql = "ALTER TABLE incoming DROP cidlookup";
117   $results = $db->query($sql);
118   if (DB::IsError($results)) {
119     out("not present");
120   } else {
121   out("removed");
122   }
123 }
124 ?>
125
Note: See TracBrowser for help on using the browser.