Changeset 2103

Show
Ignore:
Timestamp:
06/28/06 04:49:31 (7 years ago)
Author:
diego_iastrubni
Message:

rest move the code which handles the sql execution into a function.
also, we now have 2 sets of updates "sql" and "sqlite", just like in the modules install.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/trunk/install_amp

    r2102 r2103  
    323323} 
    324324 
     325 
     326function install_sqlupdate( $file ) 
     327{ 
     328  global $db; 
     329  global $dryrun; 
     330 
     331  out("-> Running SQL script ".UPGRADE_DIR."/".$version."/".$file); 
     332  // run sql script 
     333  $fd = fopen(UPGRADE_DIR."/".$version."/".$file, "r"); 
     334  $data = ""; 
     335  while (!feof($fd)) { 
     336    $data .= fread($fd, 1024); 
     337  } 
     338  fclose($fd); 
     339 
     340  preg_match_all("/((SELECT|INSERT|UPDATE|DELETE|CREATE|DROP|ALTER).*);\s*\n/Us", $data, $matches); 
     341   
     342  foreach ($matches[1] as $sql) { 
     343    debug($sql); 
     344    if (!$dryrun) { 
     345      $result = $db->query($sql);  
     346      if(DB::IsError($result)) {      
     347        fatal($result->getDebugInfo()."\" while running ".$file."\n");  
     348      } 
     349    } 
     350  } 
     351} 
     352 
    325353/** Install a particular version 
    326354 */ 
     
    328356  global $db; 
    329357  global $dryrun; 
     358  global $amp_conf; 
     359   
     360  $db_engine = $amp_conf["AMPDBENGINE"]; 
    330361   
    331362  if (is_dir(UPGRADE_DIR."/".$version)) { 
     
    334365    while ($file = readdir($dir)) { 
    335366      if (($file[0] != ".") && is_file(UPGRADE_DIR."/".$version."/".$file)) { 
    336         if (strtolower(substr($file,-4)) == ".sql") { 
    337           out("-> Running SQL script ".UPGRADE_DIR."/".$version."/".$file); 
    338           // run sql script 
    339           $fd = fopen(UPGRADE_DIR."/".$version."/".$file, "r"); 
    340           $data = ""; 
    341           while (!feof($fd)) { 
    342             $data .= fread($fd, 1024); 
    343           } 
    344           fclose($fd); 
    345  
    346           preg_match_all("/((SELECT|INSERT|UPDATE|DELETE|CREATE|DROP|ALTER).*);\s*\n/Us", $data, $matches); 
    347            
    348           foreach ($matches[1] as $sql) { 
    349             debug($sql); 
    350             if (!$dryrun) { 
    351               $result = $db->query($sql);  
    352               if(DB::IsError($result)) {      
    353                 fatal($result->getDebugInfo()."\" while running ".$file."\n");  
    354               } 
    355             } 
    356           } 
     367        if ( (strtolower(substr($file,-4)) == ".sqlite") && ($db_engine == "sqlite") ) { 
     368          install_sqlupdate( $file ); 
     369        } 
     370        elseif ((strtolower(substr($file,-4)) == ".sql") && ( ($db_engine  == "mysql")  ||  ($db_engine  == "pgsql")) ) { 
     371          install_sqlupdate( $file ); 
    357372        } 
    358373      }