This is the slightly updated import code in nadmin M5, eventually it will be a page 
with 'upload tarball'..

the config below imports PEAR from /usr/src/midgard/php4/pear..

you need to modify
$importdescription = "PEAR"; // the description on the snippetdirs.
convertsnippetdir("/usr/src/midgard/php4", "pear", 0);
where pear is the directory to import, and the other bit is the directory below it.
This should import & change the include/require etc. to mgd_include_snippet..


regards

alan



<? // convert php3 files and put them into midgard.

 
function get_snippetdir_byname($baseid, $dir) {
  global $importdescription;
  if ($snippetdirs = mgd_list_snippetdirs($baseid)) {
    while ($snippetdirs->fetch()) {
      if ($snippetdirs->name == $dir) return $snippetdirs->id;
    }
  }
  return mgd_create_snippetdir($baseid, $dir, $importdescription, 0);
}  
     
function convertsnippet($baseid, $dir, $file) {
  global $rootdir, $importdescription;
  // read the file
  $contents = implode("", file($dir . "/" . $file));
  // do the include & require replacements!
  $contents = ereg_replace("include\(", "mgd_include_snippet('$rootdir' . ", 
$contents);
  $contents = ereg_replace("require\(", "mgd_include_snippet('$rootdir' . ", 
$contents);
  $contents = ereg_replace("include_once\(", "mgd_include_snippet('$rootdir' . ", 
$contents);
  $contents = ereg_replace("require_once\(", "mgd_include_snippet('$rootdir' . ", 
$contents);
  // does it exist!
  if ($existsnippet = mgd_get_snippet_by_name($baseid, $file)) {
    // then update it!
  echo "updating snippet $file<BR>";
     mgd_update_snippet($existsnippet->id, $file, $contents, $importdescription,0);
  } else {  
  echo "creating snippet $file<BR>";
     mgd_create_snippet($baseid, $file, $contents, $importdescription, 0);
  }
//  print "imported $file";
  // create or update!
}  


function convertsnippetdir($basedir, $dir, $baseid) {
  //  
  global $rootdir;
  if ($dir == "CVS") return;
  // does this snippet dir exist!!!
  // list all snippet dirs in the base!!!
  if (!$baseid) $rootdir = $dir . "/";
  $newbaseid  = get_snippetdir_byname($baseid, $dir); 

  echo "opening dir " .$basedir . "/" . $dir;
  $handle = opendir($basedir . "/" . $dir);
  while ($dirs = readdir($handle)) {
    if ( 
          (filetype($basedir . "/". $dir . "/" .$dirs) == "dir") &&
           (!ereg("^[.]+$", $dirs ))
        ) {
        // then it is a dir!
        // check to see if it exists!
         convertsnippetdir($basedir . "/" . $dir, $dirs , $newbaseid);
    } elseif (
         (filetype($basedir . "/" . $dir . "/" .$dirs) != "dir") &&
          (ereg("\.php", $dirs ))
          ) {
        // then it is a php file! - lets import it!
        convertsnippet($newbaseid, $basedir . "/" . $dir , $dirs);
    }    
  } 
}

$importdescription = "PEAR";
convertsnippetdir("/usr/src/midgard/php4", "pear", 0);
//mmh wonder if this works!!
  //mmh wonder if this works!!
?>

 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to