Skip to content

Commit

Permalink
Created the methods to save remote settings
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavobascope committed Dec 6, 2024
1 parent 7c2516a commit 46ca020
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
5 changes: 5 additions & 0 deletions ProcessMaker/Http/Controllers/Api/DevLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ public function exportLocalBundle(Bundle $bundle)
return ['payloads' => $bundle->export()];
}

public function exportLocalBundleSettings(Bundle $bundle)
{
return ['settings' => $bundle->exportSettings()];
}

public function exportLocalAsset(Request $request)
{
$asset = $request->input('class')::findOrFail($request->input('id'));
Expand Down
36 changes: 29 additions & 7 deletions ProcessMaker/Models/Bundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public function export()
return $exports;
}

public function exportSettings()
{
return $this->settings()->get()->map(function ($setting) {
return $setting->export();
});
}

public function syncAssets($assets)
{
$assetKeys = [];
Expand Down Expand Up @@ -135,14 +142,16 @@ public function addSettings($setting, $config)
{
$exists = $this->settings()->where('setting', $setting)->exists();
if ($exists) {
throw ValidationException::withMessages(['*' => 'Setting already exists in bundle']);
$this->settings()->where('setting', $setting)->update([
'config' => $config,
]);
} else {
BundleSetting::create([
'bundle_id' => $this->id,
'setting' => $setting,
'config' => $config,
]);
}

BundleSetting::create([
'bundle_id' => $this->id,
'setting' => $setting,
'config' => $config,
]);
}

public function addAssetToBundles(ProcessMakerModel $asset)
Expand Down Expand Up @@ -204,6 +213,19 @@ public function savePayloadsToFile(array $payloads)
}
}

public function installSettings($settings)
{
$newSettingsKeys = collect($settings)->pluck('setting')->toArray();

$this->settings()
->whereNotIn('setting', $newSettingsKeys)
->delete();

foreach ($settings as $setting) {
$this->addSettings($setting['setting'], $setting['config']);
}
}

public function install(array $payloads, $mode, $logger = null)
{
if ($logger === null) {
Expand Down
8 changes: 8 additions & 0 deletions ProcessMaker/Models/BundleSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ public function bundle()
{
return $this->belongsTo(Bundle::class);
}

public function export()
{
return [
'setting' => $this->setting,
'config' => $this->config,
];
}
}
6 changes: 5 additions & 1 deletion ProcessMaker/Models/DevLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public function installRemoteBundle($remoteBundleId, $updateType)
route('api.devlink.export-local-bundle', ['bundle' => $remoteBundleId], false)
)->json();

$bundleSettingsExport = $this->client()->get(
route('api.devlink.export-local-bundle-settings', ['bundle' => $remoteBundleId], false)
)->json();

$bundle = Bundle::updateOrCreate(
[
'remote_id' => $remoteBundleId,
Expand All @@ -156,7 +160,7 @@ public function installRemoteBundle($remoteBundleId, $updateType)
);

$bundle->install($bundleExport['payloads'], $updateType, $this->logger);

$bundle->installSettings($bundleSettingsExport['settings']);
$this->logger->setStatus('done');
}

Expand Down
3 changes: 1 addition & 2 deletions resources/js/admin/devlink/components/BundleDetail.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<template>
<div class="main-content">
<div class="tw-flex tw-items-center tw-justify-center" v-if="loading">
<div class="spinner-border text-primary" role="status">
</div>
<div class="spinner-border text-primary" role="status" />
<span class="visually-hidden">Loading...</span>
</div>
<!-- Header -->
Expand Down
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@
Route::delete('devlink/local-bundles/assets/{bundle_asset}', [DevLinkController::class, 'deleteBundleAsset'])->name('devlink.delete-bundle-asset');
Route::delete('devlink/local-bundles/settings/{bundle_setting}', [DevLinkController::class, 'deleteBundleSetting'])->name('devlink.delete-bundle-setting');
Route::get('devlink/export-local-bundle/{bundle}', [DevLinkController::class, 'exportLocalBundle'])->name('devlink.export-local-bundle');
Route::get('devlink/export-local-bundle/{bundle}/settings', [DevLinkController::class, 'exportLocalBundleSettings'])->name('devlink.export-local-bundle-settings');
Route::get('devlink/export-local-asset', [DevLinkController::class, 'exportLocalAsset'])->name('devlink.export-local-asset');

Route::post('devlink/{devLink}/remote-bundles/{remoteBundleId}/install', [DevLinkController::class, 'installRemoteBundle'])->name('devlink.install-remote-bundle');
Expand Down

0 comments on commit 46ca020

Please sign in to comment.