forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptsInProcess.php
More file actions
63 lines (56 loc) · 2.01 KB
/
ScriptsInProcess.php
File metadata and controls
63 lines (56 loc) · 2.01 KB
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
<?php
namespace ProcessMaker\Assets;
use DOMXPath;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\Script;
use ProcessMaker\Providers\WorkflowServiceProvider;
class ScriptsInProcess
{
public $type = Script::class;
public $owner = Process::class;
/**
* Get scripts used in a process
*
* @param Process $process
* @param array $scripts
*
* @return array
*/
public function referencesToExport(Process $process, array $scripts = [])
{
// Scripts used in BPMN
$xpath = new DOMXPath($process->getDefinitions());
$xpath->registerNamespace('pm', WorkflowServiceProvider::PROCESS_MAKER_NS);
$xpath->registerNamespace('bpmn', 'http://www.omg.org/spec/BPMN/20100524/MODEL');
// Used in scriptRef
$nodes = $xpath->query("//*[@pm:scriptRef!='']");
foreach ($nodes as $node) {
$scripts[] = [Script::class, $node->getAttributeNS(WorkflowServiceProvider::PROCESS_MAKER_NS, 'scriptRef')];
}
return $scripts;
}
/**
* Update references used in an imported process
*
* @param Process $process
* @param array $references
*
* @return void
*/
public function updateReferences(Process $process, array $references = [])
{
$definitions = $process->getDefinitions();
$xpath = new DOMXPath($definitions);
$xpath->registerNamespace('pm', WorkflowServiceProvider::PROCESS_MAKER_NS);
$xpath->registerNamespace('bpmn', 'http://www.omg.org/spec/BPMN/20100524/MODEL');
// Used in scriptRef
$nodes = $xpath->query("//*[@pm:scriptRef!='']");
foreach ($nodes as $node) {
$oldRef = $node->getAttributeNS(WorkflowServiceProvider::PROCESS_MAKER_NS, 'scriptRef');
$newRef = $references[Script::class][$oldRef]->getKey();
$node->setAttributeNS(WorkflowServiceProvider::PROCESS_MAKER_NS, 'scriptRef', $newRef);
}
$process->bpmn = $definitions->saveXML();
$process->save();
}
}