Show
Ignore:
Timestamp:
11/09/08 21:40:54 (5 years ago)
Author:
ethans
Message:

Closes #3384

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.5/ivr/install.php

    r6695 r7245  
    6565sql($sql); 
    6666 
    67 // Now, we need to check for upgrades.  
     67// Now, we need to check for upgrades. 
    6868// V1.0, old IVR. You shouldn't see this, but check for it anyway, and assume that it's 2.0 
    6969// V2.0, Original Release 
    7070// V2.1, added 'directorycontext' to the schema 
    7171// v2.2, announcement changed to support filenames instead of ID's from recordings table 
    72 //  
     72// 
    7373 
    7474$ivr_modcurrentvers = modules_getversion('ivr'); 
    7575 
    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  
     76if($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
    117118// Version 2.5.7 adds auto-return to IVR 
    118119$sql = "SELECT ivr_ret FROM ivr_dests"; 
     
    120121if(DB::IsError($check)) { 
    121122  // 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()); } 
    125126} 
    126127 
     
    150151if(DB::IsError($check)) { 
    151152  // 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()); } 
    155156} 
    156157$sql = "SELECT alt_invalid FROM ivr"; 
     
    158159if(DB::IsError($check)) { 
    159160  // 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()); } 
    163164} 
    164165$sql = "SELECT `loops` FROM ivr"; 
     
    166167if(DB::IsError($check)) { 
    167168  // 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()); } 
    171172} 
    172173 
     
    183184  out(_("migrating")); 
    184185  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()); 
    190191  } else { 
    191192    out(_("ok")); 
     
    195196  // 
    196197  outn(_("migrate to recording ids..")); 
    197   $sql = "SELECT `ivr_id`, `announcement` FROM `ivr`"; 
     198 $sql = "SELECT `ivr_id`, `announcement` FROM `ivr`"; 
    198199  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
    199200  if(DB::IsError($results)) { 
    200201    out(_("fatal error")); 
    201     die_freepbx($results->getDebugInfo());  
     202    die_freepbx($results->getDebugInfo()); 
    202203  } 
    203204  $migrate_arr = array(); 
     
    215216    if(DB::IsError($result)) { 
    216217      out(_("fatal error")); 
    217       die_freepbx($result->getDebugInfo());   
     218      die_freepbx($result->getDebugInfo()); 
    218219    } 
    219220  } 
     
    223224  // 
    224225  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)) { 
    228229    out(_("no announcement field???")); 
    229230  } else { 
     
    243244  //  Add timeout_id field 
    244245  // 
    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()); 
    250251  } else { 
    251252    out(_("added")); 
     
    260261  //  Add invalid_id field 
    261262  // 
    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()); 
    267268  } else { 
    268269    out(_("added")); 
     
    279280  // 
    280281  $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()); 
    285286  } else { 
    286287    out(_("added"));