Add template switch and reset flows for existing projects

This commit is contained in:
2026-05-25 08:31:35 +00:00
parent ee9b9a2765
commit e38c77198d
10 changed files with 522 additions and 2 deletions
@@ -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 ?? [],
);
});
}
}