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