コード例 #1
0
    CUtil::JSPostUnescape();
    require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_js.php";
    $max_execution_time = 10;
    if (isset($_REQUEST['max_execution_time']) && 0 < intval($_REQUEST['max_execution_time'])) {
        $max_execution_time = intval($_REQUEST['max_execution_time']);
    }
    COption::SetOptionString("catalog", "max_execution_time", $max_execution_time);
    $converted = isset($_REQUEST['converted']) ? intval($_REQUEST['converted']) : 0;
    $last_id = isset($_REQUEST['last_id']) ? intval($_REQUEST['last_id']) : 0;
    $maxMessage = isset($_REQUEST['maxMessage']) ? intval($_REQUEST['maxMessage']) : 0;
    $maxMessagePerStep = isset($_REQUEST['maxMessagePerStep']) ? intval($_REQUEST['maxMessagePerStep']) : 20;
    if ($converted == 0 && $maxMessage == 0) {
        $maxMessage = CCatalogDiscountConvert::GetCountFormat();
    }
    $strSessID = isset($_REQUEST['DC']) ? $_REQUEST['DC'] : '';
    CCatalogDiscountConvert::$intLastConvertID = $last_id;
    CCatalogDiscountConvert::$intConvertPerStep = 0;
    CCatalogDiscountConvert::$intConverted = $converted;
    CCatalogDiscountConvert::$strSessID = $strSessID;
    CCatalogDiscountConvert::ConvertFormatDiscount($maxMessagePerStep, $max_execution_time);
    if (!CCatalogDiscountConvert::$boolEmptyList) {
        $aboutMinute = ($maxMessage - CCatalogDiscountConvert::$intConverted) / CCatalogDiscountConvert::$intConvertPerStep * $max_execution_time / 60;
        $strAbout = $aboutMinute >= 1 ? str_replace('#MIN#', ceil($aboutMinute), GetMessage('CAT_DISC_CONVERT_TOTAL_MIN')) : str_replace('#SEC#', ceil($aboutMinute * 60), GetMessage('CAT_DISC_CONVERT_TOTAL_SEC'));
        CAdminMessage::ShowMessage(array("MESSAGE" => GetMessage("CAT_DISC_CONVERT_IN_PROGRESS"), "DETAILS" => str_replace(array('#COUNT#', '#PERCENT#', '#TIME#'), array($converted, ceil(CCatalogDiscountConvert::$intConverted / $maxMessage * 100), $strAbout), GetMessage('CAT_DISC_CONVERT_TOTAL')), "HTML" => true, "TYPE" => "OK"));
        ?>
<script type="text/javascript">
			BX.closeWait();
			DoNext(<?php 
        echo CCatalogDiscountConvert::$intConverted;
        ?>
, <?php 
コード例 #2
0
 public static function ConvertFormatDiscount($intStep = 20, $intMaxExecutionTime = 15)
 {
     global $DBType;
     global $DB;
     global $APPLICATION;
     self::InitStep();
     $intStep = intval($intStep);
     if (0 >= $intStep) {
         $intStep = 20;
     }
     $startConvertTime = getmicrotime();
     $obDiscount = new CCatalogDiscount();
     $strTableName = '';
     switch (ToUpper($DBType)) {
         case 'MYSQL':
             $strTableName = 'b_catalog_discount';
             break;
         case 'MSSQL':
             $strTableName = 'B_CATALOG_DISCOUNT';
             break;
         case 'ORACLE':
             $strTableName = 'B_CATALOG_DISCOUNT';
             break;
     }
     if (!CCatalogDiscountConvertTmp::CreateTable()) {
         return false;
     }
     if (0 >= self::$intLastConvertID) {
         self::$intLastConvertID = CCatalogDiscountConvertTmp::GetLastID();
     }
     CTimeZone::Disable();
     self::$boolEmptyList = true;
     $rsDiscounts = CCatalogDiscount::GetList(array('ID' => 'ASC'), array('>ID' => self::$intLastConvertID, 'TYPE' => DISCOUNT_TYPE_STANDART, 'VERSION' => CATALOG_DISCOUNT_NEW_VERSION), false, array('nTopCount' => $intStep), array('ID', 'MODIFIED_BY', 'TIMESTAMP_X', 'CONDITIONS', 'NAME'));
     while ($arDiscount = $rsDiscounts->Fetch()) {
         $mxExist = CCatalogDiscountConvertTmp::IsExistID($arDiscount['ID']);
         if (false === $mxExist) {
             self::$intErrors++;
             return false;
         }
         self::$boolEmptyList = false;
         if (0 < $mxExist) {
             self::$intConverted++;
             self::$intConvertPerStep++;
             self::$intLastConvertID = $arDiscount['ID'];
             continue;
         }
         $arFields = array();
         $arFields['MODIFIED_BY'] = $arDiscount['MODIFIED_BY'];
         $arFields['CONDITIONS'] = $arDiscount['CONDITIONS'];
         $mxRes = $obDiscount->Update($arDiscount['ID'], $arFields);
         if (!$mxRes) {
             self::$intErrors++;
             $strError = '';
             if ($ex = $APPLICATION->GetException()) {
                 $strError = $ex->GetString();
             }
             if (empty($strError)) {
                 $strError = GetMessage('BT_MOD_CAT_DSC_FORMAT_ERR');
             }
             self::$arErrors[] = array('ID' => $arDiscount['ID'], 'NAME' => $arDiscount['NAME'], 'ERROR' => $strError);
             if (!CCatalogDiscountConvertTmp::SetID($arDiscount['ID'])) {
                 return false;
             }
             self::$intConverted++;
             self::$intConvertPerStep++;
             self::$intLastConvertID = $arDiscount['ID'];
         } else {
             $arTimeFields = array('~TIMESTAMP_X' => $DB->CharToDateFunction($arDiscount['TIMESTAMP_X'], "FULL"));
             $strUpdate = $DB->PrepareUpdate($strTableName, $arTimeFields);
             if (!empty($strUpdate)) {
                 $strQuery = "UPDATE " . $strTableName . " SET " . $strUpdate . " WHERE ID = " . $arDiscount['ID'] . " AND TYPE = " . DISCOUNT_TYPE_STANDART;
                 $DB->Query($strQuery, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
             }
             if (!CCatalogDiscountConvertTmp::SetID($arDiscount['ID'])) {
                 return false;
             }
             self::$intConverted++;
             self::$intConvertPerStep++;
             self::$intLastConvertID = $arDiscount['ID'];
         }
         if ($intMaxExecutionTime > 0 && getmicrotime() - $startConvertTime > $intMaxExecutionTime) {
             break;
         }
     }
     CTimeZone::Enable();
     if ($intMaxExecutionTime > 2 * (getmicrotime() - $startConvertTime)) {
         self::$intNextConvertPerStep = $intStep * 2;
     } else {
         self::$intNextConvertPerStep = $intStep;
     }
     self::SaveStep();
     return true;
 }