1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
iblock.php
См. документацию.
1<?php
2
3namespace Bitrix\Iblock\Copy\Stepper;
4
5use Bitrix\Main\Loader;
6use Bitrix\Main\Type\Dictionary;
7use Bitrix\Iblock\ElementTable;
8use Bitrix\Iblock\PropertyTable;
9
10class Iblock extends Entity
11{
12 protected $queueName = "IblockGroupQueue";
13 protected $checkerName = "IblockGroupChecker_";
14 protected $baseName = "IblockGroupStepper_";
15 protected $errorName = "IblockGroupError_";
16
25 public function execute(array &$option)
26 {
27 if (!Loader::includeModule(self::$moduleId))
28 {
29 return false;
30 }
31
32 try
33 {
34 $queue = $this->getQueue();
35 $this->setQueue($queue);
36 $queueOption = $this->getOptionData($this->baseName);
37 if (empty($queueOption))
38 {
39 $this->deleteQueueOption();
40
41 return !$this->isQueueEmpty();
42 }
43 $queueOption["errorOffset"] = (int)($queueOption["errorOffset"] ?? 0);
44
45 $iblockId = (int)($queueOption["iblockId"] ?? 0);
46 $copiedIblockId = (int)($queueOption["copiedIblockId"] ?? 0);
47 $errorOffset = $queueOption["errorOffset"];
48 $queueOption["errorOffset"] ??= 0;
49
50 $limit = 5;
51 $offset = $this->getOffset($copiedIblockId) + $errorOffset;
52
53 $enumRatio = ($queueOption["enumRatio"] ?? []);
54 if (!is_array($enumRatio))
55 {
56 $enumRatio = [];
57 }
58 $sectionsRatio = ($queueOption["sectionsRatio"] ?? []);
59 if (!is_array($sectionsRatio))
60 {
61 $sectionsRatio = [];
62 }
63 $mapIdsCopiedElements = ($queueOption["mapIdsCopiedElements"] ?? []);
64 if (!is_array($mapIdsCopiedElements))
65 {
66 $mapIdsCopiedElements = [];
67 }
68 $fieldRatio = ($queueOption['fieldRatio'] ?? []);
69 if (!is_array($fieldRatio))
70 {
71 $fieldRatio = [];
72 }
73
74 if ($iblockId)
75 {
76 list($elementIds, $selectedRowsCount) = $this->getElementIds($iblockId, $limit, $offset);
77
78 $elementCopier = $this->getElementCopier();
79
80 if (empty($fieldRatio))
81 {
82 $fieldRatio = $this->compileFieldRatio($iblockId, $copiedIblockId);
83 if (!empty($fieldRatio))
84 {
85 $queueOption['fieldRatio'] = $fieldRatio;
86 }
87 }
88
89 $dictionary = new Dictionary([
90 'targetIblockId' => $copiedIblockId,
91 'enumRatio' => $enumRatio,
92 'sectionsRatio' => $sectionsRatio,
93 'fieldRatio' => $fieldRatio,
94 ]);
95
96 $containerCollection = $this->fillContainerCollection($elementIds, $dictionary);
97
98 $result = $elementCopier->copy($containerCollection);
99 if (!$result->isSuccess())
100 {
101 $queueOption["errorOffset"] += $this->getErrorOffset($elementCopier);
102 }
103
104 $mapIdsCopiedElements = $elementCopier->getMapIdsCopiedEntity() + $mapIdsCopiedElements;
105 $queueOption["mapIdsCopiedElements"] = $mapIdsCopiedElements;
106 $this->saveQueueOption($queueOption);
107
108 if ($selectedRowsCount < $limit)
109 {
110 $this->deleteQueueOption();
111 $this->onAfterCopy($queueOption);
112
113 return !$this->isQueueEmpty();
114 }
115 else
116 {
117 $option["steps"] = $offset;
118
119 return true;
120 }
121 }
122 else
123 {
124 $this->deleteQueueOption();
125
126 return !$this->isQueueEmpty();
127 }
128 }
129 catch (\Exception $exception)
130 {
131 $this->writeToLog($exception);
132 $this->deleteQueueOption();
133
134 return false;
135 }
136 }
137
138 private function getElementIds(int $iblockId, int $limit, int $offset): array
139 {
140 $elementIds = [];
141
143 'select' => [
144 'ID',
145 ],
146 'filter' => [
147 '=IBLOCK_ID' => $iblockId,
148 ],
149 'order' => [
150 'ID' => 'ASC',
151 ],
152 'limit' => $limit,
153 'offset' => $offset,
154 ]);
155 while ($row = $iterator->fetch())
156 {
157 $elementIds[] = $row['ID'];
158 }
159 unset($row, $iterator);
160
161 return [$elementIds, count($elementIds)];
162 }
163
164 private function getOffset(int $copiedIblockId): int
165 {
167 '=IBLOCK_ID' => $copiedIblockId,
168 ]);
169 }
170
171 private function compileFieldRatio(int $iblockId, int $copiedIblockId): array
172 {
173 $result = [];
174
175 $source = $this->getPropertyList($iblockId);
176 $destination = $this->getPropertyList($copiedIblockId);
177
178 foreach ($source as $hash => $sourceId)
179 {
180 if (isset($destination[$hash]))
181 {
182 $result[$sourceId] = $destination[$hash];
183 }
184 }
185
186 return $result;
187 }
188
189 private function getPropertyHash(array $property): string
190 {
191 $property['USER_TYPE'] = (string)$property['USER_TYPE'];
192
193 return
194 $property['NAME'] . '|'
195 . $property['PROPERTY_TYPE'] . '|' . $property['USER_TYPE'] . '|'
196 . $property['MULTIPLE']
197 ;
198 }
199
200 private function getPropertyList(int $iblockId): array
201 {
202 $result = [];
204 'select' => [
205 'ID',
206 'NAME',
207 'PROPERTY_TYPE',
208 'MULTIPLE',
209 'USER_TYPE',
210 ],
211 'filter' => [
212 '=IBLOCK_ID' => $iblockId,
213 ],
214 'order' => [
215 'ID' => 'ASC',
216 ]
217 ]);
218 while ($row = $iterator->fetch())
219 {
220 $result[$this->getPropertyHash($row)] = (int)$row['ID'];
221 }
222 unset($iterator);
223
224 return $result;
225 }
226}
$hash
Определения ajax_redirector.php:8
saveQueueOption(array $data)
Определения entity.php:102
setQueue(array $queue)
Определения entity.php:86
getOptionData($optionName)
Определения entity.php:133
onAfterCopy(array $queueOption)
Определения entity.php:50
fillContainerCollection(array $elementIds, Dictionary $dictionary)
Определения entity.php:27
getErrorOffset(EntityCopier $elementCopier)
Определения entity.php:55
execute(array &$option)
Определения iblock.php:25
static includeModule($moduleName)
Определения loader.php:67
static getList(array $parameters=array())
Определения datamanager.php:431
static getCount($filter=array(), array $cache=array())
Определения datamanager.php:516
writeToLog(\Exception $exception)
Определения stepper.php:404
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$iblockId
Определения iblock_catalog_edit.php:30
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$option
Определения options.php:1711
$iterator
Определения yandex_run.php:610