28 public static function register($codes, array $params = [])
30 if (!is_array($codes))
35 $res = UpdateBlock::getList([
43 while ($row = $res->fetch())
45 UpdateBlock::update($row[
'ID'], [
49 $codes = array_diff($codes, [$row[
'CODE']]);
54 foreach ($codes as $code)
64 \Bitrix\Main\Update\Stepper::bindClass(
65 'Bitrix\Landing\Update\Block',
'landing', 600
102 protected static function prepareClassesToSet($classes, array $addClasses = [], array $removeClasses = [])
104 if (is_array($classes) && isset($classes[
'classList']))
106 $classes = $classes[
'classList'];
108 if (!is_array($classes))
110 $classes = [$classes];
113 $classesUnique = array_unique($classes);
115 if (count($classesUnique) === 1)
119 'classList' => $classesUnique[0],
129 $counts = array_count_values($classes);
131 $mainClass = key($counts);
132 foreach ($classes as $pos => $class)
134 if ($class !== $mainClass)
137 'classList' => $class,
138 'suffix' =>
'@' . $pos,
142 $result = array_merge(
145 'classList' => $mainClass,
154 foreach ($result as $pos => $class)
156 if ($addClasses || $removeClasses)
158 $classList = explode(
' ', $class[
'classList']);
162 $classList = array_merge($classList, $addClasses);
166 $classList = array_diff($classList, $removeClasses);
168 $result[$pos][
'classList'] = implode(
' ', array_unique($classList));
183 public static function executeStep(array $filter, &$count = 0, $limit = 0, array $params = [])
189 $res = BlockTable::getList([
199 while ($row = $res->fetch())
201 $lastId = $row[
'ID'];
206 $block->setAccess(BlockCore::ACCESS_X);
207 $export = $block->export([
208 'clear_form' =>
false
212 $newContent = BlockCore::getContentFromRepository(
215 $block->saveContent($newContent);
217 if ($export[
'cards'])
224 if ($export[
'style'])
226 foreach ($export[
'style'] as $selector => $classes)
229 if (isset($params[$selector][
'new_class']))
231 if (is_array($params[$selector][
'new_class']))
233 if (count($params[$selector][
'new_class']) > 1)
235 $addClasses = $params[$selector][
'new_class'];
239 $addClasses = explode(
' ', trim($params[$selector][
'new_class'][0]));
244 $addClasses = explode(
' ', trim($params[$selector][
'new_class']));
249 if (isset($params[$selector][
'remove_class']))
251 if (is_array($params[$selector][
'remove_class']))
253 if (count($params[$selector][
'remove_class']) > 1)
255 $removeClasses = $params[$selector][
'remove_class'];
259 $removeClasses = explode(
' ', trim($params[$selector][
'remove_class'][0]));
264 $removeClasses = explode(
' ', trim($params[$selector][
'remove_class']));
269 if ($selector ==
'#wrapper')
271 $selector =
'#' . $block->getAnchor($block->getId());
274 foreach (self::prepareClassesToSet($classes, $addClasses, $removeClasses) as $class)
276 $block->setClasses(array(
277 $selector . $class[
'suffix'] => array(
278 'classList' => [$class[
'classList']]
285 if ($export[
'nodes'])
287 foreach ($export[
'nodes'] as $selector => $node)
289 if (isset($params[$selector][
'update_video_to_lazyload']))
291 $export[
'nodes'][$selector] = self::updateVideoToLazyload($node);
307 if ($export[
'attrs'])
309 if (isset($export[
'attrs'][
'#wrapper']))
311 $wrapperCode =
'#' . $block->getAnchor($block->getId());
312 $export[
'attrs'][$wrapperCode] = $export[
'attrs'][
'#wrapper'];
313 unset($export[
'attrs'][
'#wrapper']);
315 $block->setAttributes(
339 $res = UpdateBlock::getList([
341 'ID',
'CODE',
'LAST_BLOCK_ID',
'PARAMS'
348 if (!($rowUpdate = $res->fetch()))
354 $res = BlockTable::getList([
361 '=CODE' => $rowUpdate[
'CODE'],
367 $row = $res->fetch();
368 if(!$row || (
int) $row[
'CNT'] === 0)
373 return $this->
execute($result);
375 $result[
'count'] = $row[
'CNT'];
378 $res = BlockTable::getList([
385 '<=ID' => $rowUpdate[
'LAST_BLOCK_ID'],
386 '=CODE' => $rowUpdate[
'CODE'],
391 if ($row = $res->fetch())
393 $result[
'steps'] = $row[
'CNT'];
397 $lastId = $this::executeStep([
398 '>ID' => $rowUpdate[
'LAST_BLOCK_ID'],
399 '=CODE' => $rowUpdate[
'CODE'],
403 $this::STEPPER_COUNT,
414 UpdateBlock::update($rowUpdate[
'ID'], [
415 'LAST_BLOCK_ID' => $lastId
421 UpdateBlock::delete($rowUpdate[
'ID']);