Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
manager.php
1<?php
3
10
11Loc::loadMessages(__FILE__);
12
19{
21
25 public static function getOrderFieldNames()
26 {
27 return array(
28 "ACCOUNT_NUMBER", "USER_ID", "PRICE", "SUM_PAID", "CURRENCY", "STATUS_ID", "PAYED", "DEDUCTED", "CANCELED",
29 "LID", "PERSON_TYPE_ID", "XML_ID", "ID_1C", "DATE_INSERT", "RESPONSIBLE_ID", "COMPANY_ID"
30 );
31 }
32
36 public static function getBasketFieldNames()
37 {
38 return array(
39 "PRODUCT_ID", "PRODUCT_PRICE_ID", "NAME", "PRICE", "MODULE", "QUANTITY", "WEIGHT", "DATE_INSERT",
40 "CURRENCY", "PRODUCT_XML_ID", "MEASURE_NAME", "TYPE", "SET_PARENT_ID", "MEASURE_CODE", "BASKET_DATA"
41 );
42 }
43
55 public static function archiveOrders($filter = array(), $limit = null, $timeExecution = null)
56 {
57 $result = new Sale\Result();
58 $countArchived = 0;
59
60 if ((int)$timeExecution)
61 {
62 @set_time_limit(0);
63 }
64
65 $params["filter"] = $filter;
66 $params["order"] = array('ID' => "ASC");
67 if ((int)$limit)
68 {
69 $params["limit"] = (int)$limit;
70 }
71
72 $orderArchiveCollection = new Process\OrderArchiveCollection();
73 $fillResult = $orderArchiveCollection->loadFromDB($params);
74 if ($fillResult->hasWarnings())
75 {
76 return $fillResult;
77 }
78
80 foreach ($orderArchiveCollection as $index => $item)
81 {
82 $resultArchiving = $item->archive();
83 if ($resultArchiving->isSuccess())
84 {
85 $countArchived++;
86 $orderArchiveCollection->deleteItem($index);
87 }
88 else
89 {
90 $errorMessages = $resultArchiving->getErrorMessages();
91 foreach ($errorMessages as $error)
92 {
93 $result->addError(new Main\Error(Loc::getMessage("ARCHIVE_ERROR_ORDER_MESSAGE", array("#ID#" => $item->getId())).": ".$error));
94 }
95 }
96
97 if ((int)$timeExecution && (getmicrotime() - START_EXEC_TIME > $timeExecution))
98 {
99 break;
100 }
101 }
102
103 $result->setData(array("count" => $countArchived));
104 return $result;
105 }
106
119 public static function archiveByOptions($limit = null, $timeExecution = null)
120 {
121 $filter = Option::get('sale', 'archive_params');
122
123 if ($filter == '')
124 {
125 throw new Main\SystemException("Settings of order's archiving are null or empty");
126 }
127
128 $filter = unserialize($filter, ['allowed_classes' => false]);
129
130 if (isset($filter['PERIOD']))
131 {
132 if ((int)$filter['PERIOD'] > 0)
133 {
134 $date = new Type\DateTime();
135 $latestDate = $date->add('-'.(int)$filter['PERIOD'].' day');
136 $filter['<=DATE_INSERT'] = $latestDate;
137 }
138
139 unset($filter['PERIOD']);
140 }
141
142 return static::archiveOrders($filter, $limit, $timeExecution);
143 }
144
155 public static function archiveOnAgent($limit, $maxTime = null)
156 {
157 global $USER;
158 $agentId = null;
159
160 $limit = (int)$limit ? (int)$limit : 10;
161 $maxTime = (int)$maxTime ? (int)$maxTime : null;
162
163 $agentsList = \CAgent::GetList(array("ID"=>"DESC"), array(
164 "MODULE_ID" => "sale",
165 "NAME" => "\\Bitrix\\Sale\\Archive\\Manager::archiveOnAgent(%",
166 ));
167 while($agent = $agentsList->Fetch())
168 {
169 $agentId = $agent["ID"];
170 }
171
172 if ($agentId)
173 {
174 if (!(isset($USER) && $USER instanceof \CUser))
175 {
176 $USER = new \CUser();
177 }
178
179 $result = static::archiveByOptions($limit, $maxTime);
180
181 $resultData = $result->getData();
182 if ($resultData['count'])
183 {
184 \CAgent::Update($agentId, array("AGENT_INTERVAL" => 60*5));
185
186 }
187 else
188 {
189 \CAgent::Update($agentId, array("AGENT_INTERVAL" => 24*60*60));
190 }
191 }
192 else
193 {
194 \CAgent::AddAgent("\\Bitrix\\Sale\\Archive\\Manager::archiveOnAgent(".$limit.",".$maxTime.");", "sale", "N", 24*60*60, "", "Y");
195 }
196
197 return "\\Bitrix\\Sale\\Archive\\Manager::archiveOnAgent(".$limit.",".$maxTime.");";
198 }
199
205 public static function getList(array $parameters = array())
206 {
207 return Internals\OrderArchiveTable::getList($parameters);
208 }
209
217 public static function getById($id)
218 {
219 return Internals\OrderArchiveTable::getById($id);
220 }
221
230 public static function getBasketList(array $parameters = array())
231 {
232 return Internals\BasketArchiveTable::getList($parameters);
233 }
234
243 public static function getBasketItemById($id)
244 {
245 return Internals\BasketArchiveTable::getById($id);
246 }
247
256 public static function delete($id)
257 {
258 $basketItems = static::getBasketList(
259 array(
260 "filter" => array("ARCHIVE_ID" => $id),
261 "select" => array("ID")
262 )
263 );
264 while ($item = $basketItems->fetch())
265 {
266 Internals\BasketArchiveTable::delete($item['ID']);
267 }
268
269 return Internals\OrderArchiveTable::delete($id);
270 }
271
281 public static function returnArchivedOrder($id)
282 {
283 $id = (int)$id;
284 if ($id <= 0)
285 throw new Main\ArgumentNullException("id");
286
287 $restorer = Recovery\Restorer::load($id);
288 if (!$restorer)
289 {
290 return null;
291 }
292
293 return $restorer->restoreOrder();
294 }
295}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static archiveOnAgent($limit, $maxTime=null)
Definition manager.php:155
static getList(array $parameters=array())
Definition manager.php:205
static returnArchivedOrder($id)
Definition manager.php:281
static getBasketItemById($id)
Definition manager.php:243
static getBasketList(array $parameters=array())
Definition manager.php:230
static archiveByOptions($limit=null, $timeExecution=null)
Definition manager.php:119