root/modules/branches/2.4/ivr/install.php

Revision 5824, 4.3 kB (checked in by p_lindheimer, 4 years ago)

#2858 Better handing of i and t options, added loop count and ability to loop before going to user defined i, t options

  • Property svn:mime-type set to text/plain
  • Property svn:eol-style set to native
Line 
1 <?php
2 sql('CREATE TABLE IF NOT EXISTS ivr ( ivr_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, displayname VARCHAR(50), deptname VARCHAR(50), enable_directory VARCHAR(8), enable_directdial VARCHAR(8), timeout INT, announcement VARCHAR(255), dircontext VARCHAR ( 50 ) DEFAULT "default", alt_timeout VARCHAR(8), alt_invalid VARCHAR(8), `loops` TINYINT(1) NOT NULL DEFAULT 2 )');
3 sql('CREATE TABLE IF NOT EXISTS ivr_dests ( ivr_id INT NOT NULL, selection VARCHAR(10), dest VARCHAR(50), ivr_ret TINYINT(1) NOT NULL DEFAULT 0)');
4
5 global $db;
6
7 // Now, we need to check for upgrades.
8 // V1.0, old IVR. You shouldn't see this, but check for it anyway, and assume that it's 2.0
9 // V2.0, Original Release
10 // V2.1, added 'directorycontext' to the schema
11 // v2.2, announcement changed to support filenames instead of ID's from recordings table
12 //
13
14 $ivr_modcurrentvers = modules_getversion('ivr');
15
16 // Add the col
17 $sql = "SELECT dircontext FROM ivr";
18 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
19 if(DB::IsError($check)) {
20   // add new field
21     $sql = 'ALTER TABLE ivr ADD COLUMN dircontext VARCHAR ( 50 ) DEFAULT "default"';
22     $result = $db->query($sql);
23     if(DB::IsError($result)) {
24             die_freepbx($result->getDebugInfo());
25     }
26 }
27
28 if (version_compare($ivr_modcurrentvers, "2.2", "<")) {
29   //echo "<p>Start 2.2 upgrade</p>";
30   $sql = "ALTER TABLE ivr CHANGE COLUMN announcement announcement VARCHAR ( 255 )";
31     $result = $db->query($sql);
32     if(DB::IsError($result)) {
33             die_freepbx($result->getDebugInfo());
34     } else {
35       // Change existing records
36       //echo "<p>Updating existing records</p>";
37       $existing = sql("SELECT DISTINCT announcement FROM ivr WHERE displayname <> '__install_done' AND announcement IS NOT NULL", "getAll");
38       foreach ($existing as $item) {
39         $recid = $item[0];
40         //echo "<p>processing '$recid'</p>";
41         $sql = "SELECT filename FROM recordings WHERE id = '$recid' AND displayname <> '__invalid'";
42         $recordings = sql($sql, "getRow");
43         if (is_array($recordings)) {
44           $filename = (isset($recordings[0]) ? $recordings[0] : '');
45           //echo "<p>filename: $filename";
46           if ($filename != '') {
47             $sql = "UPDATE ivr SET announcement = '".str_replace("'", "''", $filename)."' WHERE announcement = '$recid'";
48             $upcheck = $db->query($sql);
49             if(DB::IsError($upcheck))
50                     die_freepbx($upcheck->getDebugInfo());           
51           }
52         }
53       }
54     }
55 }
56
57 // Version 2.5.7 adds auto-return to IVR
58 $sql = "SELECT ivr_ret FROM ivr_dests";
59 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
60 if(DB::IsError($check)) {
61   // add new field
62     $sql = "ALTER TABLE ivr_dests ADD ivr_ret TINYINT(1) NOT NULL DEFAULT 0;";
63     $result = $db->query($sql);
64     if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); }
65 }
66
67 $results = array();
68 $sql = "SELECT ivr_id, selection, dest FROM ivr_dests";
69 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
70 if (!DB::IsError($results)) { // error - table must not be there
71   foreach ($results as $result) {
72     $old_dest  = $result['dest'];
73     $ivr_id    = $result['ivr_id'];
74     $selection = $result['selection'];
75
76     $new_dest = merge_ext_followme(trim($old_dest));
77     if ($new_dest != $old_dest) {
78       $sql = "UPDATE ivr_dests SET dest = '$new_dest' WHERE ivr_id = $ivr_id AND selection = '$selection' AND dest = '$old_dest'";
79       $results = $db->query($sql);
80       if(DB::IsError($results)) {
81         die_freepbx($results->getMessage());
82       }
83     }
84   }
85 }
86
87 // Version 2.5.17 adds improved i and t destination handling
88 $sql = "SELECT alt_timeout FROM ivr";
89 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
90 if(DB::IsError($check)) {
91   // add new field
92     $sql = "ALTER TABLE ivr ADD alt_timeout VARCHAR(8);";
93     $result = $db->query($sql);
94     if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); }
95 }
96 $sql = "SELECT alt_invalid FROM ivr";
97 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
98 if(DB::IsError($check)) {
99   // add new field
100     $sql = "ALTER TABLE ivr ADD alt_invalid VARCHAR(8);";
101     $result = $db->query($sql);
102     if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); }
103 }
104 $sql = "SELECT `loops` FROM ivr";
105 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
106 if(DB::IsError($check)) {
107   // add new field
108     $sql = "ALTER TABLE ivr ADD `loops` TINYINT(1) NOT NULL DEFAULT 2;";
109     $result = $db->query($sql);
110     if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); }
111 }
112 ?>
Note: See TracBrowser for help on using the browser.