34 public static function start($feedType, $exportId, $startPosition =
"", $once =
false, $execNumber = 1)
38 $exportId = \EscapePHPString($exportId);
40 if (!in_array($feedType, Vk::getExportTypes()))
44 $vk = Vk::getInstance();
46 TradingPlatform\Logger::LOG_LEVEL_DEBUG,
47 "VK_AGENT__FEED_STARTED",
49 "VKontakte export of " . $feedType .
" started from agent. Export profile: " . $exportId .
", start position: " . $startPosition
55 if ($feedType ==
'ALL')
56 $feedTypeCurr =
'ALBUMS';
58 $feedTypeCurr = $feedType;
60 $timelimit = $vk->getTimelimit($exportId);
61 $vkFeed = Manager::createFeed($feedTypeCurr, $exportId, $timelimit, $startPosition);
62 $vkFeed->processData($exportId);
69 if ($startPosition == $endPosition)
74 \CAdminNotify::Add(array(
76 'MODULE_ID' =>
'sale',
77 'TAG' =>
'vk_agent_much_times_notify',
78 'NOTIFY_TYPE' => \CAdminNotify::TYPE_ERROR,
86 $result = self::createAgentNameForAdd($feedType, $exportId, $endPosition, $once, $execNumber);
88 TradingPlatform\Logger::LOG_LEVEL_DEBUG,
89 "VK_AGENT__FEED_TIMELIMIT",
91 "VKontakte export of " . $feedType .
" for profile " . $exportId .
" takes too long and was finished at position '" . $startPosition .
"'. To continue will be create agent."
97 $msg = $e->getFullMessage() ? $e->getFullMessage() :
Loc::getMessage(
"SALE_VK__UNKNOWN_ERROR");
98 $vk->log(TradingPlatform\Logger::LOG_LEVEL_ERROR,
"VK_FEED__FEED_ERRORS",
'FEED_' . $feedType, $msg);
104 TradingPlatform\Logger::LOG_LEVEL_ERROR,
105 "VK_AGENT__FEED_ERRORS",
'FEED_' . $feedType,
106 "VKontakte export of " . $feedType .
" for profile " . $exportId .
" finished with some errors. " .
113 if ($feedType ==
'ALL' && !isset($endPosition))
116 $journal =
new Journal($exportId,
'PRODUCTS');
119 $result = self::createAgentNameForAdd(
'PRODUCTS', $exportId,
'', $once);
121 TradingPlatform\Logger::LOG_LEVEL_DEBUG,
122 "VK_FEED__FEED_ALBUM_PART_FINISH",
124 "VKontakte export of ALBUMS for profile " . $exportId .
" was finished successfull. PRODUCTS export will be continue on agent."
129 elseif (strlen($result) <= 0 && !$once)
131 $result = self::createAgentNameForAdd($feedType, $exportId,
"", $once);
135 TradingPlatform\Logger::LOG_LEVEL_DEBUG,
136 "VK_AGENT__FEED_FINISH",
138 "VKontakte export of " . $feedType .
" for profile " . $exportId .
" was finished."
155 public static function add($feedType, $exportId, $startPosition =
"", $interval, $once =
false)
160 if (empty($exportId))
163 $exportId = \EscapePHPString($exportId);
165 $timeToStart = ConvertTimeStamp(strtotime(date(
'Y-m-d H:i:s', time() + $interval)),
'FULL');
167 $result = \CAgent::AddAgent(
168 self::createAgentNameForAdd($feedType, $exportId, $startPosition, $once),
179 $vk = Vk::getInstance();
181 TradingPlatform\Logger::LOG_LEVEL_DEBUG,
182 "VK_AGENT__NEW_AGENT",
184 "New agent was crated for VKontakte export " . $feedType .
". Agent ID: " . $result .
"."
217 public static function update($exportId, $feedType, $interval, $once =
false)
220 $interval = intval($interval);
223 $dbRes = \CAgent::GetList(
226 'NAME' => self::createAgentNameForAdd($feedType, $exportId,
"", $once),
232 if ($agent = $dbRes->Fetch())
236 self::deleteAgent($agent[
"ID"]);
243 array(
'AGENT_INTERVAL' => $interval,)
246 $result = $agent[
"ID"];
254 $result = self::add($feedType, $exportId,
"", $interval, $once);