Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ReplaceLanding.php
1<?php
2
4
10
15{
16 protected const JS_COMMAND = 'replaceLanding';
17
18 public function execute(bool $undo = true): bool
19 {
20 $landing = Landing::createInstance($this->params['lid']);
21 if ($landing->exist())
22 {
23 foreach ($landing->getBlocks() as $block)
24 {
25 $accessBefore = $block->getAccess();
26 $block->setAccess(Block::ACCESS_X);
27
28 $landing->markDeletedBlock($block->getId(), true);
29
30 $block->setAccess($accessBefore);
31 }
32
33 // return blocks
34 $blocksToUndelete = $undo ? $this->params['blocksBefore'] : $this->params['blocksAfter'];
35 foreach ($blocksToUndelete as $blockId)
36 {
37 $block = new Block($blockId);
38 $accessBefore = $block->getAccess();
39 $block->setAccess(Block::ACCESS_X);
40 $landing->addBlockToCollection($block);
41
42 $landing->markDeletedBlock($blockId, false);
43
44 $block->setAccess($accessBefore);
45 }
46
47 // return additional fields
48 $fields = $undo ? $this->params['additionalFieldsBefore'] : $this->params['additionalFieldsAfter'];
49 Landing::saveAdditionalFields($this->params['lid'], $fields);
50
51 if (
53 && $landing->getError()->isEmpty()
54 )
55 {
56 $landing->publication();
57 }
58
59 return true;
60 }
61
62 return false;
63 }
64
65 public static function enrichParams(array $params): array
66 {
67 return [
68 'lid' => (int)$params['lid'],
69 'template' => $params['template'] ?? '',
70 'blocksBefore' => $params['blocksBefore'] ?? [],
71 'blocksAfter' => $params['blocksAfter'] ?? [],
72 'additionalFieldsBefore' => $params['additionalFieldsBefore'] ?? [],
73 'additionalFieldsAfter' => $params['additionalFieldsAfter'] ?? [],
74 ];
75 }
76
77 public function delete(): bool
78 {
79 if (!isset($this->params['blocksBefore']))
80 {
81 return false;
82 }
83
84 $blocks = $this->params['blocksBefore'];
85
86 if (!empty($blocks))
87 {
88 $query = BlockTable::query()
89 ->setSelect(['ID', 'ACCESS'])
90 ->whereIn('ID', $blocks)
91 ->where('DELETED', '=', 'Y')
92 ->exec()
93 ;
94 while ($block = $query->fetch())
95 {
96 if ($block['ACCESS'] === Block::ACCESS_X)
97 {
98 $blockId = (int)$block['ID'];
99 BlockTable::delete($blockId);
100 File::deleteFromBlock($blockId);
101 }
102 }
103 }
104
105 return parent::delete();
106 }
107}
static deleteFromBlock($blockId, $fileId=array())
Definition file.php:363
static createInstance($id, array $params=array())
Definition landing.php:534
static saveAdditionalFields($id, array $data)
Definition landing.php:782
static isAutoPublicationEnabled()
Definition manager.php:437