- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/tradingplatform/vk/feed/manager.php
- Класс: BitrixSaleTradingPlatformVkFeedManager
- Вызов: Manager::runProcess
static function runProcess($exportId, $processType)
{
$result = array();
if (empty($exportId))
throw new ArgumentNullException('exportId');
$exportId = EscapePHPString($exportId);
$currProcess = VkJournal::getCurrentProcess($exportId);
$startPosition = $currProcess ? $currProcess['START_POSITION'] : self::DEFAULT_START_POSITION;
$execCount = $currProcess ? $currProcess['EXEC_COUNT'] : self::DEFAULT_EXEC_COUNT;
// if we run ALL export - first we must add ALBUMS. After this we create PRODUCTS
$currProcessType = self::prepareType($processType);
if (!in_array($currProcessType, VkVk::getExportTypes()))
throw new ArgumentOutOfRangeException('currProcessType');
$journal = new VkJournal($exportId, $currProcessType);
// if first running - start journal
if ($startPosition == self::DEFAULT_START_POSITION)
$journal->start();
$vk = VkVk::getInstance();
$vk->log(
TradingPlatformLogger::LOG_LEVEL_DEBUG,
"VK_PROCESS__START",
'FEED_' . $currProcessType,
"VKontakte export of " . $currProcessType . " started. Export profile: " . $exportId . ", start position: " . $startPosition
);
try
{
$timelimit = $vk->getTimelimit($exportId);
$feed = Manager::createFeed($currProcessType, $exportId, $timelimit, $startPosition);
$feed->processData($exportId);
}
catch (TimeIsOverException $e)
{
$endPosition = $e->getEndPosition();
// control of slow export
if ($startPosition == $endPosition)
{
$execCount++;
if ($execCount >= self::MAX_EXEC_COUNT)
$result['TOO_MUCH_TIMES'] = VkJournal::getTooMuchTimeExportMessage();
}
else
{
$execCount = self::DEFAULT_EXEC_COUNT;
}
$vk->log(
TradingPlatformLogger::LOG_LEVEL_DEBUG,
"VK_PROCESS__TIMELIMIT",
'FEED_' . $currProcessType,
"VKontakte export of " . $currProcessType . " for profile " . $exportId . " takes too long and was finished at position '" . $startPosition . "'."
);
}
catch (VkExecuteException $e)
{
// reload to show errors
$result['ERRORS_CRITICAL'] = true;
$msg = $e->getFullMessage() ? $e->getFullMessage() : Loc::getMessage("SALE_VK__UNKNOWN_ERROR");
$vk->log(TradingPlatformLogger::LOG_LEVEL_ERROR, "VK_FEED__FEED_ERRORS", 'FEED_' . $currProcessType, $msg);
}
catch (Exception $e)
{
// todo: need create normal errors desc
$vk->log(
TradingPlatformLogger::LOG_LEVEL_ERROR,
"VK_PROCESS__ERRORS", 'FEED_' . $currProcessType,
"VKontakte export of " . $currProcessType . " for profile " . $exportId . " finished with some errors. " .
$e->getMessage()
);
}
$journal = new VkJournal($exportId, $currProcessType);
// If export not set endPosition - we catch finish element.
if (!isset($endPosition))
{
// close journal for current type and write to log
$journal->end();
$vk->log(
TradingPlatformLogger::LOG_LEVEL_DEBUG,
"VK_PROCESS__FINISH",
'FEED_' . $currProcessType,
"VKontakte export of " . $currProcessType . " for profile " . $exportId . " was finished."
);
// if ALL export - after ALBUMS run PRODUCTS
if ($currProcessType == self::FIRST_PROCESS_TYPE && $processType == self::DEFAULT_PROCESS_TYPE)
{
$processTypeToSave = self::SECOND_PROCESS_TYPE;
$positionToSave = self::DEFAULT_START_POSITION;
$execCountToSave = self::DEFAULT_EXEC_COUNT;
$result['CONTINUE'] = true;
$result['TYPE'] = $processTypeToSave;
}
// end of export process sovsem
else
{
$processTypeToSave = false;
$positionToSave = false;
$execCountToSave = false;
$result['CONTINUE'] = false;
}
}
// CONTINUE export in current type
else
{
// if ALBUM - save ALL value ($processType)
$processTypeToSave = $processType;
$positionToSave = $endPosition;
$execCountToSave = $execCount;
$result['CONTINUE'] = true;
$result['TYPE'] = $processTypeToSave;
}
// SAVE params of process
$journal->saveProcessParams($exportId, $processTypeToSave, $positionToSave, $execCountToSave);
return $result;
}