29 lines
867 B
PHP
29 lines
867 B
PHP
<?php
|
|
|
|
namespace App\Actions\Projects;
|
|
|
|
use App\Models\Project;
|
|
use App\Models\ProjectTemplate;
|
|
|
|
class CreateProjectBaseTemplate
|
|
{
|
|
public function __construct(
|
|
private readonly DuplicateProjectConfiguration $duplicateProjectConfiguration,
|
|
) {}
|
|
|
|
public function handle(Project $project): ProjectTemplate
|
|
{
|
|
$copyAreas = DuplicateProjectConfiguration::copyableAreas();
|
|
|
|
return ProjectTemplate::query()->create([
|
|
'project_id' => $project->id,
|
|
'source_project_id' => $project->id,
|
|
'name' => "{$project->name} base template",
|
|
'slug' => strtolower($project->key).'-base-template',
|
|
'is_published' => false,
|
|
'copy_areas' => $copyAreas,
|
|
'configuration_snapshot' => $this->duplicateProjectConfiguration->export($project, $copyAreas),
|
|
]);
|
|
}
|
|
}
|