Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
feed.php
1<?php
2
4
8use \Bitrix\Sale\TradingPlatform\Timer;
9use \Bitrix\Sale\TradingPlatform\Logger;
10use \Bitrix\Sale\TradingPlatform\Ebay\Ebay;
11use \Bitrix\Sale\TradingPlatform\TimeIsOverException;
12
13class Feed
14{
16 protected $dataConvertor;
20 protected $dataProcessor;
21
23 protected $timer = null;
24 protected $siteId = "";
25
26 public function __construct($params)
27 {
28 if(isset($params["TIMER"]) && $params["DATA_SOURCE"] instanceof Timer)
29 $this->timer = $params["TIMER"];
30
31 if(!isset($params["DATA_SOURCE"]) || (!($params["DATA_SOURCE"] instanceof Data\Sources\DataSource)))
32 throw new ArgumentException("DATA_SOURCE must be instanceof DataSource!", "DATA_SOURCE");
33
34 if(!isset($params["DATA_CONVERTER"]) || (!($params["DATA_CONVERTER"] instanceof Data\Converters\DataConverter)))
35 throw new ArgumentException("DATA_CONVERTER must be instanceof DataConverter!", "DATA_CONVERTER");
36
37 if(!isset($params["DATA_PROCESSOR"]) || (!($params["DATA_PROCESSOR"] instanceof Data\Processors\DataProcessor)))
38 throw new ArgumentException("DATA_PROCESSOR must be instanceof DataProcessor!", "DATA_PROCESSOR");
39
40 if(empty($params["SITE_ID"]))
41 throw new ArgumentNullException("params[\"SITE_ID\"]");
42
43 $this->sourceDataIterator = $params["DATA_SOURCE"];
44 $this->dataConvertor = $params["DATA_CONVERTER"];
45 $this->dataProcessor = $params["DATA_PROCESSOR"];
46 $this->site = $params["SITE_ID"];
47 }
48
49 public function processData($startPosition = "")
50 {
51 $this->sourceDataIterator->setStartPosition($startPosition);
52 $errorsMsgs = '';
53
54 foreach($this->sourceDataIterator as $position => $data)
55 {
56 try
57 {
58 $convertedData = $this->dataConvertor->convert($data);
59 $this->dataProcessor->process($convertedData);
60 }
61 catch(SystemException $e)
62 {
63 $errorsMsgs .= $e->getMessage().'\n';
64 }
65
66 if ($this->timer !== null && !$this->timer->check())
67 {
68 if(!empty($errorsMsgs))
69 $_SESSION['SALE_EBAY_FEED_PROCESSDATA_ERRORS'] .= $errorsMsgs;
70
71 throw new TimeIsOverException("Timelimit is over", $position);
72 }
73 }
74
75 if(!empty($_SESSION['SALE_EBAY_FEED_PROCESSDATA_ERRORS']))
76 {
77 $errorsMsgs = $_SESSION['SALE_EBAY_FEED_PROCESSDATA_ERRORS'].$errorsMsgs;
78 unset($_SESSION['SALE_EBAY_FEED_PROCESSDATA_ERRORS']);
79 }
80
81 if(!empty($errorsMsgs))
82 Ebay::log(Logger::LOG_LEVEL_ERROR, "EBAY_FEED_PROCESS_DATA_ERRORS", '', $errorsMsgs, $this->site);
83 }
84
85 public function setSourceData($data)
86 {
87 $this->sourceDataIterator->setData($data);
88 }
89}
static log($level, $type, $itemId, $description, $siteId)
Definition ebay.php:147