mvTemplates.php 2.01 KB
<?php

     $NEWMETA = getenv('NEWMETA');
     $AMDAINTERNALDIR = getenv('AMDAINTERNALDIR');
     $PARAMTEMPLATEDIR = getenv('ParamTemplate');

     if (empty($NEWMETA)) {
         echo "[ERROR] check if NEWMETA env varibale is defined".PHP_EOL;
         exit(1);
     }

     if (empty($AMDAINTERNALDIR)) {
         echo "[ERROR] check if AMDAINTERNALDIR env varibale is defined".PHP_EOL;
         exit(1);
     }

     if (empty($PARAMTEMPLATEDIR)) {
         echo "[ERROR] check if PARAMTEMPLATEDIR env varibale is defined".PHP_EOL;
         exit(1);
     }
     
     $templateXml = new DomDocument("1.0");
     $templateXml->load($AMDAINTERNALDIR."/ParamTemplateList.xml");
     $paramTemplates =  $templateXml->getElementsByTagName('paramTemplate');
     
     if (!is_dir($PARAMTEMPLATEDIR)) 
		mkdir("$PARAMTEMPLATEDIR");
     
     foreach ($paramTemplates as $template) {    
       $paramId = $template->getAttribute('paramId');
       $fileName = $template->getAttribute('fileName');
       // for spase-list params
       if (file_exists("$NEWMETA/final/$paramId.xml")) {
		echo "Template  ".$paramId.PHP_EOL;
		$from = "$NEWMETA/final/$paramId.xml";
		$to = "$PARAMTEMPLATEDIR/$fileName.xml";	
		
	  	copy($from, $to);
		unlink("$NEWMETA/final/$paramId.xml");
	}
	//  for internal params
	if (file_exists("$AMDAINTERNALDIR/INTERNAL_PARAM_DEF/$paramId.xml")) {
		echo "Template  ".$paramId.PHP_EOL;
		$from = "$AMDAINTERNALDIR/INTERNAL_PARAM_DEF/$paramId.xml";
		$to = "$PARAMTEMPLATEDIR/$fileName.xml";	
	  	copy($from,$to);					
	}
	// for predefined params
	$predefinedNodes = $template->getElementsByTagName('predefined');
	if ($predefinedNodes->length > 0) {
		$paramPredefinedNodes = $predefinedNodes->item(0)->getElementsByTagName('param');
		if ($paramPredefinedNodes->length > 0) {
			if (file_exists("$AMDAINTERNALDIR/PARAM_DEF/$paramId.xml")) {
				echo "Template  ".$paramId.PHP_EOL;
				$from = "$AMDAINTERNALDIR/PARAM_DEF/$paramId.xml";
				$to = "$PARAMTEMPLATEDIR/$fileName.xml";
				copy($from,$to);
			}
		}
	}
     }     
?>