Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
entityimport.php
1<?php
3
10
16abstract class EntityImport extends Exchange\ImportBase
17{
18 public $collisions = array();
19
20 protected $parentEntity = null;
22 protected $entity = null;
23 protected $external = null;
24 protected $marked = false;
25
26 public function __construct($parentEntityContext = null)
27 {
28 $this->fields = new Sale\Internals\Fields();
29
30 if(!empty($parentEntityContext))
31 {
32 $this->setParentEntity($parentEntityContext);
33 }
34 }
35
39 public function getOwnerTypeId()
40 {
41 return Exchange\EntityType::UNDEFINED;
42 }
43
49 {
50 $this->parentEntity = $parentEntity;
51 }
52
56 public function getParentEntity()
57 {
59 }
60
64 public function isLoadedParentEntity()
65 {
66 $order = $this->getParentEntity();
67 return $order instanceof Sale\Order;
68 }
69
74 protected function loadParentEntity(array $fields)
75 {
76 $entity = null;
77
78 if(!empty($fields['ID']))
79 {
80
81 $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
83 $orderClass = $registry->getOrderClassName();
84
86 $entity = $orderClass::load($fields['ID']);
87 }
88 return $entity;
89 }
90
95 abstract public function setEntity(Sale\Internals\Entity $entity);
96
100 public function getEntity()
101 {
102 return $this->entity;
103 }
104
108 protected function isExternal()
109 {
110 return $this->external;
111 }
112
116 public function setExternal($external = true)
117 {
118 $this->external = $external;
119 }
120
127 public function setCollisions($tipeId, Sale\Internals\Entity $entity, $message=null)
128 {
130 {
131 $this->collisionErrors = true;
132 }
134 {
135 $this->collisionWarnings = true;
136 }
137
138 $collision = $this->getCurrentCollision($this->getOwnerTypeId());
139 $collision->addItem($this->getOwnerTypeId(), $tipeId, $entity, $message);
140
141 $this->collisions[] = $collision;
142 }
143
147 public function getCollisions()
148 {
149 return $this->collisions;
150 }
151
155 public function hasCollisions()
156 {
157 return (count($this->collisions));
158 }
159
163 public function markedEntityCollisions($collisions)
164 {
166 $entity = $this->getEntity();
167
170
172 foreach($collisions as $collision)
173 {
174 $result = new Sale\Result();
175 $result->addWarning(new Sale\ResultError(Exchange\EntityCollisionType::getDescription($collision->getTypeId()).($collision->getMessage() != null ? " ".$collision->getMessage():'' ), $collision->getTypeName()));
176
177 $entity->setField('MARKED', 'Y');
178 $this->marked = true;
179
180 $collisionEntity = $collision->getEntity();
181 if(!empty($collisionEntity))
182 {
183 $this->addMarker($parentEntity, $collisionEntity, $result);
184 }
185 else
186 {
187 $this->addMarker($parentEntity, $entity, $result);
188 }
189 }
190 }
191
197 protected function addMarker($order, $entity, $result)
198 {
199 EntityMarker::addMarker($order, $entity, $result);
200 }
201
205 public function isMarked()
206 {
207 return $this->marked;
208 }
209
213 public function getId()
214 {
215 return $this->getEntityId();
216 }
217
223 public function isImportable()
224 {
225 return $this->settings->isImportableFor($this->getOwnerTypeId());
226 }
227
233 public function import(array $params)
234 {
235 $result = parent::import($params);
236 if($result->isSuccess())
237 {
239 if(($entity = $this->getEntity()))
240 $this->marked($entity, $params['TRAITS']);
241 }
242 return $result;
243 }
244
248 abstract public function save();
249
256 function marked(Sale\Internals\Entity $entity, array $fields)
257 {
258 if($this->isExternal())
259 $entity->setField($this->getExternalFieldName(), 'Y');
260 else
261 $entity->setField('UPDATED_1C', 'Y');
262
263 if(!$this->hasCollisions())
264 {
265 $entity->setField('VERSION_1C', $fields['VERSION_1C']);
266 }
267
268 $entity->setField('ID_1C', $fields['ID_1C']);
269
270 if(!($entity instanceof Sale\Order))
271 {
274
275 $parentEntity->setField('UPDATED_1C','Y');
276 }
277 }
278
282 public function getEntityId()
283 {
284 $entity = $this->getEntity();
285 if(!empty($entity))
286 {
288 return $entity->getId();
289 }
290
291 return null;
292 }
293
298 protected function checkEntity($id)
299 {
300 return is_int($id) && $id > 0;
301 }
302
306 abstract protected function getExternalFieldName();
307
312 public static function resolveEntityTypeId(Sale\Internals\Entity $entity)
313 {
314 return Exchange\EntityType::UNDEFINED;
315 }
316
320 public static function getFieldExternalId()
321 {
322 return 'ID_1C';
323 }
324}
setParentEntity(Sale\Order $parentEntity)
__construct($parentEntityContext=null)
setCollisions($tipeId, Sale\Internals\Entity $entity, $message=null)
static resolveEntityTypeId(Sale\Internals\Entity $entity)
setEntity(Sale\Internals\Entity $entity)