Changeset 9262

Show
Ignore:
Timestamp:
03/17/10 09:56:16 (2 years ago)
Author:
p_lindheimer
Message:

add versions of deprecated core_routing functions to tables.php for migrations from tarball type installs

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/trunk/upgrades/2.8.0alpha1/tables.php

    r9213 r9262  
    8484        out("ok"); 
    8585 
    86         $routepriority = core_routing_getroutenames(); 
     86        $routepriority = __core_routing_getroutenames(); 
    8787 
    8888        $routes = array(); 
     
    9494          $accum[] = substr($extdisplay,4); 
    9595   
    96           $routecid_array = core_routing_getroutecid($extdisplay); 
     96          $routecid_array = __core_routing_getroutecid($extdisplay); 
    9797          $accum[] = $routecid_array['routecid']; 
    9898          $accum[] = $routecid_array['routecid_mode']; 
    9999 
    100           $accum[] = core_routing_getroutepassword($extdisplay); 
    101           $accum[] = core_routing_getrouteemergency($extdisplay); 
    102           $accum[] = core_routing_getrouteintracompany($extdisplay); 
    103           $accum[] = core_routing_getroutemohsilence($extdisplay); 
    104  
    105           $dialpattern[$extdisplay] = core_routing_getroutepatterns($extdisplay); 
    106           $trunkpriority[$extdisplay] = core_routing_getroutetrunks($extdisplay); 
     100          $accum[] = __core_routing_getroutepassword($extdisplay); 
     101          $accum[] = __core_routing_getrouteemergency($extdisplay); 
     102          $accum[] = __core_routing_getrouteintracompany($extdisplay); 
     103          $accum[] = __core_routing_getroutemohsilence($extdisplay); 
     104 
     105          $dialpattern[$extdisplay] = __core_routing_getroutepatterns($extdisplay); 
     106          $trunkpriority[$extdisplay] = __core_routing_getroutetrunks($extdisplay); 
    107107 
    108108          $routes[$extdisplay] = $accum; 
     
    192192  } 
    193193} 
     194 
     195//----------  DEPRECATED functions added here so installs work from tarball -------------- 
     196 
     197function __core_routing_getroutenames()  
     198{ 
     199  global $amp_conf; 
     200   
     201  if ($amp_conf["AMPDBENGINE"] == "sqlite3")  
     202  { 
     203    $results = sql("SELECT DISTINCT context FROM extensions WHERE context LIKE 'outrt-%' ORDER BY context ","getAll"); 
     204    foreach( array_keys($results) as $idx ) 
     205    { 
     206       $results[$idx][0] = substr( $results[$idx][0], 6); 
     207    } 
     208  } 
     209  else 
     210  { 
     211    $results = sql("SELECT DISTINCT SUBSTRING(context,7) FROM extensions WHERE context LIKE 'outrt-%' ORDER BY context ","getAll"); 
     212  } 
     213  return $results; 
     214} 
     215function __core_routing_getroutecid($route) { 
     216  global $db; 
     217 
     218  $sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-".$route."' AND (args LIKE 'ROUTECID%' OR args LIKE 'EXTEN_ROUTE_CID%') "; 
     219  $results = $db->getOne($sql); 
     220  if(DB::IsError($results)) { 
     221    die_freepbx($results->getMessage()); 
     222  } 
     223  if (preg_match('/^(.*)=(.*)/', $results, $matches)) { 
     224    $routecid = $matches[2]; 
     225    $routecid_mode = $matches[1] == 'ROUTECID' ? 'override_extension':''; 
     226  } else { 
     227    $routecid = ''; 
     228    $routecid_mode = ''; 
     229  } 
     230  return array('routecid' => $routecid, 'routecid_mode' => $routecid_mode); 
     231} 
     232function __core_routing_getroutepassword($route) { 
     233  global $db; 
     234  $sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-".$route."' AND (args LIKE 'dialout-trunk,%' OR args LIKE 'dialout-enum,%' OR args LIKE 'dialout-dundi,%') ORDER BY CAST(priority as UNSIGNED) "; 
     235  $results = $db->getOne($sql); 
     236  if(DB::IsError($results)) { 
     237    die_freepbx($results->getMessage()); 
     238  } 
     239  if (preg_match('/^.*,.*,.*,(\d+|\/\S+)/', $results, $matches)) { 
     240    $password = $matches[1]; 
     241  } else { 
     242    $password = ""; 
     243  } 
     244  return $password; 
     245} 
     246function __core_routing_getrouteemergency($route) { 
     247  global $db; 
     248  $sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-".$route."' AND (args LIKE 'EMERGENCYROUTE%') "; 
     249  $results = $db->getOne($sql); 
     250  if(DB::IsError($results)) { 
     251    die_freepbx($results->getMessage()); 
     252  } 
     253  if (preg_match('/^.*=(.*)/', $results, $matches)) { 
     254    $emergency = $matches[1]; 
     255  } else { 
     256    $emergency = ""; 
     257  } 
     258  return $emergency; 
     259} 
     260function __core_routing_getrouteintracompany($route) { 
     261  global $db; 
     262  $sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-".$route."' AND (args LIKE 'INTRACOMPANYROUTE%') "; 
     263  $results = $db->getOne($sql); 
     264  if(DB::IsError($results)) { 
     265    die_freepbx($results->getMessage()); 
     266  } 
     267  if (preg_match('/^.*=(.*)/', $results, $matches)) { 
     268    $intracompany = $matches[1]; 
     269  } else { 
     270    $intracompany = ""; 
     271  } 
     272  return $intracompany; 
     273} 
     274function __core_routing_getroutemohsilence($route) { 
     275  global $db; 
     276  $sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-".$route."' AND (args LIKE 'MOHCLASS%') "; 
     277  $results = $db->getOne($sql); 
     278  if(DB::IsError($results)) { 
     279    die_freepbx($results->getMessage()); 
     280  } 
     281  if (preg_match('/^.*=(.*)/', $results, $matches)) { 
     282    $mohsilence = $matches[1]; 
     283  } else { 
     284    $mohsilence = ""; 
     285  } 
     286  return $mohsilence; 
     287} 
     288function __core_routing_getroutepatterns($route) { 
     289  global $db; 
     290  $sql = "SELECT extension, args FROM extensions WHERE context = 'outrt-".$route."' AND (args LIKE 'dialout-trunk%' OR args LIKE 'dialout-enum%' OR args LIKE 'dialout-dundi%') ORDER BY extension "; 
     291  $results = $db->getAll($sql); 
     292  if(DB::IsError($results)) { 
     293    die_freepbx($results->getMessage()); 
     294  } 
     295   
     296  $patterns = array(); 
     297  foreach ($results as $row) { 
     298    if ($row[0][0] == "_") { 
     299      // remove leading _ 
     300      $pattern = substr($row[0],1); 
     301    } else { 
     302      $pattern = $row[0]; 
     303    } 
     304     
     305    if (preg_match("/{EXTEN:(\d+)}/", $row[1], $matches)) { 
     306      // this has a digit offset, we need to insert a | 
     307      $pattern = substr($pattern,0,$matches[1])."|".substr($pattern,$matches[1]); 
     308    } 
     309     
     310    $patterns[] = $pattern; 
     311  } 
     312  return array_unique($patterns); 
     313} 
     314function __core_routing_getroutetrunks($route) { 
     315  global $db; 
     316  $sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-".$route."' AND (args LIKE 'dialout-trunk,%' OR args LIKE 'dialout-enum,%' OR args LIKE 'dialout-dundi,%') ORDER BY CAST(priority as UNSIGNED) "; 
     317  $results = $db->getAll($sql); 
     318  if(DB::IsError($results)) { 
     319    die_freepbx($results->getMessage()); 
     320  } 
     321  $trunks = array(); 
     322  foreach ($results as $row) { 
     323    if (preg_match('/^dialout-trunk,(\d+)/', $row[0], $matches)) { 
     324      // check in_array -- even though we did distinct 
     325      // we still might get ${EXTEN} and ${EXTEN:1} if they used | to split a pattern 
     326      if (!in_array("OUT_".$matches[1], $trunks)) { 
     327        $trunks[] = "OUT_".$matches[1]; 
     328      } 
     329    } else if (preg_match('/^dialout-enum,(\d+)/', $row[0], $matches)) { 
     330      if (!in_array("OUT_".$matches[1], $trunks)) { 
     331        $trunks[] = "OUT_".$matches[1]; 
     332      } 
     333    } else if (preg_match('/^dialout-dundi,(\d+)/', $row[0], $matches)) { 
     334      if (!in_array("OUT_".$matches[1], $trunks)) { 
     335        $trunks[] = "OUT_".$matches[1]; 
     336      } 
     337    } 
     338  } 
     339  return $trunks; 
     340}