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

Revision 5847, 2.8 kB (checked in by p_lindheimer, 5 years ago)

remove cidlookup field from core incoming table - should never have been there

  • Property svn:mime-type set to text/plain
  • Property svn:eol-style set to native
Line 
1 <?php
2
3 global $db;
4 global $amp_conf;
5
6 if (! function_exists("out")) {
7   function out($text) {
8     echo $text."<br />";
9   }
10 }
11
12 if (! function_exists("outn")) {
13   function outn($text) {
14     echo $text;
15   }
16 }
17
18 $autoincrement = (($amp_conf["AMPDBENGINE"] == "sqlite") || ($amp_conf["AMPDBENGINE"] == "sqlite3")) ? "AUTOINCREMENT":"AUTO_INCREMENT";
19
20 // create the tables
21 $sql = "CREATE TABLE IF NOT EXISTS cidlookup (
22   cidlookup_id INTEGER NOT NULL PRIMARY KEY $autoincrement,
23   description varchar(50) NOT NULL,
24   sourcetype varchar(100) NOT NULL,
25   cache tinyint(1) NOT NULL default '0',
26   deptname varchar(30) default NULL,
27   http_host varchar(30) default NULL,
28   http_port varchar(30) default NULL,
29   http_username varchar(30) default NULL,
30   http_password varchar(30) default NULL,
31   http_path varchar(100) default NULL,
32   http_query varchar(100) default NULL,
33   mysql_host varchar(60) default NULL,
34   mysql_dbname varchar(60) default NULL,
35   mysql_query text,
36   mysql_username varchar(30) default NULL,
37   mysql_password varchar(30) default NULL
38 );";
39 $check = $db->query($sql);
40 if (DB::IsError($check)) {
41         die_freepbx( "Can not create `cidlookup` table: " . $check->getMessage() .  "\n");
42 }
43
44
45 $sql = "CREATE TABLE IF NOT EXISTS cidlookup_incoming (
46   cidlookup_id INT NOT NULL,
47   extension VARCHAR(50),
48   cidnum VARCHAR(30)
49 );";
50 $check = $db->query($sql);
51 if (DB::IsError($check)) {
52         die_freepbx( "Can not create `cidlookup_incomming` table: " . $check->getMessage() .  "\n");
53 }
54
55 // first update
56 $sql = "SELECT cache FROM cidlookup";
57 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
58 if (DB::IsError($check)) {
59   // add new field
60   $sql = "ALTER TABLE cidlookup ADD cache INTEGER NOT NULL DEFAULT 0;";
61   $result = $db->query($sql);
62   if(DB::IsError($result)) {
63     die_freepbx($result->getMessage());
64   }
65 }
66
67 outn("Migrating channel routing to Zap DID routing..");
68 $sql = "SELECT channel FROM cidlookup_incoming";
69 $check = $db->query($sql);
70 if (!DB::IsError($check)) {
71   $chan_prefix = 'zapchan';
72   $sql = "UPDATE cidlookup_incoming SET extension=CONCAT('$chan_prefix',channel), channel='' WHERE channel != ''";
73   $results = $db->query($sql);
74   if (DB::IsError($results)) {
75     out("FATAL: failed to transform old routes: ".$results->getMessage());
76   } else {
77     out("OK");
78     outn("Removing deprecated channel field from incoming..");
79     $sql = "ALTER TABLE cidlookup_incoming DROP channel";
80     $results = $db->query($sql);
81     if (DB::IsError($results)) {
82       out("ERROR: failed: ".$results->getMessage());
83     } else {
84       out("OK");
85     }
86   }
87 } else {
88   out("Not Needed");
89 }
90
91 // This field had been wrongfully added to incoming quite some time ago
92 // this should maybe be added to core as well
93 //
94 outn("Checking for cidlookup field in core's incoming table..");
95 $sql = "ALTER TABLE incoming DROP cidlookup";
96 $results = $db->query($sql);
97 if (DB::IsError($results)) {
98   out("not present");
99 } else {
100   out("removed");
101 }
102
103 ?>
104
Note: See TracBrowser for help on using the browser.