Changeset 4349

Show
Ignore:
Timestamp:
07/10/07 20:48:38 (6 years ago)
Author:
p_lindheimer
Message:

added notifications table and added conversion in all destinations directories for now core voicemail dest format inot 2.3.0beta2 upgrade dir

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/branches/2.3/SQL/newinstall.sql

    r4180 r4349  
    424424-- 
    425425 
     426--  
     427-- Table structure for table `notifications` 
     428--  
     429 
     430DROP TABLE IF EXISTS notifications; 
     431CREATE TABLE notifications ( 
     432  module varchar(24) NOT NULL default '', 
     433  id varchar(24) NOT NULL default '', 
     434  `level` int(11) NOT NULL default '0', 
     435  display_text varchar(255) NOT NULL default '', 
     436  extended_text blob NOT NULL, 
     437  link varchar(255) NOT NULL default '', 
     438  `reset` tinyint(4) NOT NULL default '0', 
     439  `timestamp` int(11) NOT NULL default '0', 
     440  PRIMARY KEY  (module,id) 
     441) 
     442 
    426443 
    427444/*!40000 ALTER TABLE `zap` DISABLE KEYS */; 
  • freepbx/branches/2.3/SQL/newinstall.sqlite3.sql

    r4180 r4349  
    423423-- 
    424424 
     425--  
     426-- Table structure for table `notifications` 
     427--  
     428 
     429DROP TABLE IF EXISTS notifications; 
     430CREATE TABLE notifications ( 
     431  module varchar(24) NOT NULL default '', 
     432  id varchar(24) NOT NULL default '', 
     433  `level` int(11) NOT NULL default '0', 
     434  display_text varchar(255) NOT NULL default '', 
     435  extended_text blob NOT NULL, 
     436  link varchar(255) NOT NULL default '', 
     437  `reset` tinyint(4) NOT NULL default '0', 
     438  `timestamp` int(11) NOT NULL default '0', 
     439  PRIMARY KEY  (module,id) 
     440) 
     441 
    425442 
    426443/*!40000 ALTER TABLE `zap` DISABLE KEYS */; 
  • freepbx/branches/2.3/upgrades/2.3.0beta2/tables.php

    r4293 r4349  
    11<?php 
    22 
    3 /* merge_ext_followme($dest) { 
    4  *  
    5  * The purpose of this function is to take a destination 
    6  * that was either a core extension OR a findmefollow-destination 
    7  * and convert it so that they are merged and handled just like 
    8  * direct-did routing 
     3/* Convert all the core voicemail destinations that were previously controlled 
     4 * by the global setting of busy vs. unavail to the new format that allows a 
     5 * per voicemail box choice. 
     6 */ 
     7convert_destinations('convert_voicemail_dest'); 
     8 
     9/* This function takes as input an old style voicemail destination: 
    910 * 
    10  * Assuming an extension number of 222: 
     11 *   ext-local,${VM_PREFIX}222,1 
    1112 * 
    12  * The two formats that existed for findmefollow were: 
     13 * and converts it to a new style voicemail destination by looking at 
     14 * the current system default. So if busy, you would get the following: 
    1315 * 
    14  * ext-findmefollow,222,1 
    15  * ext-findmefollow,FM222,1 
    16  * 
    17  * The one format that existed for core was: 
    18  * 
    19  * ext-local,222,1 
    20  * 
    21  * In all those cases they should be converted to: 
    22  * 
    23  * from-did-direct,222,1 
    24  * 
     16 *   ext-local,vmb200,1 
    2517 */ 
    26 function merge_ext_followme($dest) { 
    27  
    28   if (preg_match("/^\s*ext-findmefollow,(FM)?(\d+),(\d+)/",$dest,$matches) || 
    29       preg_match("/^\s*ext-local,(FM)?(\d+),(\d+)/",$dest,$matches) ) { 
    30         // matches[2] => extn 
    31         // matches[3] => priority 
    32     return "from-did-direct,".$matches[2].",".$matches[3]; 
     18function convert_voicemail_dest($dest) { 
     19  global $db; 
     20 
     21  // Get the current default VM type to make the conversion with 
     22  // 
     23  $sql = "SELECT value FROM globals WHERE variable = 'VM_DDTYPE' "; 
     24  $vm_ddtype = $db->getOne($sql); 
     25  if(DB::IsError($vm_ddtype)) { 
     26    // Should really be there but if not, just set to unavailable. 
     27    // 
     28    $vm_ddtype = 'u'; 
     29  } 
     30 
     31  if (strstr($vm_ddtype,'b') === false) { 
     32    $prefix = 'vmu'; 
     33  } else { 
     34    $prefix = 'vmb'; 
     35  } 
     36  if ( preg_match('/^\s*ext-local,\$\{VM_PREFIX\}(\d+),1/',$dest,$matches) ) { 
     37        // matches[1] => extn 
     38    return "ext-local,$prefix".$matches[1].",1"; 
    3339  } else { 
    3440    return $dest; 
     
    3642} 
    3743 
    38 outn("Upgrading Inbound Routing to allow for Music on Hold per DID.."); 
    39  
    40 $sql = "SELECT mohclass FROM incoming"; 
    41 $confs = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
    42 if (!DB::IsError($confs)) { // no error... Already done 
    43   out("Not Required"); 
    44 } else { 
    45   $sql = "ALTER TABLE incoming ADD mohclass VARCHAR ( 80 ) DEFAULT \"default\""; 
    46   $results = $db->query($sql); 
    47   if(DB::IsError($results)) { 
    48           die($results->getMessage()); 
    49   } 
    50   out("Done"); 
     44function convert_destinations($convert_dest) { 
     45 
     46  global $db; 
     47 
     48  if (!function_exists($convert_dest)) { 
     49    out("ERROR: no such function $convert_dest)"; 
     50    return false; 
     51  } 
     52 
     53  // CORE: 
     54  // 
     55  outn("converting voicemail destinations in core module.."); 
     56  $results = array(); 
     57  $sql = "SELECT cidnum, extension, destination FROM incoming"; 
     58  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     59  if (DB::IsError($results)) { // error - table must not be there 
     60    out("Error - no incoming table"); 
     61  } else { 
     62    foreach ($results as $result) { 
     63      $old_dest  = $result['destination']; 
     64      $extension = $result['extension']; 
     65      $cidnum    = $result['cidnum']; 
     66   
     67      $new_dest = $convert_dest(trim($old_dest)); 
     68      if ($new_dest != $old_dest) { 
     69        $sql = "UPDATE incoming SET destination = '$new_dest' WHERE cidnum = '$cidnum' AND extension = '$extension' AND destination = '$old_dest'"; 
     70        $results = $db->query($sql); 
     71        if(DB::IsError($results)) { 
     72          die($results->getMessage()); 
     73        } 
     74      } 
     75    } 
     76    out("Done"); 
     77  } 
     78   
     79  // ANNOUCEMENT: 
     80  // 
     81  outn("converting voicemail destinations in announcement module.."); 
     82  $results = array(); 
     83  $sql = "SELECT announcement_id, post_dest FROM announcement"; 
     84  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     85  if (DB::IsError($results)) { // error - table must not be there 
     86    out("no announcement table"); 
     87  } else { 
     88    foreach ($results as $result) { 
     89      $old_dest  = $result['post_dest']; 
     90      $announcement_id    = $result['announcement_id']; 
     91   
     92      $new_dest = $convert_dest(trim($old_dest)); 
     93      if ($new_dest != $old_dest) { 
     94        $sql = "UPDATE announcement SET post_dest = '$new_dest' WHERE announcement_id = $announcement_id  AND post_dest = '$old_dest'"; 
     95        $results = $db->query($sql); 
     96        if(DB::IsError($results)) { 
     97          die($results->getMessage()); 
     98        } 
     99      } 
     100    } 
     101    out("Done"); 
     102  } 
     103   
     104  // CALLBACK: 
     105  // 
     106  outn("converting voicemail destinations in callback module.."); 
     107  $results = array(); 
     108  $sql = "SELECT callback_id, destination FROM callback"; 
     109  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     110  if (DB::IsError($results)) { // error - table must not be there 
     111    out("no callback table"); 
     112  } else { 
     113    foreach ($results as $result) { 
     114      $old_dest  = $result['destination']; 
     115      $callback_id    = $result['callback_id']; 
     116   
     117      $new_dest = $convert_dest(trim($old_dest)); 
     118      if ($new_dest != $old_dest) { 
     119        $sql = "UPDATE callback SET destination = '$new_dest' WHERE callback_id = $callback_id  AND destination = '$old_dest'"; 
     120        $results = $db->query($sql); 
     121        if(DB::IsError($results)) { 
     122          die($results->getMessage()); 
     123        } 
     124      } 
     125    } 
     126    out("Done"); 
     127  } 
     128   
     129  // FINDMEFOLLOW: 
     130  // 
     131  outn("converting voicemail destinations in findmefollow module.."); 
     132  $results = array(); 
     133  $sql = "SELECT grpnum, postdest FROM findmefollow"; 
     134  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     135  if (DB::IsError($results)) { // error - table must not be there 
     136    out("no findmefollow table"); 
     137  } else { 
     138    foreach ($results as $result) { 
     139      $old_dest  = $result['postdest']; 
     140      $grpnum    = $result['grpnum']; 
     141   
     142      $new_dest = $convert_dest(trim($old_dest)); 
     143      if ($new_dest != $old_dest) { 
     144        $sql = "UPDATE findmefollow SET postdest = '$new_dest' WHERE grpnum = $grpnum  AND postdest = '$old_dest'"; 
     145        $results = $db->query($sql); 
     146        if(DB::IsError($results)) { 
     147          die($results->getMessage()); 
     148        } 
     149      } 
     150    } 
     151    out("Done"); 
     152  } 
     153   
     154  // IVR: 
     155  // 
     156  outn("converting voicemail destinations in miscapp module.."); 
     157  $results = array(); 
     158  $sql = "SELECT ivr_id, selection, dest FROM ivr_dests"; 
     159  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     160  if (DB::IsError($results)) { // error - table must not be there 
     161    out("no ivr_dests table"); 
     162  } else { 
     163    foreach ($results as $result) { 
     164      $old_dest  = $result['dest']; 
     165      $ivr_id    = $result['ivr_id']; 
     166      $selection = $result['selection']; 
     167   
     168      $new_dest = $convert_dest(trim($old_dest)); 
     169      if ($new_dest != $old_dest) { 
     170        $sql = "UPDATE ivr_dests SET dest = '$new_dest' WHERE ivr_id = $ivr_id AND selection = '$selection' AND dest = '$old_dest'"; 
     171        $results = $db->query($sql); 
     172        if(DB::IsError($results)) { 
     173          die($results->getMessage()); 
     174        } 
     175      } 
     176    } 
     177    out("Done"); 
     178  } 
     179   
     180  // MISCAPP: 
     181  // 
     182  outn("converting voicemail destinations in miscapp module.."); 
     183  $results = array(); 
     184  $sql = "SELECT miscapps_id, dest FROM miscapps"; 
     185  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     186  if (DB::IsError($results)) { // error - table must not be there 
     187    out("no miscapp table"); 
     188  } else { 
     189    foreach ($results as $result) { 
     190      $old_dest    = $result['dest']; 
     191      $miscapps_id = $result['miscapps_id']; 
     192   
     193      $new_dest = $convert_dest(trim($old_dest)); 
     194      if ($new_dest != $old_dest) { 
     195        $sql = "UPDATE miscapps SET dest = '$new_dest' WHERE miscapps_id = $miscapps_id  AND dest = '$old_dest'"; 
     196        $results = $db->query($sql); 
     197        if(DB::IsError($results)) { 
     198          die($results->getMessage()); 
     199        } 
     200      } 
     201    } 
     202    out("Done"); 
     203  } 
     204   
     205  // PARKING: 
     206  // 
     207  outn("converting voicemail destinations in queues module.."); 
     208  $results = array(); 
     209  $sql = "SELECT id, keyword, data FROM parkinglot WHERE keyword = 'goto'"; 
     210  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     211  if (DB::IsError($results)) { // error - table must not be there 
     212    out("no parkinglot table"); 
     213  } else { 
     214    foreach ($results as $result) { 
     215      $old_dest  = $result['data']; 
     216      $id        = $result['id']; 
     217      $keyword   = $result['keyword']; 
     218   
     219      $new_dest = $convert_dest(trim($old_dest)); 
     220      if ($new_dest != $old_dest) { 
     221        $sql = "UPDATE parkinglot SET data = '$new_dest' WHERE id = '$id'  AND keyword = '$keyword' AND data = '$old_dest'"; 
     222        $results = $db->query($sql); 
     223        if(DB::IsError($results)) { 
     224          die($results->getMessage()); 
     225        } 
     226      } 
     227    } 
     228    out("Done"); 
     229  } 
     230   
     231  // QUEUES: 
     232  // 
     233  outn("converting voicemail destinations in queues module.."); 
     234  $results = array(); 
     235  $sql = "SELECT args, extension, priority FROM extensions WHERE context = 'ext-queues' AND descr = 'jump'"; 
     236  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     237  if (DB::IsError($results)) { // error - table must not be there 
     238    out("no queues table"); 
     239  } else { 
     240    foreach ($results as $result) { 
     241      $old_dest  = $result['args']; 
     242      $extension = $result['extension']; 
     243      $priority  = $result['priority']; 
     244   
     245      $new_dest = $convert_dest(trim($old_dest)); 
     246      if ($new_dest != $old_dest) { 
     247        $sql = "UPDATE extensions SET args = '$new_dest' WHERE extension = '$extension' AND priority = '$priority' AND context = 'ext-queues' AND descr = 'jump' AND args = '$old_dest'"; 
     248        $results = $db->query($sql); 
     249        if(DB::IsError($results)) { 
     250          die($results->getMessage()); 
     251        } 
     252      } 
     253    } 
     254    out("Done"); 
     255  } 
     256   
     257  // RINGGROUPS: 
     258  // 
     259  outn("converting voicemail destinations in ringgroups module.."); 
     260  $results = array(); 
     261  $sql = "SELECT grpnum, postdest FROM ringgroups"; 
     262  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     263  if (DB::IsError($results)) { // error - table must not be there 
     264    out("no ringgroups table"); 
     265  } else { 
     266    foreach ($results as $result) { 
     267      $old_dest  = $result['postdest']; 
     268      $grpnum    = $result['grpnum']; 
     269   
     270      $new_dest = $convert_dest(trim($old_dest)); 
     271      if ($new_dest != $old_dest) { 
     272        $sql = "UPDATE ringgroups SET postdest = '$new_dest' WHERE grpnum = $grpnum  AND postdest = '$old_dest'"; 
     273        $results = $db->query($sql); 
     274        if(DB::IsError($results)) { 
     275          die($results->getMessage()); 
     276        } 
     277      } 
     278    } 
     279    out("Done"); 
     280  } 
     281   
     282  // TIMECONDITIONS: 
     283  // 
     284  outn("converting voicemail destinations in timeconditions module.."); 
     285  $results = array(); 
     286  $sql = "SELECT timeconditions_id, truegoto, falsegoto FROM timeconditions"; 
     287  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     288  if (DB::IsError($results)) { // error - table must not be there 
     289    out("no timeconditions table"); 
     290  } else { 
     291    foreach ($results as $result) { 
     292      $old_false_dest    = $result['falsegoto']; 
     293      $old_true_dest     = $result['truegoto']; 
     294      $timeconditions_id = $result['timeconditions_id']; 
     295   
     296      $new_false_dest = $convert_dest(trim($old_false_dest)); 
     297      $new_true_dest  = $convert_dest(trim($old_true_dest)); 
     298      if (($new_true_dest != $old_true_dest) || ($new_false_dest != $old_false_dest)) { 
     299        $sql = "UPDATE timeconditions SET truegoto = '$new_true_dest', falsegoto = '$new_false_dest' WHERE timeconditions_id = $timeconditions_id  AND truegoto = '$old_true_dest' AND falsegoto ='$old_false_dest'"; 
     300        $results = $db->query($sql); 
     301        if(DB::IsError($results)) { 
     302          die($results->getMessage()); 
     303        } 
     304      } 
     305    } 
     306    out("Done"); 
     307  } 
     308   
     309  // DAYNIGHT: 
     310  // 
     311  outn("converting voicemail destinations in daynight module.."); 
     312  $results = array(); 
     313  $sql = "SELECT ext, dmode, dest FROM daynight WHERE dmode in ('day', 'night')"; 
     314  $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
     315  if (DB::IsError($results)) { // error - table must not be there 
     316    out("no daynight table"); 
     317  } else { 
     318    foreach ($results as $result) { 
     319      $old_dest  = $result['dest']; 
     320      $ext    = $result['ext']; 
     321      $dmode = $result['dmode']; 
     322   
     323      $new_dest = $convert_dest(trim($old_dest)); 
     324      if ($new_dest != $old_dest) { 
     325        $sql = "UPDATE daynight SET dest = '$new_dest' WHERE ext = '$ext' AND dmode = '$dmode' AND dest = '$old_dest'"; 
     326        $results = $db->query($sql); 
     327        if(DB::IsError($results)) { 
     328          die($results->getMessage()); 
     329        } 
     330      } 
     331    } 
     332    out("Done"); 
     333  } 
    51334} 
    52335 
    53 outn("Upgrading Inbound Routing to provide a description field.."); 
    54  
    55 $sql = "SELECT description FROM incoming"; 
    56 $confs = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
    57 if (!DB::IsError($confs)) { // no error... Already done 
    58   out("Not Required"); 
    59 } else { 
    60   $sql = "ALTER TABLE incoming ADD description VARCHAR ( 80 ) NULL"; 
    61   $results = $db->query($sql); 
    62   if(DB::IsError($results)) { 
    63           die($results->getMessage()); 
    64   } 
    65   out("Done"); 
     336 
     337/* Create notifications table used by framework to put warnings, errors, etc. on the dashboard 
     338 */ 
     339outn("creating notifications table.."); 
     340$sql = " 
     341  CREATE TABLE IF NOT EXISTS notifications ( 
     342    module        varchar(24) NOT NULL default '', 
     343    id            varchar(24) NOT NULL default '', 
     344    `level`       int(11) NOT NULL default '0', 
     345    display_text  varchar(255) NOT NULL default '', 
     346    extended_text blob NOT NULL, 
     347    link          varchar(255) NOT NULL default '', 
     348    `reset`       tinyint(4) NOT NULL default '0', 
     349    `timestamp`   int(11) NOT NULL default '0', 
     350    PRIMARY KEY  (module,id) 
     351  ) 
     352  "; 
     353$check = $db->query($sql); 
     354if(DB::IsError($check)) { 
     355  out("ERROR: Can not create notifications table"); 
    66356} 
    67  
    68 outn("Upgrading Inbound Routing to provide a CID Prefix field.."); 
    69  
    70 $sql = "SELECT grppre FROM incoming"; 
    71 $confs = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
    72 if (!DB::IsError($confs)) { // no error... Already done 
    73   out("Not Required"); 
    74 } else { 
    75   $sql = "ALTER TABLE incoming ADD grppre VARCHAR ( 80 ) NULL"; 
    76   $results = $db->query($sql); 
    77   if(DB::IsError($results)) { 
    78           die($results->getMessage()); 
    79   } 
    80   out("Done"); 
    81 
    82  
    83 outn("Upgrading Users/Extension Table to allow for Music on Hold per Direct DID.."); 
    84  
    85 $sql = "SELECT mohclass FROM users"; 
    86 $confs = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
    87 if (!DB::IsError($confs)) { // no error... Already done 
    88   out("Not Required"); 
    89 } else { 
    90   $sql = "ALTER TABLE users ADD mohclass VARCHAR ( 80 ) DEFAULT \"default\""; 
    91   $results = $db->query($sql); 
    92   if(DB::IsError($results)) { 
    93           die($results->getMessage()); 
    94   } 
    95   out("Done"); 
    96 
    97  
    98 $sql = "SELECT sipname FROM users"; 
    99 $confs = $db->getRow($sql, DB_FETCHMODE_ASSOC); 
    100 if (!DB::IsError($confs)) { // no error... Already done 
    101   out("Not Required"); 
    102 } else { 
    103   $sql = "ALTER TABLE users ADD sipname VARCHAR ( 50 ) NULL "; 
    104   $results = $db->query($sql); 
    105   if(DB::IsError($results)) { 
    106           die($results->getMessage()); 
    107   } 
    108   out("Done"); 
    109 
    110  
    111 outn("Checking for Global var VMX_CONTEXT.."); 
    112 $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_CONTEXT'"); 
    113 if (!$nrows) { 
    114   $db->query("insert into globals values ('VMX_CONTEXT', 'from-internal')"); 
    115   out("Created"); 
    116 } else { 
    117   out("Already exists!"); 
    118 
    119  
    120 outn("Checking for Global var VMX_PRI.."); 
    121 $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_PRI'"); 
    122 if (!$nrows) { 
    123   $db->query("insert into globals values ('VMX_PRI', '1')"); 
    124   out("Created"); 
    125 } else { 
    126   out("Already exists!"); 
    127 
    128  
    129 outn("Checking for Global var VMX_TIMEDEST_CONTEXT.."); 
    130 $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_TIMEDEST_CONTEXT'"); 
    131 if (!$nrows) { 
    132   $db->query("insert into globals values ('VMX_TIMEDEST_CONTEXT', '')"); 
    133   out("Created"); 
    134 } else { 
    135   out("Already exists!"); 
    136 
    137  
    138 outn("Checking for Global var VMX_TIMEDEST_EXT.."); 
    139 $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_TIMEDEST_EXT'"); 
    140 if (!$nrows) { 
    141   $db->query("insert into globals values ('VMX_TIMEDEST_EXT', 'dovm')"); 
    142   out("Created"); 
    143 } else { 
    144   out("Already exists!"); 
    145 
    146  
    147 outn("Checking for Global var VMX_TIMEDEST_PRI.."); 
    148 $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_TIMEDEST_PRI'"); 
    149 if (!$nrows) { 
    150   $db->query("insert into globals values ('VMX_TIMEDEST_PRI', '1')"); 
    151   out("Created"); 
    152 } else { 
    153   out("Already exists!"); 
    154 
    155  
    156 outn("Checking for Global var VMX_LOOPDEST_CONTEXT.."); 
    157 $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_LOOPDEST_CONTEXT'"); 
    158 if (!$nrows) { 
    159   $db->query("insert into globals values ('VMX_LOOPDEST_CONTEXT', '')"); 
    160   out("Created"); 
    161 } else { 
    162   out("Already exists!"); 
    163 
    164  
    165 outn("Checking for Global var VMX_LOOPDEST_EXT.."); 
    166 $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_LOOPDEST_EXT'"); 
    167 if (!$nrows) { 
    168   $db->query("insert into globals values ('VMX_LOOPDEST_EXT', 'dovm')"); 
    169   out("Created"); 
    170 } else { 
    171   out("Already exists!"); 
    172 
    173  
    174 outn("Checking for Global var VMX_LOOPDEST_PRI.."); 
    175 $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_LOOPDEST_PRI'"); 
    176 if (!$nrows) { 
    177   $db->query("insert into globals values ('VMX_LOOPDEST_PRI', '1')"); 
    178   out("Created"); 
    179 } else { 
    180   out("Already exists!"); 
    181 
    182  
    183 outn("Checking for Global var VMX_OPTS_TIMEOUT.."); 
    184 $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_OPTS_TIMEOUT'"); 
    185 if (!$nrows) { 
    186   $db->query("insert into globals values ('VMX_OPTS_TIMEOUT', '')"); 
    187   out("Created"); 
    188 } else { 
    189   out("Already exists!"); 
    190 
    191  
    192 outn("Checking for Global var VMX_OPTS_LOOP.."); 
    193 $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_OPTS_LOOP'"); 
    194 if (!$nrows) { 
    195   $db->query("insert into globals values ('VMX_OPTS_LOOP', '')"); 
    196   out("Created"); 
    197 } else { 
    198   out("Already exists!"); 
    199 
    200  
    201 outn("Checking for Global var VMX_OPTS_DOVM.."); 
    202 $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_OPTS_DOVM'"); 
    203 if (!$nrows) { 
    204   $db->query("insert into globals values ('VMX_OPTS_DOVM', '')"); 
    205   out("Created"); 
    206 } else { 
    207   out("Already exists!"); 
    208 
    209  
    210 outn("Checking for Global var VMX_TIMEOUT.."); 
    211 $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_TIMEOUT'"); 
    212 if (!$nrows) { 
    213   $db->query("insert into globals values ('VMX_TIMEOUT', '2')"); 
    214   out("Created"); 
    215 } else { 
    216   out("Already exists!"); 
    217 
    218  
    219 outn("Checking for Global var VMX_REPEAT.."); 
    220 $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_REPEAT'"); 
    221 if (!$nrows) { 
    222   $db->query("insert into globals values ('VMX_REPEAT', '1')"); 
    223   out("Created"); 
    224 } else { 
    225   out("Already exists!"); 
    226 
    227  
    228 outn("Checking for Global var VMX_LOOPS.."); 
    229 $nrows = $db->getOne("SELECT count(*) from globals where variable='VMX_LOOPS'"); 
    230 if (!$nrows) { 
    231   $db->query("insert into globals values ('VMX_LOOPS', '1')"); 
    232   out("Created"); 
    233 } else { 
    234   out("Already exists!"); 
    235 
    236  
    237 outn("Checking for Global var TRANSFER_CONTEXT.."); 
    238 $nrows = $db->getOne("SELECT count(*) from globals where variable='TRANSFER_CONTEXT'"); 
    239 if (!$nrows) { 
    240   $db->query("insert into globals values ('TRANSFER_CONTEXT', 'from-internal-xfer')"); 
    241   out("Created"); 
    242 } else { 
    243   out("Already exists!"); 
    244 
    245  
    246 outn("Alter tables incoming to increase field length.. "); 
    247 $db->query("ALTER TABLE incoming CHANGE alertinfo alertinfo VARCHAR( 255 ) NULL"); 
    248 out("Altered"); 
    249  
    250 outn("Merging findmefollow and core extension destinations for incoming routes.."); 
    251  
    252 $results = array(); 
    253 $sql = "SELECT cidnum, extension, destination FROM incoming"; 
    254 $results = $db->getAll($sql, DB_FETCHMODE_ASSOC); 
    255 if (DB::IsError($results)) { // error - table must not be there 
    256   out("Not Required"); 
    257 } else { 
    258   foreach ($results as $result) { 
    259     $old_dest  = $result['destination']; 
    260     $extension = $result['extension']; 
    261     $cidnum    = $result['cidnum']; 
    262  
    263     $new_dest = merge_ext_followme(trim($old_dest)); 
    264     if ($new_dest != $old_dest) { 
    265       $sql = "UPDATE incoming SET destination = '$new_dest' WHERE cidnum = '$cidnum' AND extension = '$extension' AND destination = '$old_dest'"; 
    266       $results = $db->query($sql); 
    267       if(DB::IsError($results)) { 
    268         die($results->getMessage()); 
    269       } 
    270     } 
    271   } 
    272   out("Done"); 
    273 
     357out("Done"); 
    274358 
    275359?>