- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/tradingplatform/vk/agent.php
- Класс: Bitrix\Sale\TradingPlatform\Vk\Agent
- Вызов: Agent::start
static function start($feedType, $exportId, $startPosition = "", $once = false, $execNumber = 1)
{
if (empty($exportId))
throw new ArgumentNullException('exportId');
$exportId = \EscapePHPString($exportId);
if (!in_array($feedType, Vk::getExportTypes()))
throw new ArgumentOutOfRangeException('feedType');
$result = "";
$vk = Vk::getInstance();
$vk->log(
TradingPlatform\Logger::LOG_LEVEL_DEBUG,
"VK_AGENT__FEED_STARTED",
'FEED_' . $feedType,
"VKontakte export of " . $feedType . " started from agent. Export profile: " . $exportId . ", start position: " . $startPosition
);
try
{
// if we run ALL export - first we must add ALBUMS. After this we create PRODUCTS agent
if ($feedType == 'ALL')
$feedTypeCurr = 'ALBUMS';
else
$feedTypeCurr = $feedType;
$timelimit = $vk->getTimelimit($exportId);
$vkFeed = Manager::createFeed($feedTypeCurr, $exportId, $timelimit, $startPosition);
$vkFeed->processData($exportId);
}
catch (TimeIsOverException $e)
{
$endPosition = $e->getEndPosition();
// control of slow export
if ($startPosition == $endPosition)
{
$execNumber++;
if ($execNumber >= 3)
{
\CAdminNotify::Add(array(
'MESSAGE' => Loc::getMessage("SALE_VK__TOO_MUCH_TIMES_NOTIFY"),
'MODULE_ID' => 'sale',
'TAG' => 'vk_agent_much_times_notify',
'NOTIFY_TYPE' => \CAdminNotify::TYPE_ERROR,
));
}
}
else
{
$execNumber = 1;
}
$result = self::createAgentNameForAdd($feedType, $exportId, $endPosition, $once, $execNumber);
$vk->log(
TradingPlatform\Logger::LOG_LEVEL_DEBUG,
"VK_AGENT__FEED_TIMELIMIT",
'FEED_' . $feedType,
"VKontakte export of " . $feedType . " for profile " . $exportId . " takes too long and was finished at position '" . $startPosition . "'. To continue will be create agent."
);
}
catch (ExecuteException $e)
{
$msg = $e->getFullMessage() ? $e->getFullMessage() : Loc::getMessage("SALE_VK__UNKNOWN_ERROR");
$vk->log(TradingPlatform\Logger::LOG_LEVEL_ERROR, "VK_FEED__FEED_ERRORS", 'FEED_' . $feedType, $msg);
}
catch (\Exception $e)
{
$vk->log(
TradingPlatform\Logger::LOG_LEVEL_ERROR,
"VK_AGENT__FEED_ERRORS", 'FEED_' . $feedType,
"VKontakte export of " . $feedType . " for profile " . $exportId . " finished with some errors. " .
$e->getMessage()
);
}
// if ALL export - we catch end of one cycle and run next type (ALBUMS => PRODUCTS)
// if ALBUM part end normal (not with timer) - run agent to PRODUCTS export
if ($feedType == 'ALL' && !isset($endPosition))
{
// for ALL export we open PRODUCTS journal after ALBUMS export end. Need for correctly show statistic to user
$journal = new Journal($exportId, 'PRODUCTS');
$journal->start();
$result = self::createAgentNameForAdd('PRODUCTS', $exportId, '', $once);
$vk->log(
TradingPlatform\Logger::LOG_LEVEL_DEBUG,
"VK_FEED__FEED_ALBUM_PART_FINISH",
'FEED_' . $feedType,
"VKontakte export of ALBUMS for profile " . $exportId . " was finished successfull. PRODUCTS export will be continue on agent."
);
}
// all OK - create new agent with null start position
elseif (strlen($result) <= 0 && !$once)
{
$result = self::createAgentNameForAdd($feedType, $exportId, "", $once);
}
$vk->log(
TradingPlatform\Logger::LOG_LEVEL_DEBUG,
"VK_AGENT__FEED_FINISH",
'FEED_' . $feedType,
"VKontakte export of " . $feedType . " for profile " . $exportId . " was finished."
);
return $result;
}