Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
entity.php
1<?php
3
4use Bitrix\Iblock\Copy\Implement\Element as ElementImplementer;
11
12abstract class Entity extends Stepper
13{
14 protected static $moduleId = "iblock";
15
16 protected function getContainerCollection($elementIds, array $sectionsRatio, array $enumRatio, $targetIblockId = 0)
17 {
18 $containerCollection = new ContainerCollection();
19
20 foreach ($elementIds as $elementId)
21 {
22 $container = new Container($elementId);
23 $dictionary = new Dictionary(
24 [
25 "targetIblockId" => $targetIblockId,
26 "enumRatio" => $enumRatio,
27 "sectionsRatio" => $sectionsRatio
28 ]
29 );
30 $container->setDictionary($dictionary);
31
32 $containerCollection[] = $container;
33 }
34
35 return $containerCollection;
36 }
37
38 protected function getElementCopier()
39 {
40 $elementImplementer = new ElementImplementer();
41 return new EntityCopier($elementImplementer);
42 }
43
44 protected function onAfterCopy(array $queueOption)
45 {
46 $this->saveErrorOption($queueOption);
47 }
48
49 protected function getErrorOffset(EntityCopier $elementCopier): int
50 {
51 $numberIds = count($elementCopier->getMapIdsCopiedEntity());
52 $numberSuccessIds = count(array_filter($elementCopier->getMapIdsCopiedEntity()));
53 return $numberIds - $numberSuccessIds;
54 }
55
56 private function saveErrorOption(array $queueOption)
57 {
58 $mapIdsCopiedElements = $queueOption["mapIdsCopiedElements"] ?: [];
59
60 $mapIdsWithErrors = [];
61 foreach ($mapIdsCopiedElements as $elementId => $copiedElementId)
62 {
63 if (!$copiedElementId)
64 {
65 $mapIdsWithErrors[] = $elementId;
66 }
67 }
68
69 if ($mapIdsWithErrors)
70 {
71 Option::set(self::$moduleId, $this->errorName, serialize($mapIdsWithErrors));
72 }
73 }
74
75 protected function getQueue(): array
76 {
77 return $this->getOptionData($this->queueName);
78 }
79
80 protected function setQueue(array $queue): void
81 {
82 $queueId = (string) current($queue);
83 $this->checkerName = (mb_strpos($this->checkerName, $queueId) === false ?
84 $this->checkerName.$queueId : $this->checkerName);
85 $this->baseName = (mb_strpos($this->baseName, $queueId) === false ?
86 $this->baseName.$queueId : $this->baseName);
87 $this->errorName = (mb_strpos($this->errorName, $queueId) === false ?
88 $this->errorName.$queueId : $this->errorName);
89 }
90
91 protected function getQueueOption()
92 {
93 return $this->getOptionData($this->baseName);
94 }
95
96 protected function saveQueueOption(array $data)
97 {
98 Option::set(static::$moduleId, $this->baseName, serialize($data));
99 }
100
101 protected function deleteQueueOption()
102 {
103 $queue = $this->getQueue();
104 $this->setQueue($queue);
105 $this->deleteCurrentQueue($queue);
106 Option::delete(static::$moduleId, ["name" => $this->checkerName]);
107 Option::delete(static::$moduleId, ["name" => $this->baseName]);
108 }
109
110 protected function deleteCurrentQueue(array $queue): void
111 {
112 $queueId = current($queue);
113 $currentPos = array_search($queueId, $queue);
114 if ($currentPos !== false)
115 {
116 unset($queue[$currentPos]);
117 Option::set(static::$moduleId, $this->queueName, serialize($queue));
118 }
119 }
120
121 protected function isQueueEmpty()
122 {
123 $queue = $this->getOptionData($this->queueName);
124 return empty($queue);
125 }
126
127 protected function getOptionData($optionName)
128 {
129 $option = Option::get(static::$moduleId, $optionName);
130 $option = ($option !== "" ? unserialize($option, ['allowed_classes' => false]) : []);
131 return (is_array($option) ? $option : []);
132 }
133
134 protected function deleteOption($optionName)
135 {
136 Option::delete(static::$moduleId, ["name" => $optionName]);
137 }
138}
getContainerCollection($elementIds, array $sectionsRatio, array $enumRatio, $targetIblockId=0)
Definition entity.php:16
onAfterCopy(array $queueOption)
Definition entity.php:44
getErrorOffset(EntityCopier $elementCopier)
Definition entity.php:49