Skip to content

Commit 930f4b7

Browse files
committed
Merge branch 'develop' into bugfix/FOUR-32329
2 parents 052f28c + 8b1e9ef commit 930f4b7

128 files changed

Lines changed: 4171 additions & 2163 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
namespace ProcessMaker\Assets;
4+
5+
use DOMXPath;
6+
use ProcessMaker\Models\Process;
7+
use ProcessMaker\Providers\WorkflowServiceProvider;
8+
9+
class DataSourcesInProcess
10+
{
11+
public $type = 'ProcessMaker\Packages\Connectors\DataSources\Models\DataSource';
12+
13+
public $owner = Process::class;
14+
15+
/**
16+
* Get the data sources used in a process
17+
*
18+
* @param Process $process
19+
* @param array $dataSources
20+
*
21+
* @return array
22+
*/
23+
public function referencesToExport(Process $process, array $dataSources = [])
24+
{
25+
// Data Sources used in BPMN Service Tasks
26+
$xpath = new DOMXPath($process->getDefinitions());
27+
$xpath->registerNamespace('pm', WorkflowServiceProvider::PROCESS_MAKER_NS);
28+
29+
// Find all nodes with pm:config
30+
$nodes = $xpath->query("//*[@pm:config!='']");
31+
foreach ($nodes as $node) {
32+
$configString = $node->getAttributeNS(WorkflowServiceProvider::PROCESS_MAKER_NS, 'config');
33+
$config = json_decode($configString, true);
34+
if (isset($config['dataSource']) && is_numeric($config['dataSource'])) {
35+
$dataSources[] = [$this->type, (int) $config['dataSource']];
36+
}
37+
}
38+
39+
return $dataSources;
40+
}
41+
42+
/**
43+
* Update references used in an imported process
44+
*
45+
* @param Process $process
46+
* @param array $references
47+
*
48+
* @return void
49+
*/
50+
public function updateReferences(Process $process, array $references = [])
51+
{
52+
$definitions = $process->getDefinitions();
53+
$xpath = new DOMXPath($definitions);
54+
$xpath->registerNamespace('pm', WorkflowServiceProvider::PROCESS_MAKER_NS);
55+
56+
$nodes = $xpath->query("//*[@pm:config!='']");
57+
foreach ($nodes as $node) {
58+
$configString = $node->getAttributeNS(WorkflowServiceProvider::PROCESS_MAKER_NS, 'config');
59+
$config = json_decode($configString, true);
60+
if (isset($config['dataSource']) && is_numeric($config['dataSource'])) {
61+
$oldRef = $config['dataSource'];
62+
if (isset($references[$this->type][$oldRef])) {
63+
$newRef = $references[$this->type][$oldRef]->getKey();
64+
$config['dataSource'] = $newRef;
65+
$node->setAttributeNS(WorkflowServiceProvider::PROCESS_MAKER_NS, 'config', json_encode($config));
66+
}
67+
}
68+
}
69+
$process->bpmn = $definitions->saveXML();
70+
$process->save();
71+
}
72+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
3+
namespace ProcessMaker\Assets;
4+
5+
use ProcessMaker\Managers\ExportManager;
6+
use ProcessMaker\Models\Screen;
7+
use Illuminate\Support\Arr;
8+
9+
class DataSourcesInScreen
10+
{
11+
public $type = 'ProcessMaker\Packages\Connectors\DataSources\Models\DataSource';
12+
13+
public $owner = Screen::class;
14+
15+
/**
16+
* Get the data sources (ex. watchers) used in a screen
17+
*
18+
* @param Screen $screen
19+
* @param array $dataSources
20+
*
21+
* @return array
22+
*/
23+
public function referencesToExport(Screen $screen, array $dataSources = [])
24+
{
25+
$watchers = $screen->watchers;
26+
if (is_array($watchers)) {
27+
$this->findInArray($watchers, function ($item) use (&$dataSources) {
28+
if (is_array($item)) {
29+
$scriptId = (string) ($item['script_id'] ?? '');
30+
$id = (string) ($item['script']['id'] ?? '');
31+
if (str_starts_with($scriptId, 'data_source-') || str_starts_with($id, 'data_source-')) {
32+
$numericId = str_replace('data_source-', '', str_starts_with($scriptId, 'data_source-') ? $scriptId : $id);
33+
if (is_numeric($numericId)) {
34+
$dataSources[] = [$this->type, (int) $numericId];
35+
}
36+
}
37+
}
38+
});
39+
}
40+
41+
$config = $screen->versionFor(null)->config;
42+
if (is_array($config)) {
43+
$this->findInArray($config, function ($item) use (&$dataSources) {
44+
if (is_array($item) && isset($item['component']) && $item['component'] === 'FormSelectList' && !empty($item['config']['options']['selectedDataSource'])) {
45+
$dataSources[] = [$this->type, (int) $item['config']['options']['selectedDataSource']];
46+
}
47+
});
48+
}
49+
50+
return $dataSources;
51+
}
52+
53+
/**
54+
* Update references used in an imported screen
55+
*
56+
* @param Screen $screen
57+
* @param array $references
58+
* @param ExportManager $exportManager
59+
*
60+
* @return void
61+
*/
62+
public function updateReferences(Screen $screen, array $references, ExportManager $exportManager)
63+
{
64+
$watches = $screen->watchers;
65+
if (is_array($watches)) {
66+
foreach ($watches as &$watcher) {
67+
$id = (string) ($watcher['script']['id'] ?? '');
68+
if (str_starts_with($id, 'data_source-')) {
69+
$oldRef = str_replace('data_source-', '', $id);
70+
if (isset($references[$this->type][$oldRef])) {
71+
$newRef = $references[$this->type][$oldRef]->getKey();
72+
} else {
73+
$newRef = null;
74+
$exportManager->addLogMessage(
75+
'DataSourcesInScreen:references',
76+
__(
77+
'Imported file does not contain the data source #:dataSource assigned to a watcher',
78+
['dataSource' => $oldRef]
79+
),
80+
false,
81+
__("Missing watcher's data source")
82+
);
83+
}
84+
if ($newRef) {
85+
$watcher['script_id'] = $newRef;
86+
$watcher['script']['id'] = "data_source-$newRef";
87+
$watcher['script']['title'] = $references[$this->type][$oldRef]->name;
88+
}
89+
}
90+
}
91+
}
92+
$screen->watchers = $watches;
93+
94+
$config = $screen->config;
95+
if (is_array($config)) {
96+
$this->findInArray($config, function ($item, $keyDotNotation) use ($references, &$config) {
97+
if (is_array($item) && isset($item['component']) && $item['component'] === 'FormSelectList' && !empty($item['config']['options']['selectedDataSource'])) {
98+
$oldRef = $item['config']['options']['selectedDataSource'];
99+
if (isset($references[$this->type][$oldRef])) {
100+
$newRef = $references[$this->type][$oldRef]->getKey();
101+
Arr::set($config, "$keyDotNotation.config.options.selectedDataSource", $newRef);
102+
}
103+
}
104+
});
105+
$screen->config = $config;
106+
}
107+
108+
$screen->save();
109+
}
110+
111+
/**
112+
* Find recursively in an array
113+
*
114+
* @param array $array
115+
* @param callable $callback
116+
* @param array $path
117+
*
118+
* @return void
119+
*/
120+
private function findInArray(array $array, callable $callback, array $path = [])
121+
{
122+
call_user_func($callback, $array, implode('.', $path));
123+
foreach ($array as $key => $item) {
124+
if (is_array($item)) {
125+
$this->findInArray($item, $callback, array_merge($path, [$key]));
126+
} else {
127+
call_user_func($callback, $item, implode('.', array_merge($path, [$key])));
128+
}
129+
}
130+
}
131+
}

‎ProcessMaker/Assets/ScriptsInProcess.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public function referencesToExport(Process $process, array $scripts = [])
3030
// Used in scriptRef
3131
$nodes = $xpath->query("//*[@pm:scriptRef!='']");
3232
foreach ($nodes as $node) {
33-
$scripts[] = [Script::class, $node->getAttributeNS(WorkflowServiceProvider::PROCESS_MAKER_NS, 'scriptRef')];
33+
$scriptId = $node->getAttributeNS(WorkflowServiceProvider::PROCESS_MAKER_NS, 'scriptRef');
34+
if (!str_starts_with((string) $scriptId, 'data_source-')) {
35+
$scripts[] = [Script::class, $scriptId];
36+
}
3437
}
3538

3639
return $scripts;
@@ -54,6 +57,9 @@ public function updateReferences(Process $process, array $references = [])
5457
$nodes = $xpath->query("//*[@pm:scriptRef!='']");
5558
foreach ($nodes as $node) {
5659
$oldRef = $node->getAttributeNS(WorkflowServiceProvider::PROCESS_MAKER_NS, 'scriptRef');
60+
if (str_starts_with((string) $oldRef, 'data_source-')) {
61+
continue;
62+
}
5763
$newRef = $references[Script::class][$oldRef]->getKey();
5864
$node->setAttributeNS(WorkflowServiceProvider::PROCESS_MAKER_NS, 'scriptRef', $newRef);
5965
}

‎ProcessMaker/Assets/ScriptsInScreen.php‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ public function referencesToExport(Screen $screen, array $scripts = [])
2626
if (is_array($config)) {
2727
$this->findInArray($config, function ($item) use (&$scripts) {
2828
if (is_array($item) && !empty($item['script_id'])) {
29-
$scripts[] = [Script::class, $item['script_id']];
29+
$scriptId = (string) $item['script_id'];
30+
$id = (string) ($item['script']['id'] ?? '');
31+
if (!str_starts_with($scriptId, 'data_source-') && !str_starts_with($id, 'data_source-')) {
32+
$scripts[] = [Script::class, $item['script_id']];
33+
}
3034
}
3135
});
3236
}
@@ -47,11 +51,12 @@ public function updateReferences(Screen $screen, array $references, ExportManage
4751
$watches = $screen->watchers;
4852
if (is_array($watches)) {
4953
foreach ($watches as &$watcher) {
50-
$refParts = explode('-', $watcher['script_id']);
51-
if ($refParts[0] === 'data_source') {
54+
$scriptId = (string) ($watcher['script_id'] ?? '');
55+
$id = (string) ($watcher['script']['id'] ?? '');
56+
if (str_starts_with($scriptId, 'data_source-') || str_starts_with($id, 'data_source-')) {
5257
continue;
5358
}
54-
$oldRef = $refParts[1];
59+
$oldRef = $scriptId;
5560
if (isset($references[Script::class][$oldRef])) {
5661
$newRef = $references[Script::class][$oldRef]->getKey();
5762
} else {
@@ -82,17 +87,18 @@ public function updateReferences(Screen $screen, array $references, ExportManage
8287
*
8388
* @param array $array
8489
* @param callable $callback
90+
* @param array $path
8591
*
8692
* @return void
8793
*/
88-
private function findInArray(array $array, callable $callback)
94+
private function findInArray(array $array, callable $callback, array $path = [])
8995
{
90-
call_user_func($callback, $array);
91-
foreach ($array as $item) {
96+
call_user_func($callback, $array, implode('.', $path));
97+
foreach ($array as $key => $item) {
9298
if (is_array($item)) {
93-
$this->findInArray($item, $callback);
99+
$this->findInArray($item, $callback, array_merge($path, [$key]));
94100
} else {
95-
call_user_func($callback, $item);
101+
call_user_func($callback, $item, implode('.', array_merge($path, [$key])));
96102
}
97103
}
98104
}

‎ProcessMaker/Console/Commands/InitializeScriptMicroservice.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ public function handle()
3535
// Keep only the first occurrence of each language
3636
if (isset($requiredLanguages[$executor->language])) {
3737
$this->info('Keeping ' . $executor->language);
38-
} else {
38+
} elseif (!config('app.custom_executors')) {
3939
// Hide non-microservice languages as well as any duplicate languages
40+
// Only do this if custom executors are not enabled on the microservice
4041
$this->info('Hiding ' . $executor->language);
4142
$executor->is_system = true;
4243
$executor->type = ScriptExecutorType::Duplicate;

‎ProcessMaker/Console/Commands/SyncGuidedTemplates.php‎

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)