Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
iblock.php
1<?php
3
6
7class Iblock extends Entity
8{
9 protected $queueName = "IblockGroupQueue";
10 protected $checkerName = "IblockGroupChecker_";
11 protected $baseName = "IblockGroupStepper_";
12 protected $errorName = "IblockGroupError_";
13
22 public function execute(array &$option)
23 {
24 if (!Loader::includeModule(self::$moduleId))
25 {
26 return false;
27 }
28
29 try
30 {
31 $queue = $this->getQueue();
32 $this->setQueue($queue);
33 $queueOption = $this->getOptionData($this->baseName);
34 if (empty($queueOption))
35 {
36 $this->deleteQueueOption();
37 return !$this->isQueueEmpty();
38 }
39
40 $iblockId = ($queueOption["iblockId"] ?: 0);
41 $copiedIblockId = ($queueOption["copiedIblockId"] ?: 0);
42 $errorOffset = ($queueOption["errorOffset"] ?: 0);
43
44 $limit = 5;
45 $offset = $this->getOffset($copiedIblockId) + $errorOffset;
46
47 $enumRatio = ($queueOption["enumRatio"] ?: []);
48 $sectionsRatio = ($queueOption["sectionsRatio"] ?: []);
49 $mapIdsCopiedElements = ($queueOption["mapIdsCopiedElements"] ?: []);
50
51 if ($iblockId)
52 {
53 list($elementIds, $selectedRowsCount) = $this->getElementIds($iblockId, $limit, $offset);
54
55 $elementCopier = $this->getElementCopier();
56 $containerCollection = $this->getContainerCollection(
57 $elementIds, $sectionsRatio, $enumRatio, $copiedIblockId);
58 $result = $elementCopier->copy($containerCollection);
59 if (!$result->isSuccess())
60 {
61 $queueOption["errorOffset"] += $this->getErrorOffset($elementCopier);
62 }
63
64 $mapIdsCopiedElements = $elementCopier->getMapIdsCopiedEntity() + $mapIdsCopiedElements;
65 $queueOption["mapIdsCopiedElements"] = $mapIdsCopiedElements;
66 $this->saveQueueOption($queueOption);
67
68 if ($selectedRowsCount < $limit)
69 {
70 $this->deleteQueueOption();
71 $this->onAfterCopy($queueOption);
72 return !$this->isQueueEmpty();
73 }
74 else
75 {
76 $option["steps"] = $offset;
77 return true;
78 }
79 }
80 else
81 {
82 $this->deleteQueueOption();
83 return !$this->isQueueEmpty();
84 }
85 }
86 catch (\Exception $exception)
87 {
88 $this->writeToLog($exception);
89 $this->deleteQueueOption();
90 return false;
91 }
92 }
93
94 private function getElementIds(int $iblockId, int $limit, int $offset): array
95 {
96 $elementIds = [];
97
98 $connection = Application::getInstance()->getConnection();
99 $sqlHelper = $connection->getSqlHelper();
100
101 $queryObject = $connection->query("SELECT ID FROM `b_iblock_element` WHERE `IBLOCK_ID` = '".
102 $sqlHelper->forSql($iblockId)."' ORDER BY ID ASC LIMIT ".$limit." OFFSET ".$offset);
103 $selectedRowsCount = $queryObject->getSelectedRowsCount();
104 while ($element = $queryObject->fetch())
105 {
106 $elementIds[] = $element["ID"];
107 }
108
109 return [$elementIds, $selectedRowsCount];
110 }
111
112 private function getOffset(int $copiedIblockId): int
113 {
114 $elementIds = [];
115
116 $connection = Application::getInstance()->getConnection();
117 $sqlHelper = $connection->getSqlHelper();
118
119 $queryObject = $connection->query("SELECT ID FROM `b_iblock_element` WHERE `IBLOCK_ID` = '".
120 $sqlHelper->forSql($copiedIblockId)."' ORDER BY ID");
121 while ($element = $queryObject->fetch())
122 {
123 $elementIds[] = $element["ID"];
124 }
125
126 return count($elementIds);
127 }
128}
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
writeToLog(\Exception $exception)
Definition stepper.php:406