Changeset 3390

Show
Ignore:
Timestamp:
12/20/06 10:09:10 (6 years ago)
Author:
gregmac
Message:

Merged revisions 3388 via svnmerge from
https://svn.sourceforge.net/svnroot/amportal/freepbx/trunk

........

r3388 | gregmac | 2006-12-20 09:35:19 -0500 (Wed, 20 Dec 2006) | 2 lines


Added error handler for no connection to online repository

........

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/branches/2.2

    • Property svnmerge-integrated changed from /freepbx/trunk:1-3224,3231,3245-3246,3300-3302,3312,3315,3336,3338,3341-3347,3349,3351,3353,3367-3368,3370,3372-3373 to /freepbx/trunk:1-3224,3231,3245-3246,3300-3302,3312,3315,3336,3338,3341-3347,3349,3351,3353,3367-3368,3370,3372-3373,3388
  • freepbx/branches/2.2/amp_conf/htdocs/admin/functions.inc.php

    r3376 r3390  
    10911091/** Get the latest module.xml file for this freePBX version.  
    10921092 * Caches in the database for 5 mintues. 
    1093  * If $module is specified, only returns the data for that module 
     1093 * If $module is specified, only returns the data for that module. 
     1094 * If the module is not found (or none are available for whatever reason), 
     1095 * then null is returned. 
     1096 * 
     1097 * Sets the global variable $module_getonlinexml_error to true if an error 
     1098 * occured getting the module from the repository, false if no error occured, 
     1099 * or null if the repository wasn't checked. Note that this may change in the  
     1100 * future if we decide we need to return more error codes, but as long as it's 
     1101 * a php zero-value (false, null, 0, etc) then no error happened. 
    10941102 */ 
    10951103function module_getonlinexml($module = false) { // was getModuleXml() 
    10961104  global $amp_conf; 
     1105   
     1106  global $module_getonlinexml_error;  // okay, yeah, this sucks, but there's no other good way to do it without breaking BC 
     1107  $module_getonlinexml_error = null; 
     1108   
    10971109  //this should be in an upgrade file ... putting here for now. 
    10981110  sql('CREATE TABLE IF NOT EXISTS module_xml (time INT NOT NULL , data BLOB NOT NULL) TYPE = MYISAM ;'); 
    10991111   
    11001112  $result = sql('SELECT * FROM module_xml','getRow',DB_FETCHMODE_ASSOC); 
     1113  $data = $result['data']; 
     1114   
    11011115  // if the epoch in the db is more than 2 hours old, or the xml is less than 100 bytes, then regrab xml 
    11021116  // Changed to 5 minutes while not in release. Change back for released version. 
     
    11171131    } 
    11181132    //$fn = "/usr/src/freepbx-modules/modules.xml"; 
    1119     $data = file_get_contents($fn); 
    1120     // remove the old xml 
    1121     sql('DELETE FROM module_xml'); 
    1122     // update the db with the new xml 
    1123     $data4sql = addslashes($data); 
    1124     sql('INSERT INTO module_xml (time,data) VALUES ('.time().',"'.$data4sql.'")'); 
    1125   } else { 
    1126 //    echo "using cache"; 
    1127     $data = $result['data']; 
    1128   } 
     1133    $data = @ file_get_contents($fn); 
     1134    $module_getonlinexml_error = empty($data); 
     1135     
     1136    if (!empty($data)) { 
     1137      // remove the old xml 
     1138      sql('DELETE FROM module_xml'); 
     1139      // update the db with the new xml 
     1140      $data4sql = addslashes($data); 
     1141      sql('INSERT INTO module_xml (time,data) VALUES ('.time().',"'.$data4sql.'")'); 
     1142    } 
     1143  } 
     1144   
     1145  if (empty($data)) { 
     1146    // no data, probably couldn't connect online, and nothing cached 
     1147    return null; 
     1148  } 
     1149   
    11291150  //echo time() - $result['time']; 
    11301151  $parser = new xml2ModuleArray($data); 
  • freepbx/branches/2.2/amp_conf/htdocs/admin/page.modules.php

    r3352 r3390  
    129129 
    130130if ($online) { 
    131   $modules_online = module_getonlinexml(); 
    132    
    133   // combine online and local modules 
    134   $modules = $modules_online; 
    135   foreach (array_keys($modules) as $name) { 
    136     if (isset($modules_local[$name])) { 
    137       // combine in any other values in _local that aren't in _online 
    138       $modules[$name] += $modules_local[$name]; 
    139        
    140       // explicitly override these values with the _local ones 
    141       // - should never come from _online anyways, but this is just to be sure 
    142       $modules[$name]['status'] = $modules_local[$name]['status']; 
    143       $modules[$name]['dbversion'] = $modules_local[$name]['dbversion']; 
    144     } else { 
    145       // not local, so it's not installed 
    146       $modules[$name]['status'] = MODULE_STATUS_NOTINSTALLED; 
     131  $modules_online = module_getonlinexml(false, $connect_error); 
     132   
     133  // $module_getonlinexml_error is a global set by module_getonlinexml() 
     134  if ($module_getonlinexml_error) { 
     135    echo "<div class=\"warning\"><p>".sprintf(_("Warning: Cannot connect to online repository (%s). Online modules are not available."), "mirror.freepbx.org")."</p></div><br />"; 
     136    $online = false; 
     137    unset($modules_online); 
     138  } else { 
     139   
     140    // combine online and local modules 
     141    $modules = $modules_online; 
     142    foreach (array_keys($modules) as $name) { 
     143      if (isset($modules_local[$name])) { 
     144        // combine in any other values in _local that aren't in _online 
     145        $modules[$name] += $modules_local[$name]; 
     146         
     147        // explicitly override these values with the _local ones 
     148        // - should never come from _online anyways, but this is just to be sure 
     149        $modules[$name]['status'] = $modules_local[$name]['status']; 
     150        $modules[$name]['dbversion'] = $modules_local[$name]['dbversion']; 
     151      } else { 
     152        // not local, so it's not installed 
     153        $modules[$name]['status'] = MODULE_STATUS_NOTINSTALLED; 
     154      } 
     155    } 
     156    // add any remaining local-only modules 
     157    $modules += $modules_local; 
     158     
     159    // use online categories 
     160    foreach (array_keys($modules) as $modname) { 
     161      if (isset($modules_online[$modname]['category'])) { 
     162        $modules[$modname]['category'] = $modules_online[$modname]['category']; 
     163      } 
    147164    } 
    148165  } 
    149   // add any remaining local-only modules 
    150   $modules += $modules_local; 
    151    
    152   // use online categories 
    153   foreach (array_keys($modules) as $modname) { 
    154     if (isset($modules_online[$modname]['category'])) { 
    155       $modules[$modname]['category'] = $modules_online[$modname]['category']; 
    156     } 
    157   } 
    158 } else { 
     166
     167 
     168if (!isset($modules)) { 
    159169  $modules = & $modules_local; 
    160170}