Your IP : 18.117.142.51


Current Path : /home/bitrix/ext_www/dev.ballu.in.ua/local/import/
Upload File :
Current File : /home/bitrix/ext_www/dev.ballu.in.ua/local/import/import.php

<?
$options = array(/*'services',*/ 'dealers', 'dealers2');
if (!(isset($argv[1]) && in_array($argv[1], $options)))
    die('Need type '.implode(' | ', $options));

$_SERVER["DOCUMENT_ROOT"] = realpath(dirname(__FILE__)."/../..");
$DOCUMENT_ROOT = $_SERVER["DOCUMENT_ROOT"];

define("NO_KEEP_STATISTIC", true);
define("NOT_CHECK_PERMISSIONS",true);
define("BX_CRONTAB", true);
define('BX_NO_ACCELERATOR_RESET', true);
define('SITE_ID', 's1');

require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule("iblock");

$option = $argv[1];
if ($option == 'all' || $option == 'downloadSource')
{
    //заказчиваем данные
    $curl = curl_init();
    $source = dirname(__FILE__).'/source/export.zip';
    $file = fopen($source, 'w');
    curl_setopt($curl, CURLOPT_URL, "ftp://ftp.mag.travel/export.zip"); #input
    curl_setopt($curl, CURLOPT_TIMEOUT, 500);
    curl_setopt($curl, CURLOPT_FILE, $file); 
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    //curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_USERPWD, "ftpclient:fefozaz<");
    curl_exec($curl);
    curl_close($curl);
    fclose($file);

    //распаковываем
    $unzip = new ZipArchive;
    $out = $unzip->open($source);
    if ($out === TRUE) {
      $unzip->extractTo(dirname(__FILE__).'/source/');
      $unzip->close();
      print  'File unzipped';
    } else {
      print 'Something went wrong?';
    }
}
GlOBAL $DB, $USER;
set_time_limit(0);
$options = array($option);
if ($option == 'downloadSource')
{
    $options = array();
}
else
{
    $options = array($option);
}
foreach($options as $type)
{
    $className = ucfirst($type).'Parser';
    require_once($className.'.php');
    $file = dirname(__FILE__).'/source/'.$type.'.xml';
    $log_file = dirname(__FILE__).'/logs/'.$type.'.log';
    try 
    {
        $log = fopen($log_file, "w");
        $XmlParser = new $className($DB, $log);
        $XmlParser->message_to_log('Parsing');
        $XmlParser->beginParsing();
        $xml_parser = xml_parser_create("UTF-8");
        xml_set_object($xml_parser, $XmlParser);
        xml_parser_set_option($xml_parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
        //xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, 1);
        xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
        xml_set_element_handler($xml_parser, "tagOpen", "tagClosed");
        xml_set_default_handler($xml_parser, "tagData");
        $in = fopen($file, "r");
        while (!feof($in))
        {       
            xml_parse($xml_parser, fgets($in, 4096 * 10));
        }
        fclose($in);
        if (xml_get_error_code($xml_parser))
        {
            $XmlParser->message_to_log('Error ' . 
                xml_error_string(xml_get_error_code($xml_parser)) . 
                ' line ' . xml_get_current_line_number($xml_parser));
        }
        xml_parser_free($xml_parser);
        $XmlParser->endParsing();
        $XmlParser->message_to_log('Parsing is ready');
    } 
    catch (Exception $e) 
    {
        $XmlParser->message_to_log('Error: ' . $e->getMessage());
    }
    fclose($log);
    unset($XmlParser);
}