-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimportBP.php
95 lines (81 loc) · 2.66 KB
/
importBP.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
<?php
class tasks extends \WS\ReduceMigrations\Scenario\ScriptScenario {
private $arBPFields = [
'DOCUMENT_TYPE' => [
'crm',
'CCrmDocumentLead',
'LEAD',
],
'AUTO_EXECUTE' => 0,
'NAME' => 'TEST',
'CODE' => 'TEST',
];
/**
* Write action by apply scenario. Use method `setData` for save need rollback data
**/
public function commit() {
self::deleteTemplate();
$pathBPElement = $_SERVER['DOCUMENT_ROOT'].'/local/static/dataForMigration/bp-35.bpt';
$id = $this->importBP($pathBPElement);
}
/**
* Write action by rollback scenario. Use method `getData` for getting commit saved data
**/
public function rollback() {
//
}
private function deleteTemplate(){
if (\Bitrix\Main\Loader::includeModule('bizproc')){
$r = \Bitrix\Bizproc\WorkflowTemplateTable::getList([
'select' => ['ID'],
'filter' => [
'=SYSTEM_CODE' => $this->arBPFields['CODE'],
'=NAME' => 'TEST',
'=MODULE_ID' => 'crm',
'=ENTITY' => 'CCrmDocumentLead',
'=DOCUMENT_TYPE' => 'LEAD',
'=DOCUMENT_STATUS' => '',
'=ACTIVE' => 'Y'
]
]);
if ($bpt = $r->fetch()){
\CBPWorkflowTemplateLoader::Delete($bpt['ID']);
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
private function importBP($path){
CModule::IncludeModule('bizproc');
CModule::IncludeModule('crm');
// Get BP id by the CODE
$result = \CBPWorkflowTemplateLoader::GetList(
[],
[
'NAME' => 'ADMIN_TASKS',
'CODE' => $this->arBPFields['CODE'],
'MODULE_ID' => 'crm'
]
);
$id = 0;
if ($arFields = $result->GetNext()) {
$id = $arFields['ID'];
}
if($id === 0){
//read file to a variable
$f = fopen($path, 'rb');
$datum = fread($f, filesize($path));
fclose($f);
//Update BP if id>0, otherwise add BP
\CBPWorkflowTemplateLoader::ImportTemplate(
(int)$id,
$this->arBPFields['DOCUMENT_TYPE'],
$this->arBPFields['AUTO_EXECUTE'],
$this->arBPFields['NAME'],
'',
$datum,
$this->arBPFields['CODE']
);
return $arFields['ID'];
}
}
}