Changeset 12798

Show
Ignore:
Timestamp:
10/13/11 12:57:54 (2 years ago)
Author:
p_lindheimer
Message:

add back check with xml2Array.class.php, add optional file_scan_exclude_list to scandirr, replace sed with preg_replace to fix OSX issues

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/branches/2.10/package.php

    r12795 r12798  
    9999  $ver    =  
    100100  $x      = ''; 
     101  $file_scan_exclude_list = array(); 
    101102   
    102103  echo 'Packaging ' . $mod . '...' . PHP_EOL; 
     
    114115    continue; 
    115116  } 
     117  // Run xml script through the exact method that FreePBX currently uses. There have 
     118  // been cases where XML is valid but this method still fails so it won't be caught 
     119  // with the proper XML checer, better here then breaking the online repository 
     120  // 
     121  include_once('xml2Array.class.php'); 
     122  $parser = new xml2ModuleArray($xml); 
     123  $xmlarray = $parser->parseAdvanced($xml); 
    116124   
    117125  //include module specifc hook, if present 
     
    150158  //check php files for syntax errors 
    151159  $bail = false; 
    152   $files = scandirr($mod, true); 
     160  $files = scandirr($mod, true, $file_scan_exclude_list); 
    153161  foreach ($files as $f) { 
    154162    if (pathinfo($f, PATHINFO_EXTENSION) == 'php') { 
     
    188196   
    189197  //update md5 sum 
    190   list($md5) = preg_split('/\s+/', run_cmd($vars['md5'] . ' ' . $filename)); 
    191   run_cmd('sed -i "s|<md5sum>.*</md5sum>|<md5sum>' . $md5 . '</md5sum>|" '  
    192       . $mod . '/module.xml'); 
     198  $module_xml = file_get_contents($mod . '/' . 'module.xml'); 
     199  if(file_exists($filename)) { 
     200    $md5 = md5_file($filename); 
     201    $module_xml = preg_replace('/<md5sum>(.*)<\/md5sum>/i','<md5sum>'.$md5.'</md5sum>',$module_xml); 
     202  } else { 
     203    echo "No Tarball Package found (in debug mode?)" . PHP_EOL; 
     204  } 
    193205   
    194206  //update location 
    195   run_cmd('sed -i "s|<location>.*</location>|<location>release/' . $vars['rver'] . '/' . $filename . '</location>|" '  
    196       . $mod . '/module.xml'); 
     207  if(file_exists($filename)) { 
     208    $module_xml = preg_replace('/<location>(.*)<\/location>/i','<location>' . $vars['rver'] . '/' . $filename . '</location>',$module_xml); 
     209  } 
     210 
     211  file_put_contents($mod . '/' . 'module.xml', $module_xml); 
     212 
    197213   
    198214  //move tarbal to relase dir 
     
    229245 * 
    230246 * @pram string - directory to scan 
    231  * @pram strin - retirn absolute paths 
     247 * @pram string - return absolute paths 
     248 * @pram array - list of excluded files/directories to ignore 
    232249 * @returns array 
    233250 * 
    234251 * @author Moshe Brevda mbrevda => gmail ~ com 
    235252 */ 
    236 function scandirr($dir, $absolute = false) { 
     253function scandirr($dir, $absolute = false, $exclude_list=array()) { 
    237254  $list = array(); 
    238255  if ($absolute) { 
     
    242259   
    243260  //get directory contents 
     261  if (!empty($exclude_list) && in_array(basename($dir), $exclude_list)) { 
     262    return $list; 
     263  } 
    244264  foreach (scandir($dir) as $d) { 
    245265     
    246266    //ignore any of the files in the array 
    247     if (in_array($d, array('.', '..'))) { 
     267    if (in_array($d, array('.', '..', '.svn')) || (!empty($exclude_list) && in_array($d, $exclude_list))) { 
    248268      continue; 
    249269    } 
     
    252272    if (is_dir($dir . '/' . $d)) { 
    253273      if ($absolute) { 
    254         scandirr($dir . '/' . $d, $absolute); 
     274        scandirr($dir . '/' . $d, $absolute, $exclude_list); 
    255275      } else { 
    256         $list[$d] = scandirr($dir . '/' . $d, $absolute); 
     276        $list[$d] = scandirr($dir . '/' . $d, $absolute, $exclude_list); 
    257277      } 
    258278       
     
    265285        $list[] = $d; 
    266286      } 
    267        
    268287    } 
    269288  }