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

Revision 1911, 2.3 kB (checked in by qldrob, 7 years ago)

Remove some blank lines

  • 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" )');
3 sql('CREATE TABLE IF NOT EXISTS ivr_dests ( ivr_id INT NOT NULL, selection VARCHAR(10), dest VARCHAR(50))');
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($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($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($upcheck->getDebugInfo());           
51           }
52         }
53       }
54     }
55 }
56
57 ?>
Note: See TracBrowser for help on using the browser.