AmdaUpdate.php 5.88 KB
<?php
/**
*   @file AmdaUpdate.php
*   @version $Id: AmdaUpdate.php 2855 2015-04-18 09:34:45Z elena $ 
*   @brief Amda Update/Install Info by DD Server WebServices
*/

   ini_set("soap.wsdl_cache_enabled", "0");

  require_once "config.php"; 
 //  error_reporting(E_ALL);
// if 'install' argument => then system installation!!!! otherwise => updating (without copy)

  $updateOnly = true;
  if (isset($argv[1]))
  {
  	  if ($argv[1] != 'install')
     {
  	    $msg = "Error: Unknown argument ".$argv[1]."!".PHP_EOL;
  	    print_r($msg);
  	    exit(1);
     }
     $updateOnly = false;
  }
    
  
   $amda = new AmdaClient($updateOnly);

/*
*      Get Shared TT id SHAREDTT dir doesn't exist
*/
   if (!$updateOnly) {              
            if (!is_dir(SHAREDPATH)) {
                    system("svn export ".SVN_DDMISSIONSINFO."SHAREDTT ".SHAREDPATH); 
                    $amda->fsmodifyr(SHAREDPATH); 
            }     
        }       


  $locBases = $amda->getAvailableMissions();

    if(is_string($locBases)) {
      $msg = "Warning: No Local Amda Data info exists!".PHP_EOL;
      print_r($msg); 
     }
    else  {

/*
*  update DD_*.xml files for local bases. If 'updateOnly', we keep DD_*.xml that already exists to not erase current user modifications.
*/ 
    $amda->getDDLocalParamsFiles($locBases);
    
/*
*  Update Start Stop for AMDA local data
*/ 
    $ok =   $amda->updateStartStop($locBases);  

/*
 *  Create EPNResource files
 */
    $epnMgr = new EPNResourcesManager($amda);
    $epnMgr->createResources();
    }
/*
 *  Create/update Orbites.xml file
 */ 
  if (!$updateOnly) { 
      $postProcessing = new PostProcessing();
      $postProcessing->createOrbites();
      $postProcessing->createOrbites(LocalDataParam.'InternalParams.xml');
      $postProcessing->createOrbitesInfoFiles($locBases);
    }

/*
*  Get available external bases if exist 
*/
   
   $extBases = $amda->getAvailableExternalBases();
 
/*
*  Update Start Stop for AMDA remote data
*/
   if(is_string($extBases)) {
      $msg = "Warning: No Remote Amda Data info exists!".PHP_EOL;
      print_r($msg); 
     }

   else  {
      $paramMgr = new ParamMgr();
      foreach ($extBases as $extBase) { 
// check connection 
	    if (!$amda->checkRemoteConnection($extBase->nodeValue)) {
		  $msg = "Warning: No connection for ".$extBase->nodeValue.PHP_EOL;  
		  print_r($msg); 
	    } 
	    if ($updateOnly)  { 
		if (!($extBase->hasAttribute('group') && $extBase->getAttribute('group') == 'IMPEX')) {
                    $ok =   $amda->updateRemoteStartStop($extBase->nodeValue);	
                }	   
	    }
// if install - copy base.xml for all Bases
	    else {
		$ok = $amda->getAvailableExternalData($extBase->nodeValue);
 
		if (!$ok) {
		    $msg = "Warning: cannot copy base.xml for ".$extBase->nodeValue.PHP_EOL;
		    print_r($msg);   
		}
// Copy all default datasets descriptions and create default parameters   
                else {
                    if ($extBase->hasAttribute('default') &&  
                             (!($extBase->hasAttribute('group') && $extBase->getAttribute('group') == 'IMPEX'))) {
                              $baseXML = new DomDocument("1.0");
                              $baseId = $extBase->nodeValue;
                              $baseXML->load(RemoteData.$baseId.'/base.xml');
                              $datasets = $baseXML->getElementsByTagName('dataset');
                              $paramMgr->baseId = $baseId;
 
                            foreach ($datasets as $dataset){     
                                if ($baseId !== 'THEMIS') {                   
                                        $infoFileName = $paramMgr->getInfoName($dataset->getAttribute('name'));
                                        $paramMgr->localInfo = RemoteData.$baseId.'/'.$infoFileName;

                                        if (!file_exists($paramMgr->localInfo)) {
                                            $remoteInfo = INFOSITE.'INFO/'.$baseId.'/DATASETS/'.$infoFileName;       
                  // call to DD Server to create new VI
                                            $viId = $dataset->getAttribute('name');

                                            $command = OLD_CLASSPATH.'AddVI '.$paramMgr->dataset2dd($viId).' '.$viId.' '.$baseId;                
                                            system($command, $err);
                  // no data set description; skip this data set  
                                            if(!copy($remoteInfo, $paramMgr->localInfo)) continue;
                                        }

                                        $params = $dataset->getElementsByTagName('parameter');
                                        $paramMgr->remoteViId = $dataset->getAttribute('name');
                                        foreach ($params as $param) {
                                            $paramMgr->paramId = $param->getAttribute('name');
                                            $paramGlobalId =  $param->getAttribute('xml:id');                           
                                            $paramMgr->paramXML = RemoteData.'PARAMS/'.$paramGlobalId.'.xml';                          

                                            $info = $paramMgr->getParamInfo();                                  
                                            if (!file_exists($paramMgr->paramXML) && !$paramMgr->createParamXml($info)) continue;
                                    }
                                }                       
                            }
                        }
                }
            }
        }
      }
     echo 'Start IMPEx user initialisation'.PHP_EOL;

 
   // update IMPEx workspace
    $userID = 'impex'; $userPWD = 'impexfp7'; $sessionID = 'impex';
    $wsUserMgr = new WSUserMgr();
    $wsUserMgr->init($userID, $userPWD, $sessionID);
    $wsUserMgr->makeUserWS();
   
    echo 'IMPEx user was inited'.PHP_EOL;

   echo PHP_EOL.'CHECK LOG IN '.log.PHP_EOL;
?>