Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
DeleteAction.php
1<?php
2
4
8use CApplicationException;
9use CIBlockProperty;
10use CIBlockRights;
11use CMain;
12
16final class DeleteAction extends Action
17{
25 public function run(int $id): bool
26 {
27 global $APPLICATION;
28
33 $fields = CIBlockProperty::GetByID($id)->Fetch();
34 if (empty($fields))
35 {
36 $this->errorCollection->setError(
37 new Error(Loc::getMessage('IBLOCK_CONTROLLER_PROPERTY_ACTION_DELETE_ERROR_NOT_FOUND'))
38 );
39
40 return false;
41 }
42
43 $iblockId = (int)$fields['IBLOCK_ID'];
44 if (!$this->checkWritePermissions($iblockId))
45 {
46 $this->errorCollection->setError(
47 new Error(Loc::getMessage('IBLOCK_CONTROLLER_PROPERTY_ACTION_DELETE_ERROR_ACCESS_DENIED'))
48 );
49
50 return false;
51 }
52
53 $result = CIBlockProperty::Delete($id) !== false;
54 if (!$result)
55 {
56 $ex = $APPLICATION->GetException();
57 if ($ex instanceof CApplicationException)
58 {
59 $this->errorCollection->setError(
60 new Error($ex->GetString())
61 );
62 }
63 }
64
65 return $result;
66 }
67
75 private function checkWritePermissions(int $iblockId): bool
76 {
77 return CIBlockRights::UserHasRightTo($iblockId, $iblockId, 'iblock_edit');
78 }
79}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29