Changeset 7245 for modules/branches/2.5
- Timestamp:
- 11/09/08 21:40:54 (5 years ago)
- Files:
-
- modules/branches/2.5/ivr/install.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
modules/branches/2.5/ivr/install.php
r6695 r7245 65 65 sql($sql); 66 66 67 // Now, we need to check for upgrades. 67 // Now, we need to check for upgrades. 68 68 // V1.0, old IVR. You shouldn't see this, but check for it anyway, and assume that it's 2.0 69 69 // V2.0, Original Release 70 70 // V2.1, added 'directorycontext' to the schema 71 71 // v2.2, announcement changed to support filenames instead of ID's from recordings table 72 // 72 // 73 73 74 74 $ivr_modcurrentvers = modules_getversion('ivr'); 75 75 76 // Add the col 77 $sql = "SELECT dircontext FROM ivr"; 78 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); 79 if(DB::IsError($check)) { 80 // add new field 81 $sql = 'ALTER TABLE ivr ADD COLUMN dircontext VARCHAR ( 50 ) DEFAULT "default"'; 82 $result = $db->query($sql); 83 if(DB::IsError($result)) { 84 die_freepbx($result->getDebugInfo()); 85 } 86 } 87 88 if (version_compare($ivr_modcurrentvers, "2.2", "<")) { 89 //echo "<p>Start 2.2 upgrade</p>"; 90 $sql = "ALTER TABLE ivr CHANGE COLUMN announcement announcement VARCHAR ( 255 )"; 91 $result = $db->query($sql); 92 if(DB::IsError($result)) { 93 die_freepbx($result->getDebugInfo()); 94 } else { 95 // Change existing records 96 //echo "<p>Updating existing records</p>"; 97 $existing = sql("SELECT DISTINCT announcement FROM ivr WHERE displayname <> '__install_done' AND announcement IS NOT NULL", "getAll"); 98 foreach ($existing as $item) { 99 $recid = $item[0]; 100 //echo "<p>processing '$recid'</p>"; 101 $sql = "SELECT filename FROM recordings WHERE id = '$recid' AND displayname <> '__invalid'"; 102 $recordings = sql($sql, "getRow"); 103 if (is_array($recordings)) { 104 $filename = (isset($recordings[0]) ? $recordings[0] : ''); 105 //echo "<p>filename: $filename"; 106 if ($filename != '') { 107 $sql = "UPDATE ivr SET announcement = '".str_replace("'", "''", $filename)."' WHERE announcement = '$recid'"; 108 $upcheck = $db->query($sql); 109 if(DB::IsError($upcheck)) 110 die_freepbx($upcheck->getDebugInfo()); 111 } 112 } 113 } 114 } 115 } 116 76 if($amp_conf["AMPDBENGINE"] != "sqlite3") { // As of 2.5 these are all in the sqlite3 schema 77 // Add the col 78 $sql = "SELECT dircontext FROM ivr"; 79 $check = $db->getRow($sql, DB_FETCHMODE_ASSOC); 80 if(DB::IsError($check)) { 81 // add new field 82 $sql = 'ALTER TABLE ivr ADD COLUMN dircontext VARCHAR ( 50 ) DEFAULT "default"'; 83 $result = $db->query($sql); 84 if(DB::IsError($result)) { 85 die_freepbx($result->getDebugInfo()); 86 } 87 } 88 89 if (version_compare($ivr_modcurrentvers, "2.2", "<")) { 90 //echo "<p>Start 2.2 upgrade</p>"; 91 $sql = "ALTER TABLE ivr CHANGE COLUMN announcement announcement VARCHAR ( 255 )"; 92 $result = $db->query($sql); 93 if(DB::IsError($result)) { 94 die_freepbx($result->getDebugInfo()); 95 } else { 96 // Change existing records 97 //echo "<p>Updating existing records</p>"; 98 $existing = sql("SELECT DISTINCT announcement FROM ivr WHERE displayname <> '__install_done' AND announcement IS NOT NULL", "getAll"); 99 foreach ($existing as $item) { 100 $recid = $item[0]; 101 //echo "<p>processing '$recid'</p>"; 102 $sql = "SELECT filename FROM recordings WHERE id = '$recid' AND displayname <> '__invalid'"; 103 $recordings = sql($sql, "getRow"); 104 if (is_array($recordings)) { 105 $filename = (isset($recordings[0]) ? $recordings[0] : ''); 106 //echo "<p>filename: $filename"; 107 if ($filename != '') { 108 $sql = "UPDATE ivr SET announcement = '".str_replace("'", "''", $filename)."' WHERE announcement = '$recid'"; 109 $upcheck = $db->query($sql); 110 if(DB::IsError($upcheck)) 111 die_freepbx($upcheck->getDebugInfo()); 112 } 113 } 114 } 115 } 116 } 117 } 117 118 // Version 2.5.7 adds auto-return to IVR 118 119 $sql = "SELECT ivr_ret FROM ivr_dests"; … … 120 121 if(DB::IsError($check)) { 121 122 // add new field 122 $sql = "ALTER TABLE ivr_dests ADD ivr_ret TINYINT(1) NOT NULL DEFAULT 0;";123 $result = $db->query($sql);124 if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); }123 $sql = "ALTER TABLE ivr_dests ADD ivr_ret TINYINT(1) NOT NULL DEFAULT 0;"; 124 $result = $db->query($sql); 125 if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); } 125 126 } 126 127 … … 150 151 if(DB::IsError($check)) { 151 152 // add new field 152 $sql = "ALTER TABLE ivr ADD alt_timeout VARCHAR(8);";153 $result = $db->query($sql);154 if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); }153 $sql = "ALTER TABLE ivr ADD alt_timeout VARCHAR(8);"; 154 $result = $db->query($sql); 155 if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); } 155 156 } 156 157 $sql = "SELECT alt_invalid FROM ivr"; … … 158 159 if(DB::IsError($check)) { 159 160 // add new field 160 $sql = "ALTER TABLE ivr ADD alt_invalid VARCHAR(8);";161 $result = $db->query($sql);162 if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); }161 $sql = "ALTER TABLE ivr ADD alt_invalid VARCHAR(8);"; 162 $result = $db->query($sql); 163 if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); } 163 164 } 164 165 $sql = "SELECT `loops` FROM ivr"; … … 166 167 if(DB::IsError($check)) { 167 168 // add new field 168 $sql = "ALTER TABLE ivr ADD `loops` TINYINT(1) NOT NULL DEFAULT 2;";169 $result = $db->query($sql);170 if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); }169 $sql = "ALTER TABLE ivr ADD `loops` TINYINT(1) NOT NULL DEFAULT 2;"; 170 $result = $db->query($sql); 171 if(DB::IsError($result)) { die_freepbx($result->getDebugInfo()); } 171 172 } 172 173 … … 183 184 out(_("migrating")); 184 185 outn(_("adding announcement_id field..")); 185 $sql = "ALTER TABLE ivr ADD announcement_id INTEGER";186 $result = $db->query($sql);187 if(DB::IsError($result)) {188 out(_("fatal error")); 189 die_freepbx($result->getDebugInfo()); 186 $sql = "ALTER TABLE ivr ADD announcement_id INTEGER"; 187 $result = $db->query($sql); 188 if(DB::IsError($result)) { 189 out(_("fatal error")); 190 die_freepbx($result->getDebugInfo()); 190 191 } else { 191 192 out(_("ok")); … … 195 196 // 196 197 outn(_("migrate to recording ids..")); 197 $sql = "SELECT `ivr_id`, `announcement` FROM `ivr`";198 $sql = "SELECT `ivr_id`, `announcement` FROM `ivr`"; 198 199 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 199 200 if(DB::IsError($results)) { 200 201 out(_("fatal error")); 201 die_freepbx($results->getDebugInfo()); 202 die_freepbx($results->getDebugInfo()); 202 203 } 203 204 $migrate_arr = array(); … … 215 216 if(DB::IsError($result)) { 216 217 out(_("fatal error")); 217 die_freepbx($result->getDebugInfo()); 218 die_freepbx($result->getDebugInfo()); 218 219 } 219 220 } … … 223 224 // 224 225 outn(_("dropping announcement field..")); 225 $sql = "ALTER TABLE `ivr` DROP `announcement`";226 $result = $db->query($sql);227 if(DB::IsError($result)) { 226 $sql = "ALTER TABLE `ivr` DROP `announcement`"; 227 $result = $db->query($sql); 228 if(DB::IsError($result)) { 228 229 out(_("no announcement field???")); 229 230 } else { … … 243 244 // Add timeout_id field 244 245 // 245 $sql = "ALTER TABLE ivr ADD timeout_id INTEGER DEFAULT null";246 $result = $db->query($sql);247 if(DB::IsError($result)) {248 out(_("fatal error")); 249 die_freepbx($result->getDebugInfo()); 246 $sql = "ALTER TABLE ivr ADD timeout_id INTEGER DEFAULT null"; 247 $result = $db->query($sql); 248 if(DB::IsError($result)) { 249 out(_("fatal error")); 250 die_freepbx($result->getDebugInfo()); 250 251 } else { 251 252 out(_("added")); … … 260 261 // Add invalid_id field 261 262 // 262 $sql = "ALTER TABLE ivr ADD invalid_id INTEGER DEFAULT null";263 $result = $db->query($sql);264 if(DB::IsError($result)) {265 out(_("fatal error")); 266 die_freepbx($result->getDebugInfo()); 263 $sql = "ALTER TABLE ivr ADD invalid_id INTEGER DEFAULT null"; 264 $result = $db->query($sql); 265 if(DB::IsError($result)) { 266 out(_("fatal error")); 267 die_freepbx($result->getDebugInfo()); 267 268 } else { 268 269 out(_("added")); … … 279 280 // 280 281 $sql = "ALTER TABLE ivr ADD retvm VARCHAR(8);"; 281 $result = $db->query($sql);282 if(DB::IsError($result)) {283 out(_("fatal error")); 284 die_freepbx($result->getDebugInfo()); 282 $result = $db->query($sql); 283 if(DB::IsError($result)) { 284 out(_("fatal error")); 285 die_freepbx($result->getDebugInfo()); 285 286 } else { 286 287 out(_("added"));
