Skip to content

Commit 46ca020

Browse files
Created the methods to save remote settings
1 parent 7c2516a commit 46ca020

6 files changed

Lines changed: 49 additions & 10 deletions

File tree

‎ProcessMaker/Http/Controllers/Api/DevLinkController.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ public function exportLocalBundle(Bundle $bundle)
203203
return ['payloads' => $bundle->export()];
204204
}
205205

206+
public function exportLocalBundleSettings(Bundle $bundle)
207+
{
208+
return ['settings' => $bundle->exportSettings()];
209+
}
210+
206211
public function exportLocalAsset(Request $request)
207212
{
208213
$asset = $request->input('class')::findOrFail($request->input('id'));

‎ProcessMaker/Models/Bundle.php‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ public function export()
7777
return $exports;
7878
}
7979

80+
public function exportSettings()
81+
{
82+
return $this->settings()->get()->map(function ($setting) {
83+
return $setting->export();
84+
});
85+
}
86+
8087
public function syncAssets($assets)
8188
{
8289
$assetKeys = [];
@@ -135,14 +142,16 @@ public function addSettings($setting, $config)
135142
{
136143
$exists = $this->settings()->where('setting', $setting)->exists();
137144
if ($exists) {
138-
throw ValidationException::withMessages(['*' => 'Setting already exists in bundle']);
145+
$this->settings()->where('setting', $setting)->update([
146+
'config' => $config,
147+
]);
148+
} else {
149+
BundleSetting::create([
150+
'bundle_id' => $this->id,
151+
'setting' => $setting,
152+
'config' => $config,
153+
]);
139154
}
140-
141-
BundleSetting::create([
142-
'bundle_id' => $this->id,
143-
'setting' => $setting,
144-
'config' => $config,
145-
]);
146155
}
147156

148157
public function addAssetToBundles(ProcessMakerModel $asset)
@@ -204,6 +213,19 @@ public function savePayloadsToFile(array $payloads)
204213
}
205214
}
206215

216+
public function installSettings($settings)
217+
{
218+
$newSettingsKeys = collect($settings)->pluck('setting')->toArray();
219+
220+
$this->settings()
221+
->whereNotIn('setting', $newSettingsKeys)
222+
->delete();
223+
224+
foreach ($settings as $setting) {
225+
$this->addSettings($setting['setting'], $setting['config']);
226+
}
227+
}
228+
207229
public function install(array $payloads, $mode, $logger = null)
208230
{
209231
if ($logger === null) {

‎ProcessMaker/Models/BundleSetting.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ public function bundle()
2323
{
2424
return $this->belongsTo(Bundle::class);
2525
}
26+
27+
public function export()
28+
{
29+
return [
30+
'setting' => $this->setting,
31+
'config' => $this->config,
32+
];
33+
}
2634
}

‎ProcessMaker/Models/DevLink.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ public function installRemoteBundle($remoteBundleId, $updateType)
143143
route('api.devlink.export-local-bundle', ['bundle' => $remoteBundleId], false)
144144
)->json();
145145

146+
$bundleSettingsExport = $this->client()->get(
147+
route('api.devlink.export-local-bundle-settings', ['bundle' => $remoteBundleId], false)
148+
)->json();
149+
146150
$bundle = Bundle::updateOrCreate(
147151
[
148152
'remote_id' => $remoteBundleId,
@@ -156,7 +160,7 @@ public function installRemoteBundle($remoteBundleId, $updateType)
156160
);
157161

158162
$bundle->install($bundleExport['payloads'], $updateType, $this->logger);
159-
163+
$bundle->installSettings($bundleSettingsExport['settings']);
160164
$this->logger->setStatus('done');
161165
}
162166

‎resources/js/admin/devlink/components/BundleDetail.vue‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<template>
22
<div class="main-content">
33
<div class="tw-flex tw-items-center tw-justify-center" v-if="loading">
4-
<div class="spinner-border text-primary" role="status">
5-
</div>
4+
<div class="spinner-border text-primary" role="status" />
65
<span class="visually-hidden">Loading...</span>
76
</div>
87
<!-- Header -->

‎routes/api.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@
403403
Route::delete('devlink/local-bundles/assets/{bundle_asset}', [DevLinkController::class, 'deleteBundleAsset'])->name('devlink.delete-bundle-asset');
404404
Route::delete('devlink/local-bundles/settings/{bundle_setting}', [DevLinkController::class, 'deleteBundleSetting'])->name('devlink.delete-bundle-setting');
405405
Route::get('devlink/export-local-bundle/{bundle}', [DevLinkController::class, 'exportLocalBundle'])->name('devlink.export-local-bundle');
406+
Route::get('devlink/export-local-bundle/{bundle}/settings', [DevLinkController::class, 'exportLocalBundleSettings'])->name('devlink.export-local-bundle-settings');
406407
Route::get('devlink/export-local-asset', [DevLinkController::class, 'exportLocalAsset'])->name('devlink.export-local-asset');
407408

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

0 commit comments

Comments
 (0)