fix: make project template inheritance granular and safe
CI/CD / test_and_check_app (push) Failing after 3m8s
CI/CD / Publish immutable image (push) Skipped
CI/CD / test_and_check_app (pull_request) Failing after 3m8s
CI/CD / Publish immutable image (pull_request) Skipped

This commit is contained in:
Nico Schröder
2026-09-08 10:25:52 +00:00
committed by Twyco
parent fed6a282a4
commit 9895fc36db
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;
}
}