31 lines
1.2 KiB
PHP
31 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Projects;
|
|
|
|
use App\Models\Project;
|
|
use App\Models\ProjectTemplate;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class RefreshProjectBaseTemplate
|
|
{
|
|
public function __construct(
|
|
private readonly DuplicateProjectConfiguration $duplicateProjectConfiguration,
|
|
) {}
|
|
|
|
public function handle(Project $project, string $area): void
|
|
{
|
|
DB::transaction(function () use ($project, $area): void {
|
|
$project = Project::query()->whereKey($project->id)->lockForUpdate()->firstOrFail();
|
|
$template = ProjectTemplate::query()->find($project->project_template_id);
|
|
if ($template === null || $template->is_published) {
|
|
return;
|
|
}
|
|
$template = ProjectTemplate::query()->whereKey($template->id)->lockForUpdate()->firstOrFail();
|
|
$snapshot = $this->duplicateProjectConfiguration->normalizeConfiguration($template->configuration_snapshot ?? []);
|
|
$template->forceFill(['configuration_snapshot' => array_replace(
|
|
$snapshot, $this->duplicateProjectConfiguration->export($project, [$area]),
|
|
)])->saveQuietly();
|
|
}, 3);
|
|
}
|
|
}
|