Merge pull request 'koda/kan-9-switchreset-template-for-existing-projects' (#97) from koda/kan-9-switchreset-template-for-existing-projects into epic/kan-3
Reviewed-on: OpenSource/KanbanGit#97
This commit was merged in pull request #97.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Projects;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\ProjectTemplate;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateProjectTemplateLink
|
||||
{
|
||||
public function __construct(
|
||||
private readonly DuplicateProjectConfiguration $duplicateProjectConfiguration,
|
||||
) {}
|
||||
|
||||
public function switch(Project $project, ProjectTemplate $template): void
|
||||
{
|
||||
DB::transaction(function () use ($project, $template): void {
|
||||
$project->forceFill([
|
||||
'project_template_id' => $template->id,
|
||||
])->save();
|
||||
|
||||
$this->duplicateProjectConfiguration->apply(
|
||||
$project->fresh(),
|
||||
$template->configuration_snapshot ?? [],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public function reset(Project $project): void
|
||||
{
|
||||
$template = $project->projectTemplate;
|
||||
|
||||
if ($template === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($project, $template): void {
|
||||
$this->duplicateProjectConfiguration->apply(
|
||||
$project->fresh(),
|
||||
$template->configuration_snapshot ?? [],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user