-
Notifications
You must be signed in to change notification settings - Fork 245
FOUR-32305: Export assets referenced in scripts using environment variables #8918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
110e7ac
d935512
f4cd158
509fe80
5abb6b6
878f65e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
|
|
||
| namespace ProcessMaker\ImportExport\Exporters; | ||
|
|
||
| use Illuminate\Support\Facades\Log; | ||
| use ProcessMaker\Enums\ExporterMap; | ||
| use ProcessMaker\ImportExport\DependentType; | ||
|
|
||
| class EnvironmentVariableExporter extends ExporterBase | ||
|
|
@@ -17,10 +19,50 @@ class EnvironmentVariableExporter extends ExporterBase | |
| public function export() : void | ||
| { | ||
| $this->addReference(DependentType::ENVIRONMENT_VARIABLE_VALUE, $this->model->value); | ||
|
|
||
| if (!$this->model->hasLinkedAsset()) { | ||
| return; | ||
| } | ||
|
|
||
| $asset = $this->model->resolveLinkedAsset(); | ||
| if (!$asset) { | ||
| Log::warning('EnvironmentVariableExporter: linked asset not found during export', [ | ||
| 'environment_variable' => $this->model->name, | ||
| 'asset_type' => $this->model->asset_type, | ||
| 'value' => $this->model->value, | ||
| ]); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| $exporterClass = ExporterMap::getExporterClassForModel($asset); | ||
| if (!$exporterClass) { | ||
| Log::warning('EnvironmentVariableExporter: no exporter registered for linked asset', [ | ||
| 'environment_variable' => $this->model->name, | ||
| 'asset_type' => $this->model->asset_type, | ||
| ]); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| $this->addDependent(DependentType::ENVIRONMENT_VARIABLE_ASSET, $asset, $exporterClass); | ||
| } | ||
|
|
||
| public function import() : bool | ||
| { | ||
| foreach ($this->getDependents(DependentType::ENVIRONMENT_VARIABLE_ASSET, true) as $dependent) { | ||
| $asset = $dependent->model; | ||
| if (!$asset) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 A discarded or unresolved asset (Custom Import) can be returned as an empty model. The truthiness check at line 55 passes, then the importer saves
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This scenario is covered and tested in this PR: #8928 |
||
| continue; | ||
| } | ||
|
|
||
| $this->model->asset_type = get_class($asset); | ||
| $this->model->value = (string) $asset->id; | ||
|
|
||
| return $this->model->save(); | ||
| } | ||
|
|
||
| // Non-linked env vars (or discarded asset dependents): restore exported value. | ||
| $this->model->value = $this->getReference(DependentType::ENVIRONMENT_VARIABLE_VALUE); | ||
|
|
||
| return $this->model->save(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\Schema; | ||
|
|
||
| return new class extends Migration | ||
| { | ||
| /** | ||
| * Run the migrations. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| Schema::table('environment_variables', function (Blueprint $table) { | ||
| $table->string('asset_type')->nullable()->after('value'); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void | ||
| { | ||
| Schema::table('environment_variables', function (Blueprint $table) { | ||
| $table->dropColumn(['asset_type']); | ||
| }); | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /** | ||
| * Exportable asset types that can be linked to an environment variable. | ||
| * apiPath is the local API listing endpoint used by the asset picker. | ||
| */ | ||
| export default [ | ||
| { | ||
| class: "ProcessMaker\\Models\\Process", | ||
| label: "Process", | ||
| apiPath: "processes", | ||
| nameField: "name", | ||
| }, | ||
| { | ||
| class: "ProcessMaker\\Models\\Screen", | ||
| label: "Screen", | ||
| apiPath: "screens", | ||
| nameField: "title", | ||
| }, | ||
| { | ||
| class: "ProcessMaker\\Models\\Script", | ||
| label: "Script", | ||
| apiPath: "scripts", | ||
| nameField: "title", | ||
| }, | ||
| { | ||
| class: "ProcessMaker\\Plugins\\Collections\\Models\\Collection", | ||
| label: "Collection", | ||
| apiPath: "collections", | ||
| nameField: "name", | ||
| }, | ||
| { | ||
| class: "ProcessMaker\\Packages\\Connectors\\DataSources\\Models\\DataSource", | ||
| label: "Data Connector", | ||
| apiPath: "data_sources", | ||
| nameField: "name", | ||
| }, | ||
| { | ||
| class: "ProcessMaker\\Package\\PackageDecisionEngine\\Models\\DecisionTable", | ||
| label: "Decision Table", | ||
| apiPath: "decision_tables", | ||
| nameField: "title", | ||
| }, | ||
| { | ||
| class: "ProcessMaker\\Package\\PackageAi\\Models\\FlowGenie", | ||
| label: "FlowGenie", | ||
| apiPath: "package-ai/flow_genies", | ||
| nameField: "name", | ||
| }, | ||
| { | ||
| class: "ProcessMaker\\Package\\PackagePmBlocks\\Models\\PmBlock", | ||
| label: "PM Block", | ||
| apiPath: "pm-blocks", | ||
| nameField: "name", | ||
| }, | ||
| ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 If
asset_uuidis retained, update validation does not actually guarantee both-or-neither. It validates only the incoming payload, so clearing one link field while omitting the other can persist an inconsistent pair. Validate the merged resulting state or update both fields atomically.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the validation of assets linking:
If the asset does not match a valid one returns an 422