1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
element.php
См. документацию.
1<?php
2namespace Bitrix\Iblock\Copy\Implement\Children;
3
4use Bitrix\Iblock\Copy\Stepper\Iblock as IblockStepper;
5use Bitrix\Iblock\Copy\Stepper\Section as SectionStepper;
6use Bitrix\Main\Config\Option;
7use Bitrix\Main\Result;
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 protected array $fieldRatio = [];
20
24 protected $result;
25
26 public function __construct($copyMode)
27 {
28 $this->copyMode = $copyMode;
29
30 $this->result = new Result();
31 }
32
40 {
41 $this->sectionsRatio = $sectionsRatio;
42 }
43
50 public function setEnumRatio(array $enumRatio)
51 {
52 $this->enumRatio = $enumRatio;
53 }
54
61 public function setFieldRatio(array $fieldRatio): void
62 {
63 $this->fieldRatio = $fieldRatio;
64 }
65
73 public function copy($entityId, $copiedEntityId): Result
74 {
75 if ($this->copyMode == self::SECTION_COPY_MODE)
76 {
77 return $this->copySectionElements($entityId, $copiedEntityId);
78 }
79 else
80 {
81 return $this->copyIblockElements($entityId, $copiedEntityId);
82 }
83 }
84
90 protected function copySectionElements(int $sectionId, int $copiedSectionId)
91 {
92 $this->addToQueue($copiedSectionId, "SectionGroupQueue");
93
94 Option::set($this->moduleId, "SectionGroupChecker_".$copiedSectionId, "Y");
95
96 $queueOption = [
97 "sectionId" => $sectionId,
98 "copiedSectionId" => $copiedSectionId,
99 "enumRatio" => ($this->enumRatio[$sectionId] ?: []),
100 "sectionsRatio" => ($this->sectionsRatio[$sectionId] ?: [])
101 ];
102 Option::set($this->moduleId, "SectionGroupStepper_".$copiedSectionId, serialize($queueOption));
103
104 $agent = \CAgent::getList([], [
105 "MODULE_ID" => $this->moduleId,
106 "NAME" => SectionStepper::class."::execAgent();"
107 ])->fetch();
108 if (!$agent)
109 {
110 SectionStepper::bind(1);
111 }
112
113 return $this->result;
114 }
115
121 private function copyIblockElements(int $iblockId, int $copiedIblockId)
122 {
123 $this->addToQueue($copiedIblockId, "IblockGroupQueue");
124
125 $moduleId = "iblock";
126
127 Option::set($moduleId, "IblockGroupChecker_".$copiedIblockId, "Y");
128
129 $queueOption = [
130 "iblockId" => $iblockId,
131 "copiedIblockId" => $copiedIblockId,
132 "enumRatio" => ($this->enumRatio[$iblockId] ?? []),
133 "sectionsRatio" => ($this->sectionsRatio[$iblockId] ?? []),
134 'fieldRatio' => ($this->fieldRatio[$iblockId] ?? []),
135 ];
136
137 Option::set($moduleId, "IblockGroupStepper_".$copiedIblockId, serialize($queueOption));
138
139 $agent = \CAgent::getList([], [
140 "MODULE_ID" => $moduleId,
141 "NAME" => IblockStepper::class."::execAgent();"
142 ])->fetch();
143 if (!$agent)
144 {
145 IblockStepper::bind(1);
146 }
147
148 return $this->result;
149 }
150
151 protected function addToQueue(int $copiedSectionId, $queueName)
152 {
153 $option = Option::get($this->moduleId, $queueName, "");
154 $option = ($option !== "" ? unserialize($option, ['allowed_classes' => false]) : []);
155 $option = (is_array($option) ? $option : []);
156
157 $option[] = $copiedSectionId;
158 Option::set($this->moduleId, $queueName, serialize($option));
159 }
160}
copy($entityId, $copiedEntityId)
Определения element.php:73
addToQueue(int $copiedSectionId, $queueName)
Определения element.php:151
copySectionElements(int $sectionId, int $copiedSectionId)
Определения element.php:90
setSectionsRatio(array $sectionsRatio)
Определения element.php:39
setFieldRatio(array $fieldRatio)
Определения element.php:61
setEnumRatio(array $enumRatio)
Определения element.php:50
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$moduleId
$iblockId
Определения iblock_catalog_edit.php:30
$entityId
Определения payment.php:4
$option
Определения options.php:1711