1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
groupstepper.php
См. документацию.
1<?php
2namespace Bitrix\Blog\Copy\Integration;
3
4use Bitrix\Blog\Copy\BlogPostManager;
5use Bitrix\Main\Config\Option;
6use Bitrix\Main\Loader;
7use Bitrix\Main\Update\Stepper;
8
9class GroupStepper extends Stepper
10{
11 protected static $moduleId = "blog";
12
13 protected $queueName = "BlogGroupQueue";
14 protected $checkerName = "BlogGroupChecker_";
15 protected $baseName = "BlogGroupStepper_";
16 protected $errorName = "BlogGroupError_";
17
24 public function execute(array &$option)
25 {
26 if (!Loader::includeModule(self::$moduleId))
27 {
28 return false;
29 }
30
31 try
32 {
33 $queue = $this->getQueue();
34 $this->setQueue($queue);
35
36 $queueOption = $this->getQueueOption();
37 if (empty($queueOption))
38 {
39 $this->deleteQueueOption();
40 return !$this->isQueueEmpty();
41 }
42
43 $executiveUserId = ($queueOption["executiveUserId"] ?? 0);
44 $groupId = ($queueOption["groupId"] ?? 0);
45 $copiedGroupId = ($queueOption["copiedGroupId"] ?? 0);
46 $errorOffset = ($queueOption["errorOffset"] ?? 0);
47
48 $limit = 10;
49 $offset = $this->getOffset($copiedGroupId) + $errorOffset;
50
51 $blogPostIds = $this->getBlogPostIdsByGroupId($groupId);
52 $count = count($blogPostIds);
53 $blogPostIds = array_slice($blogPostIds, $offset, $limit);
54 $features = ($queueOption["features"] ?: []);
55
56 if ($blogPostIds)
57 {
58 $option["count"] = $count;
59
60 $copyManager = new BlogPostManager($executiveUserId, $blogPostIds);
61 $copyManager->setChangedRights([
62 "SG" => [$groupId => $copiedGroupId]
63 ]);
64
65 $featuresToBlogPost = [];
66 if (in_array("comments", $features))
67 {
68 $featuresToBlogPost[] = "comments";
69 }
70 if (in_array("voteResult", $features))
71 {
72 $featuresToBlogPost[] = "voteResult";
73 }
74
75 $copyManager->setFeatures($featuresToBlogPost);
76
77 $result = $copyManager->startCopy();
78 if (!$result->isSuccess())
79 {
80 $queueOption["errorOffset"] += $this->getErrorOffset($copyManager);
81 $this->saveQueueOption($queueOption);
82 }
83
84 $option["steps"] = $offset;
85
86 return true;
87 }
88 else
89 {
90 $this->deleteQueueOption();
91 return !$this->isQueueEmpty();
92 }
93 }
94 catch (\Exception $exception)
95 {
96 $this->writeToLog($exception);
97 $this->deleteQueueOption();
98 return false;
99 }
100 }
101
102 private function getBlogPostIdsByGroupId($groupId)
103 {
104 $blogPostIds = [];
105
106 $queryObject = \CBlogPost::getList([], ["SOCNET_GROUP_ID" => $groupId]);
107 while ($blogPost = $queryObject->fetch())
108 {
109 $blogPostIds[] = $blogPost["ID"];
110 }
111
112 return $blogPostIds;
113 }
114
115 private function getOffset(int $copiedGroupId): int
116 {
117 $blogPostIds = $this->getBlogPostIdsByGroupId($copiedGroupId);
118 return count($blogPostIds);
119 }
120
121 private function getErrorOffset(BlogPostManager $copyManager): int
122 {
123 $numberIds = count($copyManager->getMapIdsCopiedPosts());
124 $numberSuccessIds = count(array_filter($copyManager->getMapIdsCopiedPosts()));
125 return $numberIds - $numberSuccessIds;
126 }
127
128 protected function getQueue(): array
129 {
130 return $this->getOptionData($this->queueName);
131 }
132
133 protected function setQueue(array $queue): void
134 {
135 $queueId = (string) current($queue);
136 $this->checkerName = (mb_strpos($this->checkerName, $queueId) === false ?
137 $this->checkerName.$queueId : $this->checkerName);
138 $this->baseName = (mb_strpos($this->baseName, $queueId) === false ?
139 $this->baseName.$queueId : $this->baseName);
140 $this->errorName = (mb_strpos($this->errorName, $queueId) === false ?
141 $this->errorName.$queueId : $this->errorName);
142 }
143
144 protected function getQueueOption()
145 {
146 return $this->getOptionData($this->baseName);
147 }
148
149 protected function saveQueueOption(array $data)
150 {
151 Option::set(static::$moduleId, $this->baseName, serialize($data));
152 }
153
154 protected function deleteQueueOption()
155 {
156 $queue = $this->getQueue();
157 $this->setQueue($queue);
158 $this->deleteCurrentQueue($queue);
159 Option::delete(static::$moduleId, ["name" => $this->checkerName]);
160 Option::delete(static::$moduleId, ["name" => $this->baseName]);
161 }
162
163 protected function deleteCurrentQueue(array $queue): void
164 {
165 $queueId = current($queue);
166 $currentPos = array_search($queueId, $queue);
167 if ($currentPos !== false)
168 {
169 unset($queue[$currentPos]);
170 Option::set(static::$moduleId, $this->queueName, serialize($queue));
171 }
172 }
173
174 protected function isQueueEmpty()
175 {
176 $queue = $this->getOptionData($this->queueName);
177 return empty($queue);
178 }
179
180 protected function getOptionData($optionName)
181 {
182 $option = Option::get(static::$moduleId, $optionName);
183 $option = ($option !== "" ? unserialize($option, ['allowed_classes' => false]) : []);
184 return (is_array($option) ? $option : []);
185 }
186
187 protected function deleteOption($optionName)
188 {
189 Option::delete(static::$moduleId, ["name" => $optionName]);
190 }
191}
$count
Определения admin_tab.php:4
Определения blogpostmanager.php:12
deleteCurrentQueue(array $queue)
Определения groupstepper.php:163
execute(array &$option)
Определения groupstepper.php:24
writeToLog(\Exception $exception)
Определения stepper.php:404
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$option
Определения options.php:1711
$optionName
Определения options.php:1735