1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
removeactionsitem.php
См. документацию.
1<?php
2
3namespace Bitrix\Iblock\Grid\Panel\UI\Actions\Item;
4
5use Bitrix\Iblock\Grid\Access\IblockRightsChecker;
6use Bitrix\Iblock\Grid\ActionType;
7use Bitrix\Iblock\Grid\Panel\UI\Actions\Helpers\ItemFinder;
8use Bitrix\Main\Application;
9use Bitrix\Main\DB\SqlQueryException;
10use Bitrix\Main\Error;
11use Bitrix\Main\Filter\Filter;
12use Bitrix\Main\HttpRequest;
13use Bitrix\Main\Localization\Loc;
14use Bitrix\Main\Result;
15use CIBlockElement;
16use CIBlockSection;
17use CMain;
18
20{
21 use ItemFinder;
22
23 private int $iblockId;
24 private IblockRightsChecker $rights;
25 private string $listMode;
26
27 public static function getId(): string
28 {
29 return ActionType::DELETE;
30 }
31
32 public function __construct(int $iblockId, IblockRightsChecker $rights, string $listMode)
33 {
34 $this->iblockId = $iblockId;
35 $this->rights = $rights;
36 $this->listMode = $listMode;
37 }
38
39 final protected function getIblockId(): int
40 {
41 return $this->iblockId;
42 }
43
44 final protected function getListMode(): string
45 {
46 return $this->listMode;
47 }
48
49 public function processRequest(HttpRequest $request, bool $isSelectedAllRows, ?Filter $filter = null): ?Result
50 {
51 $result = new Result();
52
53 [$elementIds, $sectionIds] = $this->prepareItemIds($request, $isSelectedAllRows, $filter);
54
55 if ($elementIds)
56 {
57 $result->addErrors(
58 $this->removeElements($elementIds)->getErrors()
59 );
60 }
61
62 if ($sectionIds)
63 {
64 $result->addErrors(
65 $this->removeSections($sectionIds)->getErrors()
66 );
67 }
68
69 return $result;
70 }
71
72 private function removeElements(array $ids): Result
73 {
77 global $APPLICATION;
78
79 $result = new Result();
80
81 $conn = Application::getConnection();
82
83 foreach ($ids as $id)
84 {
85 if (!$this->rights->canDeleteElement($id))
86 {
87 $message = Loc::getMessage('IBLOCK_GRID_PANEL_UI_REMOVE_ACTIONS_ITEM_ACCESS_DENIED', [
88 '#ID#' => $id,
89 ]);
90 $result->addError(
91 new Error($message)
92 );
93
94 continue;
95 }
96
97 $conn->startTransaction();
98 $error = '';
99 try
100 {
101 if (!CIBlockElement::Delete($id))
102 {
103 $ex = $APPLICATION->GetException();
104 if ($ex)
105 {
106 $error = $ex->GetString();
107 }
108 else
109 {
110 $error = Loc::getMessage(
111 'IBLOCK_GRID_PANEL_UI_ACTIONS_ELEMENT_DELETE_INTERNAL_ERROR',
112 [
113 '#ID#' => $id,
114 ]
115 );
116 }
117 unset($ex);
118 }
119 }
120 catch (SqlQueryException)
121 {
122 $error = Loc::getMessage(
123 'IBLOCK_GRID_PANEL_UI_ACTIONS_ELEMENT_DELETE_INTERNAL_ERROR',
124 [
125 '#ID#' => $id,
126 ]
127 );
128 }
129 if ($error === '')
130 {
131 $conn->commitTransaction();
132 }
133 else
134 {
135 $conn->rollbackTransaction();
136 $result->addError(new Error($error));
137 }
138 }
139
140 return $result;
141 }
142
143 private function removeSections(array $ids): Result
144 {
148 global $APPLICATION;
149
150 $result = new Result();
151
152 $conn = Application::getConnection();
153
154 foreach ($ids as $id)
155 {
156 if (!$this->rights->canDeleteSection($id))
157 {
158 $message = Loc::getMessage('IBLOCK_GRID_PANEL_UI_REMOVE_ACTIONS_ITEM_ACCESS_DENIED', [
159 '#ID#' => $id,
160 ]);
161 $result->addError(
162 new Error($message)
163 );
164
165 continue;
166 }
167
168 $conn->startTransaction();
169 $error = '';
170 try
171 {
172 if (!CIBlockSection::Delete($id))
173 {
174 $ex = $APPLICATION->GetException();
175 if ($ex)
176 {
177 $error = $ex->GetString();
178 }
179 else
180 {
181 $error = Loc::getMessage(
182 'IBLOCK_GRID_PANEL_UI_ACTIONS_SECTION_DELETE_INTERNAL_ERROR',
183 [
184 '#ID#' => $id,
185 ]
186 );
187 }
188 unset($ex);
189 }
190 }
191 catch (SqlQueryException)
192 {
193 $error = Loc::getMessage(
194 'IBLOCK_GRID_PANEL_UI_ACTIONS_SECTION_DELETE_INTERNAL_ERROR',
195 [
196 '#ID#' => $id,
197 ]
198 );
199 }
200 if ($error === '')
201 {
202 $conn->commitTransaction();
203 }
204 else
205 {
206 $conn->rollbackTransaction();
207 $result->addError(new Error($error));
208 }
209 }
210
211 return $result;
212 }
213}
global $APPLICATION
Определения include.php:80
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения catalog_reindex.php:36
const DELETE
Определения actiontype.php:8
processRequest(HttpRequest $request, bool $isSelectedAllRows, ?Filter $filter=null)
Определения removeactionsitem.php:49
__construct(int $iblockId, IblockRightsChecker $rights, string $listMode)
Определения removeactionsitem.php:32
Определения error.php:15
</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
$iblockId
Определения iblock_catalog_edit.php:30
$filter
Определения iblock_catalog_list.php:54
getErrors()
Определения errorableimplementation.php:34
trait Error
Определения error.php:11
$message
Определения payment.php:8
$error
Определения subscription_card_product.php:20