fix: make project template inheritance granular and safe
linter / quality (pull_request) Successful in 2m52s
tests / ci (8.4) (pull_request) Successful in 3m15s

This commit is contained in:
Nico Schröder
2026-09-08 12:03:07 +02:00
parent 0f125f17a3
commit 3122e00ed8
50 changed files with 1504 additions and 624 deletions
@@ -0,0 +1,55 @@
<?php
namespace App\Actions\Projects;
use App\Models\Project;
class ProjectTemplateOverrideManager
{
private static int $suppressionDepth = 0;
public function mark(Project $project, string $area): void
{
if (self::$suppressionDepth > 0) {
return;
}
$project->loadMissing('projectTemplate');
if ($project->projectTemplate === null || ! $project->projectTemplate->is_published) {
return;
}
$overrides = array_values(array_unique([
...($project->template_overrides ?? []),
$area,
]));
$project->forceFill(['template_overrides' => $overrides])->saveQuietly();
}
/**
* @param list<string> $areas
*/
public function clear(Project $project, array $areas): void
{
$remaining = array_values(array_diff($project->template_overrides ?? [], $areas));
$project->forceFill(['template_overrides' => $remaining])->saveQuietly();
}
public function withoutRecording(callable $callback): mixed
{
self::$suppressionDepth++;
try {
return $callback();
} finally {
self::$suppressionDepth--;
}
}
public function isRecording(): bool
{
return self::$suppressionDepth === 0;
}
}