-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchangeSourceId.php
65 lines (65 loc) · 2.22 KB
/
changeSourceId.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
<?php
class ChnageSourceId extends AbstractMigration
{
public function up()
{
if(!\Bitrix\Main\Loader::includeModule('crm') || !\Bitrix\Main\Loader::includeModule('main'))
{
return;
}
$rs = \CCrmStatus::GetList(
[],
[
'ENTITY_ID'=>'SOURCE',
]
);
$obCCrmStatus = new \CCrmStatus("SOURCE");
while ($res = $rs->fetch())
{
preg_match("/^[A-Za-z]+/", $res['STATUS_ID'], $matches);
if(strstr($res['STATUS_ID'], '|') == false && empty($matches))
{
$arParams = [
"replace_space"=>"_",
"replace_other"=>"_",
"change_case"=>"U",
];
$translit = \Cutil::translit($res['NAME'],"ru", $arParams);
if(strlen($translit) > 0)
{
$resultId = $obCCrmStatus->Update(
$res['ID'],
[
'STATUS_ID'=>$translit
],
[
'ENABLE_STATUS_ID'=>(int)$res['ID']
]
);
if($resultId)
{
$rsDealTable = \Bitrix\Crm\DealTable::getList([
'filter'=>['SOURCE_ID'=>$res['STATUS_ID']],
'select'=>['ID']
]);
$idsUpdate = [];
while ($resDealTable = $rsDealTable->fetch())
{
$idsUpdate[] = $resDealTable['ID'];
}
if(count($idsUpdate)>0)
{
$sql = "UPDATE `b_crm_deal` SET SOURCE_ID='".$translit."' WHERE ID IN (".implode(",",$idsUpdate).");";
$connection = \Bitrix\Main\Application::getInstance()->getConnection();
$connection->query($sql);
}
}
}
}
}
}
public function down()
{
//
}
}