删除时间检查PHP脚本

时间:2017-03-07 08:49:28

标签: php prestashop prestashop-1.6

我在prestashop中有一个php脚本(应该)下载一个xml文件,然后开始导入过程。该脚本检查上次下载的文件是否与数据库条目中的时间匹配,如果它们不匹配则下载新的xml。这一切都不起作用,因为它应该主要是因为整个if命令是错误的。 (Normaly它应该首先下载文件,然后检查它的时间算术)。无论如何,这都不是必需的,因为文件很小。所以我需要删除这个if语句并下载文件,无论如何替换以前下载的文件。 任何人都可以帮我删除检查日期的if命令吗?

这是剧本:

ini_set('display_errors', 0);
//ini_set('memory_limit', '812M');
set_time_limit(0);

include_once realpath(__DIR__.'/../../')."/config/config.inc.php";
include_once realpath(__DIR__)."/XmlFeedImporter.php";
if( Configuration :: get('CRONRUN_STATUS') && Configuration :: get('PRODUCTXML_URL')){
    $remoteXmlFile = Configuration :: get('PRODUCTXML_URL');
    $url_parts = parse_url($remoteXmlFile);
    $isCLI = ( php_sapi_name() == 'cli' );
    if( $isCLI){
        // For live
        $server_host = $url_parts['host'];
        $server_root = _PS_ROOT_DIR_.'/';
    } else {
        $server_host = $_SERVER['HTTP_HOST'];
        $server_root = $_SERVER['DOCUMENT_ROOT'].'/';    
    }

    $outputLocalCsv = _PS_DOWNLOAD_DIR_.'products_output_'.date('Y-m-d').'.csv';
    $objXmlFeedImporter = new XmlFeedImporter();

    if(strpos($remoteXmlFile,$server_host) === false){
        // CHeck whether same remote file was download or not ?
        if (((int)Configuration :: get('PRODUCTXML_DOWNLOAD_DATE') && (int)Configuration :: get('PRODUCTXML_UPDATE_TIME')) && ((int)Configuration :: get('PRODUCTXML_DOWNLOAD_DATE') > (int)Configuration :: get('PRODUCTXML_UPDATE_TIME'))) {
            $inputLocalXml = _PS_UPLOAD_DIR_.'products_input_'.date('Y-m-d', Configuration :: get('PRODUCTXML_DOWNLOAD_DATE')).'.xml';
        } else {
            $time = time();
            $inputLocalXml = _PS_UPLOAD_DIR_.'products_input_'.date('Y-m-d', $time).'.xml';
            $downloadedBytes = $objXmlFeedImporter->downloadRemoteFile($remoteXmlFile, $inputLocalXml);
            Configuration :: updateValue('PRODUCTXML_DOWNLOAD_DATE', $time);

            if($downloadedBytes == 0){
                d('Nothing was downloaded from '.$remoteXmlFile.' !!');
            }
        }
    } else {
        $file_parts = explode($server_host, $remoteXmlFile);
        if( $server_host == 'localhost'){
            $server_root = str_replace(DS.'my-presta','',$server_root);
        }
        $inputLocalXml = $server_root.trim($file_parts[1],'/');
    }
    //d($inputLocalXml);
    $objXmlFeedImporter->setInputFile($inputLocalXml);
    // Get products in a csv  
    if(Configuration :: get('CREATE_XML2CSV')){
        $objXmlFeedImporter->setOutputFile($outputLocalCsv);   
    }
    //$objXmlFeedImporter->_justCount = true; // just count products
    //$objXmlFeedImporter->_dump = true; // print product data
    try{
        $objXmlFeedImporter->runParser(); // run parser
    } catch(Exception $e){
        // Send Email
        print_r($e);
    }

}
?>

1 个答案:

答案 0 :(得分:0)

我相信这是没有检查的:

ini_set('display_errors', 0);
//ini_set('memory_limit', '812M');
set_time_limit(0);

include_once realpath(__DIR__.'/../../')."/config/config.inc.php";
include_once realpath(__DIR__)."/XmlFeedImporter.php";
if( Configuration :: get('CRONRUN_STATUS') && Configuration :: get('PRODUCTXML_URL')){
    $remoteXmlFile = Configuration :: get('PRODUCTXML_URL');
    $url_parts = parse_url($remoteXmlFile);
    $isCLI = ( php_sapi_name() == 'cli' );
    if( $isCLI){
        // For live
        $server_host = $url_parts['host'];
        $server_root = _PS_ROOT_DIR_.'/';
    } else {
        $server_host = $_SERVER['HTTP_HOST'];
        $server_root = $_SERVER['DOCUMENT_ROOT'].'/';    
    }

    $outputLocalCsv = _PS_DOWNLOAD_DIR_.'products_output_'.date('Y-m-d').'.csv';
    $objXmlFeedImporter = new XmlFeedImporter();

    if(strpos($remoteXmlFile,$server_host) === false){
        // CHeck whether same remote file was download or not ?
        $time = time();
        $inputLocalXml = _PS_UPLOAD_DIR_.'products_input_'.date('Y-m-d', $time).'.xml';

    } else {
        $file_parts = explode($server_host, $remoteXmlFile);
        if( $server_host == 'localhost'){
            $server_root = str_replace(DS.'my-presta','',$server_root);
        }
        $inputLocalXml = $server_root.trim($file_parts[1],'/');
    }

    $downloadedBytes = $objXmlFeedImporter->downloadRemoteFile($remoteXmlFile, $inputLocalXml);
    Configuration :: updateValue('PRODUCTXML_DOWNLOAD_DATE', $time);
    if($downloadedBytes == 0){
             d('Nothing was downloaded from '.$remoteXmlFile.' !!');
        }

    //d($inputLocalXml);
    $objXmlFeedImporter->setInputFile($inputLocalXml);
    // Get products in a csv  
    if(Configuration :: get('CREATE_XML2CSV')){
        $objXmlFeedImporter->setOutputFile($outputLocalCsv);   
    }
    //$objXmlFeedImporter->_justCount = true; // just count products
    //$objXmlFeedImporter->_dump = true; // print product data
    try{
        $objXmlFeedImporter->runParser(); // run parser
    } catch(Exception $e){
        // Send Email
        print_r($e);
    }

}
?>

这似乎是你在谈论的:

if (((int)Configuration :: get('PRODUCTXML_DOWNLOAD_DATE') && (int)Configuration :: get('PRODUCTXML_UPDATE_TIME')) && ((int)Configuration :: get('PRODUCTXML_DOWNLOAD_DATE') > (int)Configuration :: get('PRODUCTXML_UPDATE_TIME')))