forked from VitaliiSestrenskyi/bitrix24_migrations
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AddNewDealStages.php
64 lines (55 loc) · 1.74 KB
/
AddNewDealStages.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
<?php
class AddNewDealStages
{
protected static $arNewStatuses = array(
'Новая стадия 1',
'Новая стадия 2',
'Новая стадия 3',
);
public function up()
{
Bitrix\Main\Loader::includeModule('crm');
$arLastStatus = Bitrix\Crm\StatusTable::getList(array(
'order' => array(
'SORT' => 'DESC'
),
'filter' => array(
'ENTITY_ID' => 'DEAL_STAGE'
)
))->fetchAll();
$maxSort = 0;
$maxStatusId = 0;
foreach ($arLastStatus as $lastStatus) {
if (is_numeric($lastStatus['STATUS_ID']) && $maxStatusId < $lastStatus['STATUS_ID']) {
$maxStatusId = $lastStatus['STATUS_ID'];
}
if ($maxSort < $lastStatus['SORT']) {
$maxSort = $lastStatus['SORT'];
}
}
foreach (self::$arNewStatuses as $newStatus) {
$maxSort += 10;
$maxStatusId++;
Bitrix\Crm\StatusTable::add(array(
'ENTITY_ID' => 'DEAL_STAGE',
'NAME' => $newStatus,
'STATUS_ID' => (string)$maxStatusId,
'SORT' => $maxSort
));
}
}
public function down()
{
Bitrix\Main\Loader::includeModule('crm');
$statuses = Bitrix\Crm\StatusTable::getList(array(
'filter' => array(
'NAME' => self::$arNewStatuses
)
))->fetchAll();
global $DB;
foreach ($statuses as $status) {
$DB->query('DELETE FROM b_crm_status WHERE NAME = "' . $status['NAME']
. '" AND STATUS_ID = "' . $status['STATUS_ID'] . '"');
}
}
}