Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ProcessMaker/Enums/ExporterMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum ExporterMap
],
'screen_translation' => [\ProcessMaker\Package\Translations\Models\Translatable::class, \ProcessMaker\Package\Translations\ImportExport\TranslatableExporter::class],
'pm_block' => [\ProcessMaker\Package\PackagePmBlocks\Models\PmBlock::class, \ProcessMaker\Package\PackagePmBlocks\ImportExport\PmBlockExporter::class],
'service_task_resource' => [\ProcessMaker\Package\PackageServiceTask\Models\ServiceTaskResource::class, \ProcessMaker\Package\PackageServiceTask\ImportExport\Exporters\ServiceTaskResourceExporter::class],
];

public static function getModelClass(string $type): ?string
Expand Down
53 changes: 53 additions & 0 deletions ProcessMaker/ImportExport/Exporters/ProcessExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function export() : void

$this->exportScripts();

$this->exportServiceTaskResources();

$this->exportCategories();

$this->exportSignals();
Expand Down Expand Up @@ -435,6 +437,40 @@ private function exportScripts()
}
}

private function exportServiceTaskResources()
{
$tags = [
'bpmn:serviceTask',
];

foreach (Utils::getElementByMultipleTags($this->model->getDefinitions(true), $tags) as $element) {
$path = $element->getNodePath();
$meta = [
'path' => $path,
];

// Check if it's a package-service-task implementation
$implementation = $element->getAttribute('implementation');
if ($implementation === 'package-service-task/service-task') {
// Get the resource ID from pm:config
$config = json_decode($element->getAttribute('pm:config'), true);
$resourceId = $config['resource']['id'] ?? null;

if (is_numeric($resourceId)) {
// Try to load the ServiceTaskResource class
if (class_exists('ProcessMaker\Package\PackageServiceTask\Models\ServiceTaskResource')) {
$resource = \ProcessMaker\Package\PackageServiceTask\Models\ServiceTaskResource::find($resourceId);
if ($resource) {
$this->addDependent('service_task_resource', $resource, 'ProcessMaker\Package\PackageServiceTask\ImportExport\Exporters\ServiceTaskResourceExporter', $meta);
} else {
Log::debug("ServiceTaskResourceId: {$resourceId} not exists");
}
}
}
}
}
}

private function importScripts()
{
foreach ($this->getDependents(DependentType::SCRIPTS) as $dependent) {
Expand All @@ -443,6 +479,22 @@ private function importScripts()
}
}

private function importServiceTaskResources()
{
foreach ($this->getDependents('service_task_resource') as $dependent) {
$path = $dependent->meta['path'];

// Get current config
$config = json_decode(Utils::getAttributeAtXPath($this->model, $path, 'pm:config'), true);

// Update resource ID in config
$config['resource']['id'] = $dependent->model->id;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Invalid JSON Handling in Resource Import

The importServiceTaskResources method attempts to update $config['resource']['id'] without validating the pm:config attribute. If json_decode returns null due to invalid JSON, or if the decoded config lacks the resource key, this causes PHP errors.

Fix in Cursor Fix in Web

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gustavobascope consider to include this defensive code in case the pm:config is not defined


// Set updated config back to BPMN
Utils::setAttributeAtXPath($this->model, $path, 'pm:config', json_encode($config));
}
}

/**
* Imports assets according to the `saveAssetsMode` option of the manifest.
*
Expand Down Expand Up @@ -471,6 +523,7 @@ private function importAssetsByMode(): void
if ($saveAssetsMode === null || $saveAssetsMode === 'saveAllAssets') {
$this->importScreens();
$this->importScripts();
$this->importServiceTaskResources();
$this->importSubprocesses();
$this->importAssignments();
$this->importProcessLaunchpad();
Expand Down
9 changes: 9 additions & 0 deletions resources/js/admin/devlink/components/assetTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,13 @@ export default [
icon: 'fp-flowgenie-outline',
nameField: 'name',
},
{
type: 'service_task_resource',
name: 'Service Task Resources',
url: 'package.service-task.resources.fetch',
listingUrl: '/designer/service-tasks',
class: 'ProcessMaker\\Package\\PackageServiceTask\\Models\\ServiceTaskResource',
icon: 'fp-script-outline',
nameField: 'name',
},
];