Changeset 10850

Show
Ignore:
Timestamp:
01/08/11 22:45:06 (2 years ago)
Author:
p_lindheimer
Message:

remove IVR migrations code and keep admin table for one-off tracking, WARNING: needs testing once merged back from bootstrap branch

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/bootstrap-2.9/directory/functions.inc.php

    r10795 r10850  
    352352   
    353353  if ($default_directory) { 
    354     sql("REPLACE INTO `directory` (`key`, value) VALUES ('default_directory', '$default_directory')"); 
     354    sql("REPLACE INTO `admin` (`key`, value) VALUES ('default_directory', '$default_directory')"); 
    355355  } else { 
    356     sql("DELETE FROM `directory` WHERE `key` = 'default_directory'"); 
     356    sql("DELETE FROM `admin` WHERE `key` = 'default_directory'"); 
    357357  } 
    358358} 
     
    361361  global $db; 
    362362 
    363   $ret = sql("SELECT value FROM `directory` WHERE `key` = 'default_directory'", 'getOne'); 
     363  $ret = sql("SELECT value FROM `admin` WHERE `key` = 'default_directory'", 'getOne'); 
    364364  return $ret ? $ret : ''; 
    365365 
  • modules/branches/bootstrap-2.9/directory/install.php

    r10796 r10850  
    4141    audio varchar(50), 
    4242    dial varchar(50) default '' 
    43   )"; 
    44  
    45 $sql[] = "CREATE TABLE IF NOT EXISTS directory ( 
    46     `key` varchar(50) UNIQUE key, 
    47     `value` varchar(150) 
    4843  )"; 
    4944 
     
    121116} 
    122117 
    123 //move defualt dir info in to directory table 
    124 $defdir = $db->getOne("SELECT value FROM `admin` WHERE `key` = 'default_directory'"); 
    125 if (isset($defdir) && $defdir) { 
    126   $q = $db->query("REPLACE INTO `directory` (`key`, value) VALUES ('default_directory', '$defdir')"); 
    127   if(DB::IsError($q)) {  
    128     die_freepbx(_('Error migrating to new directory! ERROR: Unable to migrate. The default directory setting. You may need to reset this manually. ' . $q->getDebugInfo())); 
    129   } 
    130   $db->query("DELETE FROM `admin` WHERE variable = 'default_directory"); 
    131 
     118//check to see if there is a need to migrate from legacy directory 
     119$migrated = $db->getOne("SELECT value FROM `admin` WHERE `key` = 'directory28_migrated'"); 
    132120 
    133 //check to see if there is a need to migrate from legacy directory 
    134 $migrated = $db->getOne("SELECT value FROM `directory` WHERE `key` = 'directory28_migrated'"); 
    135  
    136  
     121// TODO: restrucutre without the die_freepbx() where it is not critical (e.g. creating new directory failures 
     122//       should not kill the install 
    137123if (!$migrated) { 
    138124  //migrate legacy directories to new directory 
     
    141127  $section = null; 
    142128  $vmusers = array(); 
    143   parse_voicemailconf_directory_migration(rtrim($amp_conf["ASTETCDIR"],"/")."/voicemail.conf", $vmconf, $section); 
     129  parse_voicemailconf(rtrim($amp_conf["ASTETCDIR"],"/")."/voicemail.conf", $vmconf, $section); 
    144130  if (isset($vmconf) && $vmconf) { 
    145131    foreach ($vmconf['default'] as $ext => $vm) { 
     
    181167    } 
    182168   
    183     //set as defualt directory 
     169    //set as default directory 
    184170    if (!isset($def_dir) || !$def_dir) { 
    185       out(_("Setting migrated directory as defualt")); 
     171      out(_("Setting migrated directory as default")); 
    186172      $sql = 'REPLACE INTO `directory` (`key`, value) VALUES ("default_directory", ?)'; 
    187173      $db->query($sql, $newdir); 
     
    189175  } 
    190176 
    191  
    192   //check to see if were using the directory in ivr's, ensureing that we have ivr's 
    193   $ivr_stat = $db->getOne('SELECT count(*) FROM modules WHERE modulename = "ivr" AND enabled = 1'); 
    194   if(DB::IsError($q)) {  
    195     die_freepbx(_('Error migrating to new directory! ERROR: Could not get Ivr status ' . $q->getDebugInfo())); 
    196   } 
    197   if ($ivr_stat == 1) { 
    198     $count = $db->getOne('SELECT count(*) FROM ivr WHERE displayname != "__install_done"'); 
    199     if(DB::IsError($count)) {  
    200       die_freepbx(_('Error migrating to new directory! ERROR: Could not get count of Ivr\'s using the legacy Directory ' . $q->getDebugInfo())); 
    201     } 
    202   } else { 
    203     $count = 0; 
    204   } 
    205  
    206   //Migrate ivr's if we have ivr's using directory 
    207   if ($count > 0) {  
    208     out(_("Migrating Ivr's to new Directory")); 
    209     //if we were able to set a new directory 
    210     if (isset($newdir) && $newdir){ 
    211       //get al ivr's 
    212       $ivrs = $db->getAll('SELECT * FROM ivr WHERE displayname != "__install_done"', DB_FETCHMODE_ASSOC); 
    213       if(DB::IsError($ivrs)) {  
    214         die_freepbx(_('Error migrating to new directory! ERROR: Could not get all Ivr\'s')); 
    215       } 
    216      
    217       //get misc destinations that might be referencing legacy directory 
    218       $miscdests = $db->getAll('SELECT id FROM miscdests WHERE destdial = "{infoservices:directory}"'); 
    219       foreach ($miscdests as $m) { 
    220         $miscdest[] = 'ext-miscdests,' . $m[0] . ',1'; 
    221       } 
    222       //iterate over ivr's and their entries, looking  for a misc apps that might be legacy directory or a # dest 
    223       foreach ($ivrs as $ivr) { 
    224         out(_("Migrating Ivr " . $ivr['displayname'] . "'s entires to new Directory")); 
    225          
    226         //is this ivr set to use directory? 
    227         $true_opts = array('1', 'on', 'ON', 'CHECKED', 'checked', 'TRUE', 'true'); 
    228         if (in_array($ivr['enable_directory'], $true_opts)) { 
    229           out(_("Removing legacy Directory from Ivr " . $ivr['displayname'] . "'s destinations")); 
    230            
    231           //update ivr dests 
    232           $sql = 'UPDATE ivr_dests SET dest = ? WHERE ivr_id = ? AND '; 
    233           //add misc diests if we have any 
    234           if (isset($miscdest) && $miscdest) { 
    235             $sql .= ' (selection = "#" '; 
    236             $m = array(); 
    237             foreach ($miscdest as $md) { 
    238               $m[] = '"' . $md . '"'; 
    239             } 
    240             $sql .= ' OR dest IN(' . implode(',', $m) . ') )'; 
    241           } else { 
    242             $sql .= ' selection = "#" '; 
    243           } 
    244           $q = $db->query($sql, array($dirdest, $ivr['ivr_id'])); 
    245           if(DB::IsError($q)) {  
    246             die_freepbx(_('Error migrating to new directory! ERROR: Failed to update ivr destinations ' . $q->getDebugInfo())); 
    247           } 
    248            
    249            
    250           //check to ensure that we have a # destination 
    251           $sql = 'SELECT COUNT(*) FROM ivr_dests WHERE ivr_id = ? AND selection = "#"'; 
    252           $pound_count = $db->getOne($sql, array($ivr['ivr_id'])); 
    253            
    254           if ($pound_count < 1) { 
    255             $sql = 'INSERT INTO ivr_dests (ivr_id, selection, dest) VALUES (?, ?, ?)'; 
    256             $q = $db->query($sql, array($ivr['ivr_id'], '#', $dirdest)); 
    257             if(DB::IsError($q)) {  
    258               die_freepbx(_('Error migrating to new directory! ERROR: Failed to add ivr destination # ' . $q->getDebugInfo())); 
    259             } 
    260           } 
    261            
    262           //remove the legacy directroy option from this ivr 
    263           $sql = 'UPDATE ivr SET enable_directory = "" WHERE ivr_id = ?'; 
    264           $q = $db->query($sql, array($ivr['ivr_id'])); 
    265           if(DB::IsError($q)) {  
    266             die_freepbx(_('Error migrating to new directory! ERROR: Failed to unset enable_directory from ivr ' . $q->getDebugInfo())); 
    267           } 
    268         } else {//even if it wasnt set to use the legace directory, ensure that we dont have mics dests pointing at it 
    269           if (isset($miscdest) && $miscdest) { 
    270             $sql = 'UPDATE ivr_dests SET dest = ? WHERE ivr_id = ? AND dest'; 
    271             $m = array(); 
    272             foreach ($miscdest as $md) { 
    273               $m[] = '"' . $md . '"'; 
    274             } 
    275             $sql .= ' IN(' . implode(',', $m) . ')'; 
    276             $q = $db->query($sql, array($dirdest, $ivr['ivr_id'])); 
    277             if(DB::IsError($q)) {  
    278               die_freepbx(_('Error migrating to new directory! ERROR: Failed to update ivr destinations (2) ' . $q->getDebugInfo())); 
    279             } 
    280           }  
    281         } 
    282       }//<--- end ivr foreach loop 
    283     } else { //if we dont have/couldnt create a new directory, assume there are no vm users and disable the option from ivr's 
    284       out(_("Removing legacy Directory from Ivr " . $ivr['displayname'])); 
    285       $q = $db->query('UPDATE ivr SET enable_directory = ""'); 
    286       if(DB::IsError($q)) {  
    287         die_freepbx(_('Error migrating to new directory! ERROR: Failed to unset enable_directory from ivr (2) ' . $q->getDebugInfo())); 
    288       } 
    289     } 
    290   }//<--- end ivr if case 
    291  
    292   //TODO: migrate misc dests if any are using legacy directory 
    293    
    294177  //Seem where done with migration - mark that in the database 
    295   $migrated_dir = (isset($newdir) && $newdir) ? $newdir : 'true'; 
    296   $q = $db->query("REPLACE INTO `directory` (`key`, value) VALUES ('directory28_migrated', '$migrated_dir')"); 
     178  $migrated_dir = (isset($newdir) && $newdir != "") ? $newdir : 'true'; 
     179  $q = $db->query("REPLACE INTO `admin` (`key`, value) VALUES ('directory28_migrated', '$migrated_dir')"); 
    297180  if(DB::IsError($q)) {  
    298181    die_freepbx(_('Error migrating to new directory! ERROR: Unable to mark Directory as migrated. Migration will probobly be run again at next install/upgrade of this module. ' . $q->getDebugInfo())); 
     
    300183  out(_('Migration Complete!')); 
    301184} 
    302  
    303 /** Recursively read voicemail.conf (and any included files) 
    304  * This function coppied from functions.inc.php 
    305  */ 
    306 function parse_voicemailconf_directory_migration($filename, &$vmconf, &$section) { 
    307   if (is_null($vmconf)) { 
    308     $vmconf = array(); 
    309   } 
    310   if (is_null($section)) { 
    311     $section = "general"; 
    312   } 
    313    
    314   if (file_exists($filename)) { 
    315     $fd = fopen($filename, "r"); 
    316     while ($line = fgets($fd, 1024)) { 
    317       if (preg_match("/^\s*(\d+)\s*=>\s*(\d*),(.*),(.*),(.*),(.*)\s*([;#].*)?/",$line,$matches)) { 
    318         // "mailbox=>password,name,email,pager,options" 
    319         // this is a voicemail line  
    320         $vmconf[$section][ $matches[1] ] = array("mailbox"=>$matches[1], 
    321                   "pwd"=>$matches[2], 
    322                   "name"=>$matches[3], 
    323                   "email"=>$matches[4], 
    324                   "pager"=>$matches[5], 
    325                   "options"=>array(), 
    326                   ); 
    327                  
    328         // parse options 
    329         //output($matches); 
    330         foreach (explode("|",$matches[6]) as $opt) { 
    331           $temp = explode("=",$opt); 
    332           //output($temp); 
    333           if (isset($temp[1])) { 
    334             list($key,$value) = $temp; 
    335             $vmconf[$section][ $matches[1] ]["options"][$key] = $value; 
    336           } 
    337         } 
    338       } else if (preg_match('/^(?:\s*)#include(?:\s+)["\']{0,1}([^"\']*)["\']{0,1}(\s*[;#].*)?$/',$line,$matches)) { 
    339         // include another file 
    340          
    341         if ($matches[1][0] == "/") { 
    342           // absolute path 
    343           $filename = trim($matches[1]); 
    344         } else { 
    345           // relative path 
    346           $filename =  dirname($filename)."/".trim($matches[1]); 
    347         } 
    348          
    349         parse_voicemailconf_directory_migration($filename, $vmconf, $section); 
    350          
    351       } else if (preg_match("/^\s*\[(.+)\]/",$line,$matches)) { 
    352         // section name 
    353         $section = strtolower($matches[1]); 
    354       } else if (preg_match("/^\s*([a-zA-Z0-9-_]+)\s*=\s*(.*?)\s*([;#].*)?$/",$line,$matches)) { 
    355         // name = value 
    356         // option line 
    357         $vmconf[$section][ $matches[1] ] = $matches[2]; 
    358       } 
    359     } 
    360     fclose($fd); 
    361   } 
    362 } 
    363185?> 
  • modules/branches/bootstrap-2.9/directory/uninstall.php

    r10795 r10850  
    1111  } 
    1212} 
    13 outn(_('dropping directory_details, directory_entries, directory...')); 
    14 sql('DROP TABLE IF EXISTS directory_details, directory_entries, directory'); 
     13outn(_('dropping directory_details, directory_entries..')); 
     14sql('DROP TABLE IF EXISTS directory_details, directory_entries'); 
     15out(_('ok')); 
     16 
     17outn(_('deleting default_directory and migration tracking keys..')); 
     18sql("DELETE FROM `admin` WHERE `key` = 'default_directory'"); 
     19sql("DELETE FROM `admin` WHERE `key` = 'directory28_migrated'"); 
    1520out(_('ok')); 
    1621?>