Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
element.php
1<?php
3
4use Bitrix\Iblock\Copy\Stepper\Iblock as IblockStepper;
5use Bitrix\Iblock\Copy\Stepper\Section as SectionStepper;
8
9class Element implements Child
10{
11 const IBLOCK_COPY_MODE = "iblock";
12 const SECTION_COPY_MODE = "section";
13
14 protected $moduleId = "iblock";
15
16 private $copyMode;
17 protected $sectionsRatio = [];
18 protected $enumRatio = [];
19
23 protected $result;
24
25 public function __construct($copyMode)
26 {
27 $this->copyMode = $copyMode;
28
29 $this->result = new Result();
30 }
31
32 public function setSectionsRatio(array $sectionsRatio)
33 {
34 $this->sectionsRatio = $sectionsRatio;
35 }
36
37 public function setEnumRatio(array $enumRatio)
38 {
39 $this->enumRatio = $enumRatio;
40 }
41
49 public function copy($entityId, $copiedEntityId): Result
50 {
51 if ($this->copyMode == self::SECTION_COPY_MODE)
52 {
53 return $this->copySectionElements($entityId, $copiedEntityId);
54 }
55 else
56 {
57 return $this->copyIblockElements($entityId, $copiedEntityId);
58 }
59 }
60
68 protected function copySectionElements(int $sectionId, int $copiedSectionId)
69 {
70 $this->addToQueue($copiedSectionId, "SectionGroupQueue");
71
72 Option::set($this->moduleId, "SectionGroupChecker_".$copiedSectionId, "Y");
73
74 $queueOption = [
75 "sectionId" => $sectionId,
76 "copiedSectionId" => $copiedSectionId,
77 "enumRatio" => ($this->enumRatio[$sectionId] ?: []),
78 "sectionsRatio" => ($this->sectionsRatio[$sectionId] ?: [])
79 ];
80 Option::set($this->moduleId, "SectionGroupStepper_".$copiedSectionId, serialize($queueOption));
81
82 $agent = \CAgent::getList([], [
83 "MODULE_ID" => $this->moduleId,
84 "NAME" => SectionStepper::class."::execAgent();"
85 ])->fetch();
86 if (!$agent)
87 {
88 SectionStepper::bind(1);
89 }
90
91 return $this->result;
92 }
93
101 private function copyIblockElements(int $iblockId, int $copiedIblockId)
102 {
103 $this->addToQueue($copiedIblockId, "IblockGroupQueue");
104
105 $moduleId = "iblock";
106
107 Option::set($moduleId, "IblockGroupChecker_".$copiedIblockId, "Y");
108
109 $queueOption = [
110 "iblockId" => $iblockId,
111 "copiedIblockId" => $copiedIblockId,
112 "enumRatio" => ($this->enumRatio[$iblockId] ?: []),
113 "sectionsRatio" => ($this->sectionsRatio[$iblockId] ?: [])
114 ];
115 Option::set($moduleId, "IblockGroupStepper_".$copiedIblockId, serialize($queueOption));
116
117 $agent = \CAgent::getList([], [
118 "MODULE_ID" => $moduleId,
119 "NAME" => IblockStepper::class."::execAgent();"
120 ])->fetch();
121 if (!$agent)
122 {
123 IblockStepper::bind(1);
124 }
125
126 return $this->result;
127 }
128
129 protected function addToQueue(int $copiedSectionId, $queueName)
130 {
131 $option = Option::get($this->moduleId, $queueName, "");
132 $option = ($option !== "" ? unserialize($option, ['allowed_classes' => false]) : []);
133 $option = (is_array($option) ? $option : []);
134
135 $option[] = $copiedSectionId;
136 Option::set($this->moduleId, $queueName, serialize($option));
137 }
138}
copy($entityId, $copiedEntityId)
Definition element.php:49
addToQueue(int $copiedSectionId, $queueName)
Definition element.php:129
copySectionElements(int $sectionId, int $copiedSectionId)
Definition element.php:68