Skip to content

Commit 1df5aa0

Browse files
Added a new update_by column in process_template table
1 parent 873d698 commit 1df5aa0

3 files changed

Lines changed: 50 additions & 3 deletions

File tree

ProcessMaker/Models/ProcessTemplates.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Database\Eloquent\Builder;
66
use Illuminate\Database\Eloquent\Factories\HasFactory;
7+
use Illuminate\Support\Facades\Auth;
78
use ProcessMaker\Traits\HasCategories;
89
use ProcessMaker\Traits\HideSystemResources;
910
use ProcessMaker\Traits\ProcessTrait;
@@ -17,6 +18,24 @@ class ProcessTemplates extends Template
1718

1819
protected $table = 'process_templates';
1920

21+
public static function boot()
22+
{
23+
parent::boot();
24+
25+
static::creating(function ($model) {
26+
$model->updated_by = Auth::id();
27+
});
28+
29+
static::updating(function ($model) {
30+
$model->updated_by = Auth::id();
31+
});
32+
}
33+
34+
public function updatedByUser()
35+
{
36+
return $this->belongsTo(User::class, 'updated_by');
37+
}
38+
2039
const categoryClass = ProcessCategory::class;
2140

2241
public $process_category_id;

ProcessMaker/Templates/ProcessTemplate.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ public function updateTemplateConfigs($request) : JsonResponse
360360
$template = ProcessTemplates::where('id', $id)->firstOrFail();
361361
$oldTemplateName = $template->name;
362362
$template->fill($request->except('id'));
363-
$template->user_id = Auth::user()->id;
364363
$process = Process::where('name', $oldTemplateName)->where('is_template', 1)->first();
365364
if ($process) {
366365
$process->fill($request->except('id'));
@@ -408,11 +407,11 @@ public function updateTemplateManifest(int $processId, $request) : JsonResponse
408407
// Extract svg from payload
409408
$svg = Arr::get($payload, 'export.' . $payload['root'] . '.attributes.svg');
410409

411-
// Update the process template manifest, svg, and user_id
410+
// Update the process template manifest, svg, and updated_by
412411
$processTemplate = ProcessTemplates::where('name', $data['name'])->update([
413412
'manifest' => json_encode($payload),
414413
'svg' => $svg,
415-
'user_id' => \Auth::user()->id,
414+
'updated_by' => \Auth::user()->id,
416415
]);
417416

418417
return response()->json();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\DB;
6+
use Illuminate\Support\Facades\Schema;
7+
8+
return new class extends Migration {
9+
public function up()
10+
{
11+
Schema::table('process_templates', function (Blueprint $table) {
12+
$table->unsignedInteger('updated_by')->nullable()->after('user_id');
13+
$table->foreign('updated_by')->references('id')->on('users')->onDelete('set null');
14+
});
15+
16+
// Seed updated_by with the existing user_id value
17+
DB::table('process_templates')->update([
18+
'updated_by' => DB::raw('user_id'),
19+
]);
20+
}
21+
22+
public function down()
23+
{
24+
Schema::table('process_templates', function (Blueprint $table) {
25+
$table->dropForeign(['updated_by']);
26+
$table->dropColumn('updated_by');
27+
});
28+
}
29+
};

0 commit comments

Comments
 (0)