getLastRealUpdate.php 1.24 KB
<?php
/** 
*   @file getLastRealUpdate.php
*   @brief Returns modif date of the last modified data file (*.nc.gz) for a given DataSet 
*   @version $Id:  $ 
*/

    if (!isset($_GET['id'])) exit('INPUT ERROR');
    
    require_once './DDserverWeb_ini.php';
    
    error_reporting(E_ERROR | E_WARNING | E_PARSE);

    $replace = array("-" => "_");

    $dataSet = strtr($_GET['id'], $replace); 

    $referXML = baseDir."/DDsys.xml";
    $DDsys = new DOMDocument("1.0");
    $DDsys->load($referXML);
    $xp = new domxpath($DDsys);
    $VI_NAME = $xp->query("//NAME[.='".$dataSet."']");

    if ($VI_NAME->item(0)->nodeValue != NULL)
    {
            $VI = $VI_NAME->item(0)->parentNode;
            $location = $VI->getElementsByTagName("LOCATION")->item(0)->nodeValue;                     
            $find = 'find '.$location.' -name \'*.nc.gz\' -type f -printf \'%T@ %p\n\' | sort -n | tail -1 | cut -f2- -d" "';
            $lastFile = exec($find);
            if (!file_exists($lastFile))
                exit('NO SUCH FILE '.$lastFile);
            $cmd = 'date "+%Y-%m-%dT%H:%M:%SZ" -u -r '.$lastFile;  // for NFS      
            $dateModif = exec($cmd);       
            exit($dateModif); 
    }
    else {
            exit('NO SUCH DATASET');
    }
?>