cleanRemoteParams.php 1.63 KB
<?php
/*
*  Executable to clean up Remote Params  
*/

    if (!function_exists('__autoload')) {
        function __autoload($class_name) {
                require_once $class_name . '.php';
        }
    }

    $AMDA_IHM = getenv('AMDA_IHM');
     
    require_once $AMDA_IHM."/php/config.php"; 

    if (file_exists(DATAPATH."/RemoteData/Bases.xml")) {
    
        try {
            $client = new SoapClient(DD_WSDL);
        }
        catch  (SoapFault $exception) {
            $msg = $exception->faultstring.PHP_EOL;                           
            exit($msg);
        }
        
        $basesDom = new DomDocument("1.0");
        $basesDom->load(DDSERVICE."/BASE/INFO/Bases.xml"); // Remote from DDBASE/INFO
        foreach ($basesDom->getElementsByTagName("dataCenter") as $center) {
            $id = $center->getAttribute("xml:id");
            if (is_dir(DATAPATH."/RemoteData/$id")) {
                foreach (glob(DATAPATH."/RemoteData/$id/*") as $file) {
                    if (basename($file) == "base.xml") continue;
                    $ds = basename($file,".nc");                    
                    if ($client->isRemoteViAdded($id, strtolower($ds))) continue; // VI exists; do nothing
                    
                    // vi was deleted in DDBASE; delete everything
                    unlink($file);
                    $paramId = strtolower($id)."_".strtolower($ds);
                    foreach (glob(DATAPATH."/RemoteData/PARAMS/$paramId*.xml") as $xml)  unlink($xml);
                    foreach (glob(DATAPATH."/LocalData/ParamDef/$paramId*.xml") as $xml)  unlink($xml);
                }
            }      
        }
    }
?>