24 if (self::$strSessID ==
'')
25 self::$strSessID =
'DC'.time();
26 if (isset($_SESSION[self::$strSessID]) && is_array($_SESSION[self::$strSessID]))
28 if (isset($_SESSION[self::$strSessID][
'ERRORS_COUNT']) && (
int)$_SESSION[self::$strSessID][
'ERRORS_COUNT'] > 0)
29 self::$intErrors = (int)$_SESSION[self::$strSessID][
'ERRORS_COUNT'];
30 if (isset($_SESSION[self::$strSessID][
'ERRORS']) && is_array($_SESSION[self::$strSessID][
'ERRORS']))
31 self::$arErrors = $_SESSION[self::$strSessID][
'ERRORS'];
63 $intStep = (int)$intStep;
66 $startConvertTime = microtime(
true);
70 $strQueryPriceTypes =
'';
71 $strQueryUserGroups =
'';
74 $strQueryPriceTypes =
'select CATALOG_GROUP_ID from b_catalog_discount2cat where DISCOUNT_ID = #ID#';
75 $strQueryUserGroups =
'select GROUP_ID from b_catalog_discount2group where DISCOUNT_ID = #ID#';
76 $strTableName =
'b_catalog_discount';
87 array(
'nTopCount' => $intStep),
88 array(
'ID',
'MODIFIED_BY',
'TIMESTAMP_X',
'NAME',
'ACTIVE')
90 while ($arDiscount = $rsDiscounts->Fetch())
93 $arSrcEntity =
array();
96 'MODIFIED_BY' => $arDiscount[
'MODIFIED_BY'],
97 'ACTIVE' => $arDiscount[
'ACTIVE']
100 $arPriceTypes =
array();
101 $arUserGroups =
array();
103 $rsPriceTypes =
$DB->Query(str_replace(
'#ID#', $arDiscount[
'ID'], $strQueryPriceTypes));
104 while ($arPrice = $rsPriceTypes->Fetch())
106 $arPrice[
'CATALOG_GROUP_ID'] = (int)$arPrice[
'CATALOG_GROUP_ID'];
107 if ($arPrice[
'CATALOG_GROUP_ID'] > 0)
108 $arPriceTypes[] = $arPrice[
'CATALOG_GROUP_ID'];
110 if (!empty($arPriceTypes))
112 $arPriceTypes = array_values(array_unique($arPriceTypes));
116 $arPriceTypes =
array(-1);
119 $rsUserGroups =
$DB->Query(str_replace(
'#ID#', $arDiscount[
'ID'], $strQueryUserGroups));
120 while ($arGroup = $rsUserGroups->Fetch())
122 $arGroup[
'GROUP_ID'] = (int)$arGroup[
'GROUP_ID'];
123 if ($arGroup[
'GROUP_ID'] > 0)
124 $arUserGroups[] = $arGroup[
'GROUP_ID'];
126 if (!empty($arUserGroups))
128 $arUserGroups = array_values(array_unique($arUserGroups));
132 $arUserGroups =
array(-1);
135 $arFields[
'CATALOG_GROUP_IDS'] = $arPriceTypes;
138 $arIBlockList =
array();
139 $arSectionList =
array();
140 $arElementList =
array();
141 $arConditions =
array(
142 'CLASS_ID' =>
'CondGroup',
147 'CHILDREN' =>
array(),
152 $arSrcList =
array();
161 $strName = CIBlock::GetArrayByID(
$arIBlock[
'IBLOCK_ID'],
'NAME');
162 if ($strName !==
false && $strName !==
null)
164 $arIBlockList[] =
$arIBlock[
'IBLOCK_ID'];
168 if (!empty($arIBlockList))
170 $arIBlockList = array_values(array_unique($arIBlockList));
178 $arSrcEntity[] = str_replace(
'#IDS#', implode(
', ', $arSrcList),
Loc::getMessage(
'BT_MOD_CAT_DSC_CONV_ENTITY_IBLOCK_ERR'));
183 $arSrcList =
array();
185 while ($arSection = $rsSections->Fetch())
188 $arSrcList[] = $arSection[
'SECTION_ID'];
189 $arSection[
'SECTION_ID'] = (int)$arSection[
'SECTION_ID'];
190 if ($arSection[
'SECTION_ID'] > 0)
191 $arSectionList[] = $arSection[
'SECTION_ID'];
193 if (!empty($arSectionList))
195 $arSectionList = array_values(array_unique($arSectionList));
196 $rsSections = CIBlockSection::GetList(
array(),
array(
'ID' => $arSectionList),
false,
array(
'ID'));
197 $arCheckResult =
array();
198 while ($arSection = $rsSections->Fetch())
200 $arCheckResult[] = (int)$arSection[
'ID'];
202 if (!empty($arCheckResult))
204 $arSectionList = $arCheckResult;
209 $arSectionList =
array();
213 if (empty($arSectionList))
218 $arSrcEntity[] = str_replace(
'#IDS#', implode(
', ', $arSrcList),
Loc::getMessage(
'BT_MOD_CAT_DSC_CONV_ENTITY_SECTION_ERR'));
223 $arSrcList =
array();
225 while ($arElement = $rsElements->Fetch())
228 $arSrcList[] = $arElement[
'PRODUCT_ID'];
229 $arElement[
'PRODUCT_ID'] = (int)$arElement[
'PRODUCT_ID'];
230 if ($arElement[
'PRODUCT_ID'] > 0)
231 $arElementList[] = $arElement[
'PRODUCT_ID'];
233 if (!empty($arElementList))
235 $arElementList = array_values(array_unique($arElementList));
236 $rsItems = CIBlockElement::GetList(
array(),
array(
'ID' => $arElementList),
false,
false,
array(
'ID'));
237 $arCheckResult =
array();
238 while ($arItem = $rsItems->Fetch())
240 $arCheckResult[] = (int)$arItem[
'ID'];
242 if (!empty($arCheckResult))
244 $arElementList = $arCheckResult;
249 $arElementList =
array();
253 if (empty($arElementList))
258 $arSrcEntity[] = str_replace(
'#IDS#', implode(
', ', $arSrcList),
Loc::getMessage(
'BT_MOD_CAT_DSC_CONV_ENTITY_ELEMENT_ERR'));
262 if (!empty($arIBlockList))
264 if (1 <
count($arIBlockList))
267 foreach ($arIBlockList as &$intItemID)
270 'CLASS_ID' =>
'CondIBIBlock',
273 'value' => $intItemID
277 if (isset($intItemID))
279 if (1 == $intEntityCount)
281 $arConditions =
array(
282 'CLASS_ID' =>
'CondGroup',
287 'CHILDREN' => $arList,
292 $arConditions[
'CHILDREN'][] =
array(
293 'CLASS_ID' =>
'CondGroup',
298 'CHILDREN' => $arList,
304 $arConditions[
'CHILDREN'][] =
array(
305 'CLASS_ID' =>
'CondIBIBlock',
308 'value' => current($arIBlockList)
314 if (!empty($arSectionList))
316 if (1 <
count($arSectionList))
319 foreach ($arSectionList as &$intItemID)
322 'CLASS_ID' =>
'CondIBSection',
325 'value' => $intItemID
329 if (isset($intItemID))
331 if (1 == $intEntityCount)
333 $arConditions =
array(
334 'CLASS_ID' =>
'CondGroup',
339 'CHILDREN' => $arList,
344 $arConditions[
'CHILDREN'][] =
array(
345 'CLASS_ID' =>
'CondGroup',
350 'CHILDREN' => $arList,
356 $arConditions[
'CHILDREN'][] =
array(
357 'CLASS_ID' =>
'CondIBSection',
360 'value' => current($arSectionList)
366 if (!empty($arElementList))
368 if (1 <
count($arElementList))
371 foreach ($arElementList as &$intItemID)
374 'CLASS_ID' =>
'CondIBElement',
377 'value' => $intItemID
381 if (isset($intItemID))
383 if (1 == $intEntityCount)
385 $arConditions =
array(
386 'CLASS_ID' =>
'CondGroup',
391 'CHILDREN' => $arList,
396 $arConditions[
'CHILDREN'][] =
array(
397 'CLASS_ID' =>
'CondGroup',
402 'CHILDREN' => $arList,
408 $arConditions[
'CHILDREN'][] =
array(
409 'CLASS_ID' =>
'CondIBElement',
412 'value' => current($arElementList)
424 self::$arErrors[] =
array(
425 'ID' => $arDiscount[
'ID'],
426 'NAME' => $arDiscount[
'NAME'],
427 'ERROR' =>
Loc::getMessage(
'BT_MOD_CAT_DSC_CONV_INACTIVE').
' '.implode(
'; ', $arSrcEntity),
431 $mxRes = $obDiscount->Update($arDiscount[
'ID'],
$arFields);
442 self::$arErrors[] =
array(
443 'ID' => $arDiscount[
'ID'],
444 'NAME' => $arDiscount[
'NAME'],
450 $arTimeFields =
array(
'~TIMESTAMP_X' =>
$DB->CharToDateFunction($arDiscount[
'TIMESTAMP_X'],
"FULL"));
451 $strUpdate =
$DB->PrepareUpdate($strTableName, $arTimeFields);
452 if (!empty($strUpdate))
454 $strQuery =
"UPDATE ".$strTableName.
" SET ".$strUpdate.
" WHERE ID = ".$arDiscount[
'ID'].
" AND TYPE = ".
CCatalogDiscount::ENTITY_ID;
455 $DB->Query($strQuery);
458 self::$intConverted++;
459 self::$intConvertPerStep++;
462 if ($intMaxExecutionTime > 0 && (microtime(
true) - $startConvertTime > $intMaxExecutionTime))
468 if ($intMaxExecutionTime > (2*(microtime(
true) - $startConvertTime)))
469 self::$intNextConvertPerStep = $intStep*2;
471 self::$intNextConvertPerStep = $intStep;
483 $intStep = (int)$intStep;
486 $startConvertTime = microtime(
true);
490 $strTableName =
'b_catalog_discount';
497 if (self::$intLastConvertID <= 0)
500 CTimeZone::Disable();
502 self::$boolEmptyList =
true;
505 array(
'ID' =>
'ASC'),
507 '>ID' => self::$intLastConvertID,
512 array(
'nTopCount' => $intStep),
513 array(
'ID',
'MODIFIED_BY',
'TIMESTAMP_X',
'CONDITIONS',
'NAME',
'ACTIVE')
515 while ($arDiscount = $rsDiscounts->Fetch())
518 if (
false === $mxExist)
523 self::$boolEmptyList =
false;
526 self::$intConverted++;
527 self::$intConvertPerStep++;
528 self::$intLastConvertID = $arDiscount[
'ID'];
533 'select' =>
array(
'DISCOUNT_ID'),
534 'filter' =>
array(
'=DISCOUNT_ID' => (
int)$arDiscount[
'ID']),
540 'MODIFIED_BY' => $arDiscount[
'MODIFIED_BY'],
541 'CONDITIONS' => $arDiscount[
'CONDITIONS'],
542 'ACTIVE' => $arDiscount[
'ACTIVE'],
543 'USE_COUPONS' => (!empty($existRow) ?
'Y' :
'N')
547 $mxRes = $obDiscount->Update($arDiscount[
'ID'],
$arFields);
558 self::$arErrors[] =
array(
559 'ID' => $arDiscount[
'ID'],
560 'NAME' => $arDiscount[
'NAME'],
568 self::$intConverted++;
569 self::$intConvertPerStep++;
570 self::$intLastConvertID = $arDiscount[
'ID'];
574 $arTimeFields =
array(
'~TIMESTAMP_X' =>
$DB->CharToDateFunction($arDiscount[
'TIMESTAMP_X'],
"FULL"));
575 $strUpdate =
$DB->PrepareUpdate($strTableName, $arTimeFields);
576 if (!empty($strUpdate))
578 $strQuery =
"UPDATE ".$strTableName.
" SET ".$strUpdate.
" WHERE ID = ".$arDiscount[
'ID'].
" AND TYPE = ".
CCatalogDiscount::ENTITY_ID;
579 $DB->Query($strQuery);
586 self::$intConverted++;
587 self::$intConvertPerStep++;
588 self::$intLastConvertID = $arDiscount[
'ID'];
591 if ($intMaxExecutionTime > 0 && (microtime(
true) - $startConvertTime > $intMaxExecutionTime))
597 if ($intMaxExecutionTime > (2*(microtime(
true) - $startConvertTime)))
598 self::$intNextConvertPerStep = $intStep*2;
600 self::$intNextConvertPerStep = $intStep;