19 private $ritchLog =
false;
29 $this->exportId = $exportId;
30 $this->ritchLog = Vk::getInstance()->getRichLog($this->exportId);
41 private function getExistingErrors($errCode =
null, $itemId =
null)
45 $filter = array(
'=EXPORT_ID' => $this->exportId,);
47 $filter[
'=ERROR_CODE'] = $errCode;
49 $filter[
'=ITEM_ID'] = $itemId;
51 $resExistErrors = LogTable::getList(array(
53 'order' => array(
'ERROR_CODE' =>
'ASC'),
56 while ($err = $resExistErrors->fetch())
58 $result[$err[
'ID']] = $err;
69 public function addLog($itemId =
null, $params =
null)
74 return $this->
addError(
"LOG", $itemId, print_r($params,
true));
90 public function addError($errCode, $itemId =
null, $errParams =
null)
92 $errorDescription = $this->getErrorsDescriptions($errCode);
93 $errCode = $errorDescription[
'CODE'] ? $errorDescription[
'CODE'] : $errCode;
95 if (!$this->addErrorToTable($errCode, $itemId, $errParams))
99 if ($errorDescription[
'CRITICAL'])
117 private function addErrorToTable($errCode, $itemId =
null, $errParams =
null)
120 "EXPORT_ID" => $this->exportId,
121 "ERROR_CODE" => $errCode,
125 $fields[
"ITEM_ID"] = $itemId;
129 $fields[
"ERROR_PARAMS"] = $errParams;
131 $resExistError = LogTable::getList(array(
"filter" => $fields));
133 if ($existError = $resExistError->fetch())
135 $resDb = LogTable::update($existError[
"ID"], $fields);
139 $resDb = LogTable::add($fields);
141 return $resDb->isSuccess();
153 $errorDescription = $this->getErrorsDescriptions($errCode);
157 $errCodes[$errorDescription[
'CODE']] = $errorDescription[
'CODE'];
158 $errCodes[$errCode] = $errCode;
161 $resErrId = LogTable::getList(array(
'filter' => array(
"EXPORT_ID" => $this->exportId,
"ERROR_CODE" => $errCodes)));
162 while ($err = $resErrId->fetch())
165 LogTable::delete($errId);
179 $existingErrors = $this->getExistingErrors();
180 foreach ($existingErrors as $key => $err)
182 $resDelete = LogTable::delete($err[
'ID']);
196 $errorsConverted = array();
197 $errorsConvertedStrings = array();
199 $errorsExistings = $this->getExistingErrors();
200 $errorsDescriptions = $this->getErrorsDescriptions();
202 if ($errorsExistings)
204 foreach ($errorsExistings as $err)
208 array_key_exists($err[
'ERROR_CODE'], $errorsDescriptions) &&
209 !$errorsDescriptions[$err[
'ERROR_CODE']][
'IGNORE']
213 $errorsConverted[$err[
'ERROR_CODE']][
'MESSAGE'] = $errorsDescriptions[$err[
'ERROR_CODE']][
'MESSAGE'];
215 $errorsConverted[$err[
'ERROR_CODE']][
'ITEMS'][$err[
'ITEM_ID']] = $err[
'ITEM_ID'];
219 elseif (!$errorsDescriptions[$err[
'ERROR_CODE']][
'IGNORE'])
223 if ($err[
'ERROR_CODE'])
224 $errorsConverted[
'UNKNOWN'][
'ITEMS'][$err[
'ERROR_CODE']] = $err[
'ERROR_CODE'];
229 foreach ($errorsConverted as $errCode => $err)
231 $errCritical = $errorsDescriptions[$errCode][
'CRITICAL'];
234 if ($errCritical == $flagCritical)
236 $itemsConvertedString =
'';
237 $itemsConverted = array();
238 $itemsConvertedHide = array();
240 if (array_key_exists(
'ITEMS', $err) && !empty($err[
'ITEMS']))
243 foreach ($err[
'ITEMS'] as $item)
245 $itemConverted = $this->createItemErrorString(
251 if ($itemConverted <>
'')
252 if ($itemsCount <= self::MAX_SHOWING_ERRORS_ITEMS)
253 $itemsConverted[] = $itemConverted;
255 $itemsConvertedHide[] = $itemConverted;
257 if (!empty($itemsConverted))
258 $itemsConvertedString =
': ' . implode(
', ', $itemsConverted);
259 if (!empty($itemsConvertedHide))
261 $itemsConvertedString .=
',
262 <span class="vk_export_notify__error_normal__hide_elements" style="display:none"
263 id="vk_export_notify__error_normal__hide_elements--' . $errCode .
'">' .
264 implode(
', ', $itemsConvertedHide) .
266 $itemsConvertedString .=
'
267 <span style="text-align: center;">
268 <span style="cursor:pointer; border: 1px dashed; border-width: 0 0 1px 0"
269 onclick = "expandElements(\'' . $errCode .
'\');
"
270 class="vk_export_notify__error_normal__more_elements
" id="vk_export_notify__error_normal__more_elements--
' . $errCode . '">' .
271 Loc::getMessage('SALE_VK_ERRORS__MORE_ELEMENTS',
272 array('#C1' => $itemsCount - self::MAX_SHOWING_ERRORS_ITEMS)) .
275 <span style="cursor:pointer; border: 1px dashed; border-width: 0 0 1px 0; display:none;
"
276 onclick = "narrowElement(\
'' . $errCode .
'\');
"
277 class="vk_export_notify__error_normal__less_elements
" id="vk_export_notify__error_normal__less_elements--
' . $errCode . '">' .
278 Loc::getMessage('SALE_VK_ERRORS__LESS_ELEMENTS') .
285// create common string for one error
286 $errorsConvertedStrings[$errCode] =
287 '<p style="font-weight: normal !important;
">' .
288 $err['MESSAGE'] . $itemsConvertedString .
293// for critical errors show message just once - clean after get message
294 if ($errCritical && $flagCritical)
296 $criticalErrors = $this->getExistingErrors($errCode);
297 foreach ($criticalErrors as $error)
298 $resDelete = LogTable::delete($error['ID']);
302 $errorsConvertedString = implode('', $errorsConvertedStrings);
304// add intro before errors
305 if ($errorsConvertedString <> '')
307 $result = $flagCritical ? Loc::getMessage("SALE_VK_ERRORS__INTRO_CRITICAL
") : Loc::getMessage("SALE_VK_ERRORS__INTRO_NORMAL
");
308 $result .= ':<br>' . $errorsConvertedString;
311// check if need download log file
314 $vk = Vk::getInstance();
315 if ($richLog = $vk->getRichLog($this->exportId))
317 $href = '/bitrix/admin/sale_vk_export_edit.php' . '?ID=' . $this->exportId . '&lang=' . LANG . '&download_log=Y';
318 $result .= '<br><p>' . Loc::getMessage("SALE_VK_ERRORS__LOG_TITLE
") . ': <a href="' . $href . '">' . Loc::getMessage("SALE_VK_ERRORS__LOG_DOWNLOAD
") . '</a>.</p>';
336 public function getErrorExpandScript()
340 function expandElements(code) {
341 BX.adjust(
BX(
'vk_export_notify__error_normal__less_elements--'+code), {style:{display:
'inline'}});
342 BX.adjust(
BX(
'vk_export_notify__error_normal__more_elements--'+code), {style:{display:
'none'}});
343 BX.adjust(
BX(
'vk_export_notify__error_normal__hide_elements--'+code), {style:{display:
'inline'}});
346 function narrowElement(code) {
347 BX.adjust(
BX(
'vk_export_notify__error_normal__more_elements--'+code), {style:{display:
'inline'}});
348 BX.adjust(
BX(
'vk_export_notify__error_normal__less_elements--'+code), {style:{display:
'none'}});
349 BX.adjust(
BX(
'vk_export_notify__error_normal__hide_elements--'+code), {style:{display:
'none'}});
356 public static function createLogFileContent($exportId)
358 $resExistLogs = LogTable::getList(array(
359 'select' => array("ITEM_ID
", "ERROR_PARAMS
", "TIME
"),
361 '=EXPORT_ID' => $exportId,
362 '=ERROR_CODE' => "LOG
",
364 'order' => array('TIME' => 'ASC', 'ID' => 'ASC'),
368 while ($record = $resExistLogs->fetch())
370 $log .= $record["TIME
"] . ' - ' . $record["ITEM_ID
"] . ".
";
371 if (!empty($record["ERROR_PARAMS
"]))
372 $log .= " Params:
" . print_r($record["ERROR_PARAMS
"], true);
387 private function createItemErrorString($item, $errCode)
389 $errorsDescriptions = $this->getErrorsDescriptions();
391 if (array_key_exists($errCode, $errorsDescriptions) && array_key_exists('ITEMS_TYPE', $errorsDescriptions[$errCode]))
393 return self::createItemErrorStringByType($item, $errorsDescriptions[$errCode]['ITEMS_TYPE']);
396// if error have format without items - just item ID - for unknown errors
411 private static function createItemErrorStringByType($item, $type)
419// get iblock id fore create link to edit
420 $resProduct = \CIBlockElement::GetList(array(), array("ID
" => $item), false, false, array('IBLOCK_ID', 'NAME'));
421 $resProduct = $resProduct->Fetch();
423 "IBLOCK_ID
" => $resProduct["IBLOCK_ID
"],
426 "lang
" => LANGUAGE_ID,
428 $href = "/
bitrix/admin/cat_product_edit.php
";
429 $result = '<a href="' . $href . '?
' . http_build_query($query) . '">' . $resProduct['NAME'] . '</a>';
433// todo: use link create method from ZZ
434// get iblock id fore create link to edit
435 $resSection = \CIBlockSection::GetList( array(), array("ID
" => $item), false, array('IBLOCK_ID', 'NAME'));
436 $resSection = $resSection->Fetch();
438 "IBLOCK_ID
" => $resSection["IBLOCK_ID
"],
441 "lang
" => LANGUAGE_ID,
443 $href = "/
bitrix/admin/cat_section_edit.php
";
444 $result = '<a href="' . $href . '?
' . http_build_query($query) . '">' . $resSection['NAME'] . '</a>';
448 $resFile = \CFile::GetFileArray($item);
449 $result = '<a href="' . $resFile['SRC
'] . '">' . $resFile['ORIGINAL_NAME'] . '</a>';
453// do nothing - just print method name
457// not need items string
480 private function getErrorsDescriptions($key = null)
482 $errorsDescriptions = array(
483 //"LOG
" using just for write to log some data - f.e. to debug
490 "MESSAGE
" => Loc::getMessage("SALE_VK_ERROR__CODE_100
"),
492 "ITEMS_TYPE
" => 'METHODS',
497 "MESSAGE
" => Loc::getMessage("SALE_VK_ERROR__UNKNOWN_VK_ERROR
") . ' ' . Loc::getMessage('SALE_VK_ERROR__CODE_1'),
500 "ITEMS_TYPE
" => 'NONE',
503 "MESSAGE
" => Loc::getMessage("SALE_VK_ERROR__GROUP_NOT_ACCESS_ERROR
"),
506 "ITEMS_TYPE
" => 'NONE',
509 "MESSAGE
" => Loc::getMessage("SALE_VK_ERROR__UNKNOWN_VK_ERROR
") . ' ' . Loc::getMessage('SALE_VK_ERROR__CODE_10'),
512 "ITEMS_TYPE
" => 'NONE',
515 "MESSAGE
" => Loc::getMessage("SALE_VK_ERROR__EXECUTE_ERROR
"),
518 "ITEMS_TYPE
" => 'NONE',
521 "MESSAGE
" => Loc::getMessage("SALE_VK_ERROR__ACCESS_DENIED
"),
524 "ITEMS_TYPE
" => 'NONE',
526 "VK_NOT_AVAILABLE
" => array(
527 "MESSAGE
" => Loc::getMessage("SALE_VK_ERROR__VK_NOT_AVAILABLE
", array(
528 '#A1' => '<a href="http:
531 "CODE" =>
"VK_NOT_AVAILABLE",
532 "ITEMS_TYPE" =>
'NONE',
534 "PRODUCT_SHORT_NAME" => array(
537 "CODE" =>
"PRODUCT_SHORT_NAME",
538 "ITEMS_TYPE" =>
'PRODUCT',
540 "PRODUCT_SHORT_DESCRIPTION" => array(
541 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERROR__PRODUCT_SHORT_DESCRIPTION"),
543 "CODE" =>
"PRODUCT_SHORT_DESCRIPTION",
544 "ITEMS_TYPE" =>
'PRODUCT',
546 "PRODUCT_LONG_NAME" => array(
549 "CODE" =>
"PRODUCT_LONG_NAME",
550 "ITEMS_TYPE" =>
'PRODUCT',
552 "ALBUM_LONG_TITLE" => array(
555 "CODE" =>
"ALBUM_LONG_TITLE",
556 "ITEMS_TYPE" =>
'ALBUM',
558 "ALBUM_EMPTY" => array(
561 "CODE" =>
"ALBUM_EMPTY",
562 "ITEMS_TYPE" =>
'ALBUM',
564 "PRODUCT_EMPTY_PRICE" => array(
567 "CODE" =>
"PRODUCT_EMPTY_PRICE",
568 "ITEMS_TYPE" =>
'PRODUCT',
571 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERROR__WRONG_ACCESS_TOKEN", array(
572 '#A1' =>
'<a href="/bitrix/admin/sale_vk_export_edit.php?ID=' . $this->exportId .
'&lang=' . LANG .
'&tabControl_active_tab=vk_settings">',
577 "ITEMS_TYPE" =>
'NONE',
579 "WRONG_ACCESS_TOKEN" => array(
583 "ITEMS_TYPE" =>
'NONE',
585 "CLIENT_SECRET_IS_INCORRECT" => array(
586 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERROR__CLIENT_SECRET_IS_INCORRECT"),
588 "CODE" =>
"CLIENT_SECRET_IS_INCORRECT",
589 "ITEMS_TYPE" =>
'NONE',
595 "ITEMS_TYPE" =>
'NONE',
603 "ITEMS_TYPE" =>
'NONE',
610 "ITEMS_TYPE" =>
'NONE',
614 'MESSAGE' =>
'Product already in album',
616 "ITEMS_TYPE" =>
'NONE',
622 "ITEMS_TYPE" =>
'NONE',
625 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERROR__PRODUCTS_IN_ALBUM_LIMIT_EXCEED"),
628 "ITEMS_TYPE" =>
'NONE',
634 "ITEMS_TYPE" =>
'NONE',
636 "PRODUCT_WRONG_PHOTOS" => array(
639 "CODE" =>
"PRODUCT_WRONG_PHOTOS",
640 "ITEMS_TYPE" =>
'PRODUCT',
642 "PRODUCT_PHOTOS_RESIZE_UP" => array(
643 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERRORS__PRODUCT_PHOTOS_RESIZE_UP"),
645 "CODE" =>
"PRODUCT_PHOTOS_RESIZE_UP",
646 "ITEMS_TYPE" =>
'PRODUCT',
648 "PRODUCT_PHOTOS_RESIZE_DOWN" => array(
649 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERRORS__PRODUCT_PHOTOS_RESIZE_DOWN"),
651 "CODE" =>
"PRODUCT_PHOTOS_RESIZE_DOWN",
652 "ITEMS_TYPE" =>
'PRODUCT',
654 "ALBUM_EMPTY_PHOTOS" => array(
657 "CODE" =>
"ALBUM_EMPTY_PHOTOS",
658 "ITEMS_TYPE" =>
'ALBUM',
660 "ALBUM_PHOTOS_10" => array(
661 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERRORS__ALBUM_PHOTOS_RESIZE_UP"),
663 "CODE" =>
"ALBUM_PHOTOS_10",
664 "ITEMS_TYPE" =>
'ALBUM',
666 "ALBUM_PHOTOS_30" => array(
667 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERRORS__ALBUM_PHOTOS_RESIZE_DOWN"),
669 "CODE" =>
"ALBUM_PHOTOS_30",
670 "ITEMS_TYPE" =>
'ALBUM',
672 "ALBUM_PHOTOS_20" => array(
673 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERRORS__ALBUM_PHOTOS_RESIZE_CROP"),
675 "CODE" =>
"ALBUM_PHOTOS_20",
676 "ITEMS_TYPE" =>
'ALBUM',
678 "ALBUM_PHOTOS_40" => array(
679 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERRORS__ALBUM_PHOTOS_RESIZE_CROP"),
681 "CODE" =>
"ALBUM_PHOTOS_40",
682 "ITEMS_TYPE" =>
'ALBUM',
685 "EMPTY_SECTIONS_LIST" => array(
688 "CODE" =>
"EMPTY_SECTIONS_LIST",
689 "ITEMS_TYPE" =>
'NONE',
691 "EMPTY_SECTION_PRODUCTS" => array(
692 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERRORS__EMPTY_SECTION_PRODUCTS"),
694 "CODE" =>
"EMPTY_SECTION_PRODUCTS",
695 "ITEMS_TYPE" =>
'NONE',
697 "TOO_MANY_SECTIONS_TO_EXPORT" => array(
698 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERRORS__TOO_MANY_SECTIONS_TO_EXPORT") .
' ' . Vk::MAX_EXECUTION_ITEMS,
700 "CODE" =>
"TOO_MANY_SECTIONS_TO_EXPORT",
701 "ITEMS_TYPE" =>
'NONE',
703 "TOO_MANY_PRODUCTS_TO_EXPORT" => array(
704 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERRORS__TOO_MANY_PRODUCTS_TO_EXPORT") .
' ' . Vk::MAX_EXECUTION_ITEMS,
706 "CODE" =>
"TOO_MANY_PRODUCTS_TO_EXPORT",
707 "ITEMS_TYPE" =>
'NONE',
710 "ERR_UPLOAD_BAD_IMAGE_SIZE_ALBUM_PHOTO" => [
711 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERRORS__ERR_UPLOAD_BAD_IMAGE_SIZE_ALBUM_PHOTO"),
713 "CODE" =>
"ERR_UPLOAD_BAD_IMAGE_SIZE_ALBUM_PHOTO",
714 "ITEMS_TYPE" =>
'ALBUM',
716 "ERR_UPLOAD_BAD_IMAGE_SIZE_PRODUCT_MAIN_PHOTO" => [
717 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERRORS__ERR_UPLOAD_BAD_IMAGE_SIZE_PRODUCT_MAIN_PHOTO"),
719 "CODE" =>
"ERR_UPLOAD_BAD_IMAGE_SIZE_PRODUCT_MAIN_PHOTO",
720 "ITEMS_TYPE" =>
'PRODUCT',
722 "ERR_UPLOAD_BAD_IMAGE_SIZE_PRODUCT_PHOTOS" => [
723 "MESSAGE" =>
Loc::getMessage(
"SALE_VK_ERRORS__ERR_UPLOAD_BAD_IMAGE_SIZE_PRODUCT_PHOTOS"),
725 "CODE" =>
"ERR_UPLOAD_BAD_IMAGE_SIZE_PRODUCT_PHOTOS",
726 "ITEMS_TYPE" =>
'PHOTO',
733 return array_key_exists($key, $errorsDescriptions) ? $errorsDescriptions[$key] :
null;
737 return $errorsDescriptions;
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)