Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
agent.php
1<?php
2
4
11
17class Agent
18{
30 public static function start($feedType, $siteId, $startPosition="", $once = false)
31 {
32 if(empty($siteId))
33 throw new ArgumentNullException('siteId');
34
35 $siteId = \EscapePHPString($siteId);
36
37 if(!in_array($feedType, array("ORDER", "PRODUCT", "INVENTORY", "IMAGE", "PROCESS_RESULT", "RESULTS", "ORDER_ACK")))
38 throw new ArgumentOutOfRangeException('feedType');
39
40 $result = "";
41 $timeLimit = 300;
42 Ebay::log(Logger::LOG_LEVEL_DEBUG, "EBAY_AGENT_FEED_STARTED", $feedType, "Feed: ".$feedType.", site: ".$siteId.", start position: ".$startPosition, $siteId);
43
44 try
45 {
46 if(in_array($feedType, array("ORDER", "PROCESS_RESULT", "RESULTS")))
47 {
48 $ebayFeed = Manager::createFeed($feedType, $siteId, $timeLimit);
49 $ebayFeed->processData($startPosition);
50 }
51 else
52 {
53 $timer = new Timer($timeLimit);
54 $queue = Manager::createSftpQueue($feedType, $siteId, $timer);
55 $queue->sendData();
56 }
57 }
58 catch(TimeIsOverException $e)
59 {
60 $result = 'Bitrix\Sale\TradingPlatform\Ebay\Agent::start("'.$feedType.'","'.$siteId.'","'.$e->getEndPosition().'",, '.($once ? 'true' : 'false').');';
61 }
62 catch(\Exception $e)
63 {
64 Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_FEED_ERROR", $feedType, $e->getMessage(), $siteId);
65 }
66
67 if($result == '' && !$once)
68 $result = 'Bitrix\Sale\TradingPlatform\Ebay\Agent::start("'.$feedType.'","'.$siteId.'");';
69
70 return $result;
71 }
72
82 public static function add($feedType, $siteId, $interval, $once = false)
83 {
84 if($interval <= 0)
85 return 0;
86
87 if(empty($siteId))
88 throw new ArgumentNullException('siteId');
89
90 $siteId = \EscapePHPString($siteId);
91
92 if($feedType == "ORDER")
93 $sort = 50;
94 elseif($feedType == "PRODUCT" || $feedType == "PROCESS_RESULT" || $feedType == "RESULTS")
95 $sort = 100;
96 elseif($feedType == "INVENTORY" || $feedType == "IMAGE" || $feedType == "ORDER_ACK" )
97 $sort = 150;
98 else
99 throw new ArgumentOutOfRangeException('feedType');
100
101 $intervalSeconds = $interval*60;
102 $timeToStart = ConvertTimeStamp(strtotime(date('Y-m-d H:i:s', time() + $intervalSeconds)), 'FULL');
103
104 $result = \CAgent::AddAgent(
105 self::createAgentNameForAdd($feedType, $siteId, $once),
106 'sale',
107 "N",
108 $interval*60,
109 $timeToStart,
110 "Y",
111 $timeToStart,
112 $sort);
113
114 Ebay::log(Logger::LOG_LEVEL_DEBUG, "EBAY_AGENT_ADDING_RESULT", $feedType, "Feed: ".$feedType.", site: ".$siteId.", interval: ".$interval." once: ".($once ? 'true' : 'false')." agentId: '".$result."'", $siteId);
115
116 return $result;
117 }
118
119 protected static function createAgentNameForAdd($feedType, $siteId, $once = false)
120 {
121 return 'Bitrix\Sale\TradingPlatform\Ebay\Agent::start("'.$feedType.'","'.$siteId.'", "", '.($once ? 'true' : 'false').');';
122 }
123
124
131 public static function update($siteId, array $feedSettings)
132 {
133 foreach($feedSettings as $feedType => $feedParams)
134 {
135 $interval = intval($feedParams["INTERVAL"]);
136
137 $dbRes = \CAgent::GetList(
138 array(),
139 array(
140 'NAME' => self::createAgentNameForAdd($feedType, $siteId)
141 )
142 );
143
144 if($agent = $dbRes->Fetch())
145 {
146 if($interval <= 0)
147 {
148 \CAgent::Delete($agent["ID"]);
149 $feedSettings[$feedType]["AGENT_ID"] = 0;
150 continue;
151 }
152
153 \CAgent::Update(
154 $agent["ID"],
155 array('AGENT_INTERVAL' => $interval*60)
156 );
157
158 $feedSettings[$feedType]["AGENT_ID"] = $agent["ID"];
159 }
160 else
161 {
162 $feedSettings[$feedType]["AGENT_ID"] = self::add($feedType, $siteId, $feedParams["INTERVAL"]);
163 }
164 }
165
166 return $feedSettings;
167 }
168}
static add($feedType, $siteId, $interval, $once=false)
Definition agent.php:82
static start($feedType, $siteId, $startPosition="", $once=false)
Definition agent.php:30
static createAgentNameForAdd($feedType, $siteId, $once=false)
Definition agent.php:119
static update($siteId, array $feedSettings)
Definition agent.php:131
static log($level, $type, $itemId, $description, $siteId)
Definition ebay.php:147