-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddDeleteProps.php
98 lines (94 loc) · 2.92 KB
/
addDeleteProps.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
class ChnageSourceId extends AbstractMigration
{
public function up()
{
$this->createProps();
}
public function down()
{
$this->deleteProps();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
///
///
///
public function createProps()
{
if( !\Bitrix\Main\Loader::includeModule('lists') ||
!\Bitrix\Main\Loader::includeModule('iblock')
)
{
return;
}
$res = \Bitrix\Iblock\IblockTable::getList([
'filter'=>['CODE'=>"TEST"],
'select'=>['ID']
])->fetch();
$iblockId = $res['ID'];
if($iblockId)
{
$obList = new \CList( $iblockId );
$allListsFields = [
[
"SORT" => 150,
"NAME" => 'test',
"IS_REQUIRED" => "N",
"MULTIPLE" => "Y",
"CODE" => "TEST",
"TYPE" => "S",
"DEFAULT_VALUE" => "",
"USER_TYPE"=>"bcrmstatusiblockprops",
"USER_TYPE_SETTINGS" => [
'ENTITY_ID'=>'SOURCE'
],
"SETTINGS" => [
"SHOW_ADD_FORM" => "Y",
"SHOW_EDIT_FORM" => "Y",
"ADD_READ_ONLY_FIELD" => "N",
"EDIT_READ_ONLY_FIELD" => "N",
"SHOW_FIELD_PREVIEW" => "N",
],
"LIST" =>[],
],
];
foreach ($allListsFields as $allListsField)
{
$obList->AddField($allListsField);
}
$obList->Save();
global $CACHE_MANAGER;
$CACHE_MANAGER->ClearByTag("lists_list_".$iblockId);
}
}
public function deleteProps()
{
if(!\Bitrix\Main\Loader::includeModule('lists') || !\Bitrix\Main\Loader::includeModule('iblock'))
{
return;
}
$res = \Bitrix\Iblock\IblockTable::getList([
'filter'=>['CODE'=>"TEST"],
'select'=>['ID']
])->fetch();
$iblockId = $res['ID'];
if($iblockId)
{
$obList = new \CList( $iblockId );
$resIblockPropertyTable = \Bitrix\Iblock\PropertyTable::getList([
'filter'=>[
'=IBLOCK_ID'=>$iblockId,
'=CODE'=>'TEST',
],
'select'=>['ID']
])->fetch();
if($resIblockPropertyTable)
{
$obList->DeleteField("PROPERTY_".$resIblockPropertyTable['ID']);
$obList->Save();
global $CACHE_MANAGER;
$CACHE_MANAGER->ClearByTag("lists_list_".$iblockId);
}
}
}
}