Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
groupstepper.php
1
<?php
2
namespace
Bitrix\Photogallery\Copy\Integration
;
3
4
use
Bitrix\Main\Config\Option
;
5
use
Bitrix\Photogallery\Copy\Implement\Children\Element
as ElementImplementer;
6
use
Bitrix\Iblock\Copy\Implement\Section
as SectionImplementer;
7
use
Bitrix\Iblock\Copy\Section
as SectionCopier;
8
use
Bitrix\Main\Copy\Container
;
9
use
Bitrix\Main\Copy\ContainerCollection
;
10
use
Bitrix\Main\Loader
;
11
use
Bitrix\Main\Update\Stepper
;
12
13
class
GroupStepper
extends
Stepper
14
{
15
protected
static
$moduleId
=
"photogallery"
;
16
17
protected
$queueName
=
"PhotogalleryGroupQueue"
;
18
protected
$checkerName
=
"PhotogalleryGroupChecker_"
;
19
protected
$baseName
=
"PhotogalleryGroupStepper_"
;
20
protected
$errorName
=
"PhotogalleryGroupError_"
;
21
31
public
function
execute
(array &$option)
32
{
33
if
(!Loader::includeModule(
"iblock"
) || !Loader::includeModule(
"photogallery"
))
34
{
35
return
false
;
36
}
37
38
try
39
{
40
$queue = $this->
getQueue
();
41
$this->
setQueue
($queue);
42
$queueOption = $this->
getOptionData
($this->baseName);
43
44
$copiedGroupId = ($queueOption[
"copiedGroupId"
] ?: 0);
45
$parentSectionId = ($queueOption[
"parentSectionId"
] ?: 0);
46
$newSectionName = ($queueOption[
"newSectionName"
] ?:
""
);
47
48
if
($parentSectionId && $newSectionName)
49
{
50
$containerCollection =
new
ContainerCollection
();
51
$containerCollection[] =
new
Container
($parentSectionId);
52
53
$elementImplementer =
new
ElementImplementer(
ElementImplementer::SECTION_COPY_MODE
);
54
$sectionImplementer =
new
SectionImplementer();
55
$sectionImplementer->setChangedFields([
56
"NAME"
=> $newSectionName,
57
"CODE"
=>
"group_"
.$copiedGroupId,
58
"SOCNET_GROUP_ID"
=> $copiedGroupId,
59
]);
60
$sectionImplementer->setChangedFieldsForChildSections([
"CODE"
=>
"group_"
.$copiedGroupId]);
61
$sectionImplementer->setChild($elementImplementer);
62
63
$sectionCopier =
new
SectionCopier($sectionImplementer);
64
$sectionCopier->copy($containerCollection);
65
66
$this->
deleteQueueOption
();
67
return
!$this->
isQueueEmpty
();
68
}
69
else
70
{
71
$this->
deleteQueueOption
();
72
return
!$this->
isQueueEmpty
();
73
}
74
}
75
catch
(\Exception $exception)
76
{
77
$this->
writeToLog
($exception);
78
$this->
deleteQueueOption
();
79
return
false
;
80
}
81
}
82
83
protected
function
getQueue
(): array
84
{
85
return
$this->
getOptionData
($this->queueName);
86
}
87
88
protected
function
setQueue
(array $queue): void
89
{
90
$queueId = (string) current($queue);
91
$this->checkerName = (mb_strpos($this->checkerName, $queueId) ===
false
?
92
$this->checkerName.$queueId :
$this->checkerName
);
93
$this->baseName = (mb_strpos($this->baseName, $queueId) ===
false
?
94
$this->baseName.$queueId :
$this->baseName
);
95
$this->errorName = (mb_strpos($this->errorName, $queueId) ===
false
?
96
$this->errorName.$queueId :
$this->errorName
);
97
}
98
99
protected
function
getQueueOption
()
100
{
101
return
$this->
getOptionData
($this->baseName);
102
}
103
104
protected
function
saveQueueOption
(array $data)
105
{
106
Option::set(static::$moduleId, $this->baseName, serialize($data));
107
}
108
109
protected
function
deleteQueueOption
()
110
{
111
$queue = $this->
getQueue
();
112
$this->
setQueue
($queue);
113
$this->
deleteCurrentQueue
($queue);
114
Option::delete(static::$moduleId, [
"name"
=> $this->checkerName]);
115
Option::delete(static::$moduleId, [
"name"
=> $this->baseName]);
116
}
117
118
protected
function
deleteCurrentQueue
(array $queue): void
119
{
120
$queueId = current($queue);
121
$currentPos = array_search($queueId, $queue);
122
if
($currentPos !==
false
)
123
{
124
unset($queue[$currentPos]);
125
Option::set(static::$moduleId, $this->queueName, serialize($queue));
126
}
127
}
128
129
protected
function
isQueueEmpty
()
130
{
131
$queue = $this->
getOptionData
($this->queueName);
132
return
empty($queue);
133
}
134
135
protected
function
getOptionData
($optionName)
136
{
137
$option = Option::get(static::$moduleId, $optionName);
138
$option = ($option !==
""
? unserialize($option, [
'allowed_classes'
=>
false
]) : []);
139
return
(is_array($option) ? $option : []);
140
}
141
142
protected
function
deleteOption
($optionName)
143
{
144
Option::delete(static::$moduleId, [
"name"
=> $optionName]);
145
}
146
}
Bitrix\Iblock\Copy\Implement\Children\Element\SECTION_COPY_MODE
const SECTION_COPY_MODE
Definition
element.php:12
Bitrix\Iblock\Copy\Implement\Section
Definition
section.php:14
Bitrix\Iblock\Copy\Section
Definition
section.php:8
Bitrix\Main\Config\Option
Definition
option.php:15
Bitrix\Main\Copy\ContainerCollection
Definition
containercollection.php:12
Bitrix\Main\Copy\Container
Definition
container.php:12
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Update\Stepper
Definition
stepper.php:27
Bitrix\Main\Update\Stepper\writeToLog
writeToLog(\Exception $exception)
Definition
stepper.php:406
Bitrix\Photogallery\Copy\Implement\Children\Element
Definition
element.php:10
Bitrix\Photogallery\Copy\Integration\GroupStepper
Definition
groupstepper.php:14
Bitrix\Photogallery\Copy\Integration\GroupStepper\deleteQueueOption
deleteQueueOption()
Definition
groupstepper.php:109
Bitrix\Photogallery\Copy\Integration\GroupStepper\saveQueueOption
saveQueueOption(array $data)
Definition
groupstepper.php:104
Bitrix\Photogallery\Copy\Integration\GroupStepper\$errorName
$errorName
Definition
groupstepper.php:20
Bitrix\Photogallery\Copy\Integration\GroupStepper\$queueName
$queueName
Definition
groupstepper.php:17
Bitrix\Photogallery\Copy\Integration\GroupStepper\deleteCurrentQueue
deleteCurrentQueue(array $queue)
Definition
groupstepper.php:118
Bitrix\Photogallery\Copy\Integration\GroupStepper\setQueue
setQueue(array $queue)
Definition
groupstepper.php:88
Bitrix\Photogallery\Copy\Integration\GroupStepper\$checkerName
$checkerName
Definition
groupstepper.php:18
Bitrix\Photogallery\Copy\Integration\GroupStepper\deleteOption
deleteOption($optionName)
Definition
groupstepper.php:142
Bitrix\Photogallery\Copy\Integration\GroupStepper\getQueue
getQueue()
Definition
groupstepper.php:83
Bitrix\Photogallery\Copy\Integration\GroupStepper\isQueueEmpty
isQueueEmpty()
Definition
groupstepper.php:129
Bitrix\Photogallery\Copy\Integration\GroupStepper\getOptionData
getOptionData($optionName)
Definition
groupstepper.php:135
Bitrix\Photogallery\Copy\Integration\GroupStepper\execute
execute(array &$option)
Definition
groupstepper.php:31
Bitrix\Photogallery\Copy\Integration\GroupStepper\$moduleId
static $moduleId
Definition
groupstepper.php:15
Bitrix\Photogallery\Copy\Integration\GroupStepper\$baseName
$baseName
Definition
groupstepper.php:19
Bitrix\Photogallery\Copy\Integration\GroupStepper\getQueueOption
getQueueOption()
Definition
groupstepper.php:99
Bitrix\Photogallery\Copy\Integration
Definition
group.php:2
modules
photogallery
lib
copy
integration
groupstepper.php
Создано системой
1.10.0