示例#1
0
 public static function CronRun($profileID, $in_cron = "N")
 {
     define("path2export", "/bitrix/php_interface/include/catalog_export/");
     $pr = CProfileAdmin::GetByID($profileID)->Fetch();
     $cron_period = intval($pr['PERIOD']);
     $cron_period = $cron_period <= 0 ? 86400 : $cron_period;
     $data = date("d.m.Y H:i:s", $pr['DATA_START']);
     $d = explode(" ", $data);
     $t = explode(":", $d[1]);
     $cron_hour = intval($t[0]);
     $cron_minute = intval($t[1]);
     $cron_hour = $cron_hour <= 0 ? 0 : $cron_hour;
     $cron_minute = $cron_minute <= 0 ? 0 : $cron_minute;
     $cron_php_path = COption::GetOptionString("acrit.googlemerchant", "php_path");
     $cron_php_path = strlen($cron_php_path) > 0 ? $cron_php_path : getPHPExecutableFromPath();
     if (file_exists($_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php")) {
         CheckDirPath($_SERVER["DOCUMENT_ROOT"] . path2export);
         $tmp_file_size = filesize($_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php");
         $fp = fopen($_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php", "rb");
         $tmp_data = fread($fp, $tmp_file_size);
         fclose($fp);
         $tmp_data = str_replace("#DOCUMENT_ROOT#", $_SERVER["DOCUMENT_ROOT"], $tmp_data);
         $tmp_data = str_replace("#PHP_PATH#", $cron_php_path, $tmp_data);
         $fp = fopen($_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php", "w+");
         fwrite($fp, $tmp_data);
         fclose($fp);
     }
     $cfg_data = "";
     if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg")) {
         $cfg_file_size = filesize($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg");
         $cfg_file_size = $cfg_file_size != 0 ? $cfg_file_size : 1;
         $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", "rb");
         $cfg_data = fread($fp, $cfg_file_size);
         fclose($fp);
     }
     CheckDirPath($_SERVER["DOCUMENT_ROOT"] . path2export . "logs/");
     if ($in_cron == "Y") {
         $cfg_data = preg_replace("#^.*?" . preg_quote(path2export) . "acrit_gm_cron.php " . $profileID . " *>.*?\$#im", "", $cfg_data);
     } else {
         if ($cron_period > 0) {
             $strTime = "0 */" . $cron_period . " * * * ";
         } else {
             $strTime = intval($cron_minute) . " " . intval($cron_hour) . " * * * ";
         }
         if (strlen($cfg_data) > 0) {
             $cfg_data .= "\n";
         }
         $cfg_data = preg_replace("#^.*?" . preg_quote(path2export) . "acrit_gm_cron.php " . $profileID . " *>.*?\$#im", "", $cfg_data);
         $cfg_data .= $strTime . $cron_php_path . " -f " . $_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php " . $profileID . " >" . $_SERVER["DOCUMENT_ROOT"] . path2export . "logs/" . $profileID . ".txt\n";
     }
     CheckDirPath($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/");
     $cfg_data = preg_replace("#[\r\n]{2,}#im", "\n", $cfg_data);
     $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", "wb");
     fwrite($fp, $cfg_data);
     fclose($fp);
     $arRetval = array();
     @exec("crontab " . $_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", $arRetval, $return_var);
 }
        } else {
            LocalRedirect("/bitrix/admin/acrit_googlemerchant_list.php?lang=" . LANG);
        }
    } else {
        if ($e = $APPLICATION->GetException()) {
            $message = new CAdminMessage(GetMessage("gmprofile_save_error"), $e);
        }
        $bVarsFromForm = true;
    }
}
ClearVars();
if ($ID > 0 || $copy) {
    if ($ID) {
        $parser = CProfileAdmin::GetByID($ID);
    } elseif ($copy) {
        $parser = CProfileAdmin::GetByID($copy);
    }
    if (!$parser->ExtractFields("acrit_")) {
        $ID = 0;
    }
}
if ($bVarsFromForm) {
    $DB->InitTableVarsForEdit("b_acrit_list_profile", "", "acrit_");
}
$APPLICATION->SetTitle($ID > 0 ? GetMessage("gmprofile_title_edit") : GetMessage("gmprofile_title_add"));
require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
$aMenu = array(array("TEXT" => GetMessage("gmprofile_list"), "TITLE" => GetMessage("gmprofile_list_title"), "LINK" => "acrit_googlemerchant_list.php?lang=" . LANG, "ICON" => "btn_list"));
if ($ID > 0) {
    $aMenu[] = array("SEPARATOR" => "Y");
    $aMenu[] = array("TEXT" => GetMessage("gmprofile_add"), "TITLE" => GetMessage("rubric_mnu_add"), "LINK" => "acrit_googlemerchant_edit.php?lang=" . LANG, "ICON" => "btn_new");
    $aMenu[] = array("TEXT" => GetMessage("gmprofile_copy"), "TITLE" => GetMessage("rubric_mnu_copy"), "LINK" => "acrit_googlemerchant_edit.php?copy=" . $ID . "&lang=" . LANG, "ICON" => "btn_copy");
示例#3
0
 function __construct($prof)
 {
     global $USER;
     if (!is_object($USER)) {
         $USER = new CUser();
     }
     CModule::IncludeModule("iblock");
     if (CModule::IncludeModule("catalog")) {
         $this->isCat = true;
     } else {
         $this->isCat = false;
     }
     $pro = new CProfileAdmin();
     $cgm = new CGMExport();
     $pr = $pro->GetByID($prof)->Fetch();
     $this->ID = $pr["ID"];
     $this->Name = $pr["NAME"];
     $this->TYPE_RUN = $pr["TYPE_RUN"];
     $this->FEED = $pr["FEED"];
     $this->COMPANY = $pr["COMPANY"];
     $this->SHOPNAME = $pr["SHOPNAME"];
     $this->DOMAIN_NAME = $pr["DOMAIN_NAME"];
     $this->ACTIVE = $pr["ACTIVE"] == "Y" ? true : false;
     $this->ENCODING = $pr["ENCODING"];
     $this->IBLOCK_ID = unserialize(base64_decode($pr["IBLOCK_ID"]));
     $this->SECTION_ID = unserialize(base64_decode($pr["SECTION_ID"]));
     $this->GOOGLE_CATEGORY = unserialize(base64_decode($pr["GOOGLE_CATEGORY"]));
     $this->CONDITIONS = $pr["CONDITIONS"];
     $this->LID = $pr["LID"];
     $this->DETAIL_PAGE_URL = $pr["DETAIL_PAGE_URL"];
     $this->USE_SKU = $pr["USE_SKU"] == "Y" ? true : false;
     $this->CHECK_INCLUDE = $pr["CHECK_INCLUDE"] == "Y" ? true : false;
     $this->FORORDER = $pr["FORORDER"] == "Y" ? true : false;
     $this->OTHER = $pr["OTHER"] == "Y" ? true : false;
     $this->CONDITION_RULE = unserialize(base64_decode($pr["CONDITION_RULE"]));
     $this->PRICE = $pr["PRICE"];
     $this->XML_DATA = unserialize(base64_decode($pr["XML_DATA"]));
     $this->DATA_START = date("d-m-Y h:i:s", $pr["DATA_START"]);
     $this->PERIOD = (int) $pr["PERIOD"];
     $this->USE_XML_FILE = $pr["USE_XML_FILE"] == "Y" ? true : false;
     $this->URL_DATA_FILE = $pr["URL_DATA_FILE"];
     $this->NAMESCHEMA = $pr["NAMESCHEMA"];
     $this->arSelect = array("ID", "CODE", "LID", "NAME", "IBLOCK_ID", "IBLOCK_SECTION_ID", "IBLOCK_CODE", "ACTIVE", "DATE_ACTIVE_FROM", "DATE_ACTIVE_TO", "SORT", "PREVIEW_PICTURE", "PREVIEW_TEXT", "TIMESTAMP_X", "PREVIEW_TEXT_TYPE", "DETAIL_PICTURE", "DETAIL_TEXT", "DETAIL_TEXT_TYPE", "DATE_CREATE", "CREATED_BY", "DETAIL_PAGE_URL");
     $this->Filter = array("LID" => "", "IBLOCK_ID" => "", "SECTION_ID" => "", "ACTIVE" => "Y", "ACTIVE_DATE" => "Y", "INCLUDE_SUBSECTIONS" => "", "IBLOCK_ACTIVE" => "Y", "SECTION_GLOBAL_ACTIVE" => "Y");
     if (is_array($this->GOOGLE_CATEGORY) && sizeof($this->GOOGLE_CATEGORY) > 0) {
         foreach ($this->GOOGLE_CATEGORY as $id => $gogle) {
             $this->GOOGLE_CATEGORY[$id]['THIS'] = text2xml($gogle['THIS'], true, true, $this->ENCODING);
             $this->GOOGLE_CATEGORY[$id]['GOOGLE'] = text2xml($gogle['GOOGLE'], false, true, $this->ENCODING);
         }
     }
     if ($this->isCat) {
         if (is_array($this->IBLOCK_ID)) {
             foreach ($this->IBLOCK_ID as $ibl) {
                 $this->isCatalog[$ibl] = CCatalog::GetByID($ibl) ? true : false;
             }
         } else {
             $this->isCat = false;
         }
     }
     if ($this->isCat && (is_array($this->isCatalog) && sizeof($this->isCatalog) > 0)) {
         foreach ($this->isCatalog as $code => $val) {
             if ($val == 1) {
                 $mxResult = CCatalogSKU::GetInfoByProductIBlock($code);
                 if (is_array($mxResult)) {
                     $this->sku_IBLOCK_ID[$code] = $mxResult['IBLOCK_ID'];
                     $this->sku_PROPERTY[$code] = $mxResult['SKU_PROPERTY_ID'];
                 }
             }
         }
     }
     if (CModule::IncludeModule("currency")) {
         $this->baseCur = CCurrency::GetbaseCurrency();
         if ($this->baseCur == "RUB") {
             $this->baseCur = "RUB";
         }
     } else {
         $this->baseCur = "RUB";
     }
     $this->Filter['INCLUDE_SUBSECTIONS'] = $this->CHECK_INCLUDE ? "Y" : "N";
     if (sizeof($this->IBLOCK_ID) > 0) {
         foreach ($this->IBLOCK_ID as $ibl) {
             $this->arFilter[$ibl] = $this->Filter;
             $this->arFilter[$ibl]["LID"] = $this->LID;
             $this->arFilter[$ibl]["IBLOCK_ID"] = $ibl;
             $this->arFilter[$ibl]["SECTION_ID"] = $this->GetSectionFromIB($ibl);
         }
     }
     if (sizeof($this->CONDITION_RULE) > 0) {
         $fltr = array();
         $skufil = array();
         $tmpFilter = array();
         $tmpFilter1 = array();
         foreach ($this->CONDITION_RULE as $al => $rule) {
             if ($al != "COUNT") {
                 if ($rule['VALUE'] != "" && $rule['RULES'] != "no" && $rule['PROPERTY'] != 0 && !empty($rule['PROPERTY'])) {
                     $tmp = explode("-", $rule['PROPERTY']);
                     $tmp1 = explode("_", $tmp[1]);
                     if (in_array("SKU", $tmp1)) {
                         //add sku filter
                         $skufil[$tmp[0]][] = array("PROPERTY" => $tmp1[1], "RULES" => $rule['RULES'], "VALUE" => $rule['VALUE']);
                     } else {
                         //add filter
                         $fltr[$tmp[0]][] = array("PROPERTY" => $tmp[1], "RULES" => $rule['RULES'], "VALUE" => $rule['VALUE']);
                     }
                 }
             }
         }
         if (is_array($fltr) && sizeof($fltr) > 0) {
             $tmpFilter = $cgm->SQLCondition($fltr);
         }
         if (is_array($skufil) && sizeof($skufil) > 0) {
             $tmpFilter1 = $cgm->SQLCondition($skufil);
         }
         if (sizeof($this->IBLOCK_ID) > 0) {
             foreach ($this->IBLOCK_ID as $ibl) {
                 if (sizeof($tmpFilter[$ibl]) > 0) {
                     foreach ($tmpFilter[$ibl] as $cond) {
                         foreach ($cond as $code => $cnd) {
                             $this->EditFilter($ibl, $code, $cnd);
                         }
                     }
                 }
                 if (sizeof($tmpFilter1[$ibl]) > 0) {
                     foreach ($tmpFilter1[$ibl] as $cond) {
                         foreach ($cond as $code => $cnd) {
                             $this->AddSkuFilter($ibl, $code, $cnd);
                         }
                     }
                 }
             }
         }
     }
     if ($this->CHECK_INCLUDE) {
         foreach ($this->GOOGLE_CATEGORY as $id => $v) {
             $rsParentSection = CIBlockSection::GetByID($id);
             if ($arParentSection = $rsParentSection->GetNext()) {
                 $arFilter = array('ACTIVE' => 'Y', 'IBLOCK_ID' => $arParentSection['IBLOCK_ID'], '>LEFT_MARGIN' => $arParentSection['LEFT_MARGIN'], '<RIGHT_MARGIN' => $arParentSection['RIGHT_MARGIN'], '>DEPTH_LEVEL' => $arParentSection['DEPTH_LEVEL']);
                 $rsSect = CIBlockSection::GetList(array('left_margin' => 'asc'), $arFilter);
                 while ($arSect = $rsSect->GetNext()) {
                     $this->GOOGLE_CATEGORY[$arSect['ID']] = $v;
                 }
             }
         }
     }
     unset($pro);
 }