Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
feed.php
1<?php
2
4
10
15class Feed
16{
18 protected $dataConvertor;
22 protected $dataProcessor;
23 protected $feedType;
24 protected $startPosition;
25
27 static $timer = NULL;
28
35 public function __construct($params, $startPosition)
36 {
37 if (isset($params["TIMER"]) && $params["TIMER"] instanceof Timer)
38 self::$timer = $params["TIMER"];
39
40 if (!isset($params["DATA_SOURCE"]) /*|| (!($params["DATA_SOURCE"] instanceof Data\Sources\DataSource))*/)
41 throw new ArgumentException("DATA_SOURCE must be instanceof DataSource!", "DATA_SOURCE");
42
43 if (!isset($params["DATA_CONVERTER"]) /*|| (!($params["DATA_CONVERTER"] instanceof Data\Converters\DataConverter))*/)
44 throw new ArgumentException("DATA_CONVERTER must be instanceof DataConverter!", "DATA_CONVERTER");
45
46 if (!isset($params["DATA_PROCESSOR"]) || (!($params["DATA_PROCESSOR"] instanceof Data\Processors\DataProcessor)))
47 throw new ArgumentException("DATA_PROCESSOR must be instanceof DataProcessor!", "DATA_PROCESSOR");
48
49 $this->feedType = $params["FEED_TYPE"];
50 $this->sourceDataIterator = $params["DATA_SOURCE"];
51 $this->dataConvertor = $params["DATA_CONVERTER"];
52 $this->dataProcessor = $params["DATA_PROCESSOR"];
53 $this->startPosition = $startPosition;
54 }
55
60 private static function getTimer()
61 {
62 return self::$timer;
63 }
64
72 public function processData($exportId = NULL)
73 {
74// EMPTY data for deleteAll-operations
75 if (!$this->sourceDataIterator)
76 {
77 $this->dataProcessor->process(NULL, self::getTimer());
78 }
79
80 else
81 {
82 $vk = Vk\Vk::getInstance();
83 $executionItemsLimit = $exportId ? $vk->getExecutionItemsLimit($exportId) : Vk\Vk::MAX_EXECUTION_ITEMS;
84
85 $journal = new Vk\Journal($exportId, $this->feedType);
86 $logger = new Vk\Logger($exportId);
87 $logger->addLog('Feed start', 'Feed type ' . $this->feedType);
88
89 $convertedData = array();
90 $nextStepItem = NULL;
91 $nextStepFlag = false;
92
93 foreach ($this->sourceDataIterator as $data)
94 {
95 $logger->addLog('Item to convert', 'ID: ' . $data["ID"] . ' NAME: ' . $data["NAME"]);
96 if ($nextStepFlag)
97 {
98 $nextStepItem = $data["ID"];
99 break;
100 }
101
102 if ($currData = $this->dataConvertor->convert($data))
103 {
104 $convertedData += $currData;
105 }
106
107 if (count($convertedData) >= $executionItemsLimit)
108 {
109 $nextStepFlag = true;
110 }
111 }
112
113// PROCESSING
114 if (count($convertedData) > 0)
115 {
116 $logger->addLog('Items to process', 'Count '.count($convertedData));
117 $this->dataProcessor->process($convertedData, self::getTimer());
118 $logger->addLog('Finish process items', 'Count '.count($convertedData));
119 $journal->addItemsCount(count($convertedData));
120// for running next step
121 if ($nextStepItem)
122 {
123 throw new TimeIsOverException("VK export next step", $nextStepItem);
124 }
125 }
126
127 if (count($convertedData) == 0 && $this->feedType == 'PRODUCTS')
128 {
129 $logger->addError('EMPTY_SECTION_PRODUCTS');
130 }
131
132// all OK - close journal
133 $journal->end();
134
135 $vk->log(
137 "VK_FEED__FEED_FINISH_OK",
138 'FEED_' . $this->feedType,
139 "VKontakte export of " . $this->feedType . " for export profile " . $exportId . " was finished successful. "
140 );
141 }
142 }
143
144}
__construct($params, $startPosition)
Definition feed.php:35