diff --git a/app/Enums/BuildGroupType.php b/app/Enums/BuildGroupType.php new file mode 100644 index 0000000000..82547b532f --- /dev/null +++ b/app/Enums/BuildGroupType.php @@ -0,0 +1,11 @@ + */ @@ -57,6 +58,7 @@ class BuildGroup extends Model 'summaryemail' => 'integer', 'includesubprojectotal' => 'integer', 'emailcommitters' => 'integer', + 'type' => BuildGroupType::class, ]; /** diff --git a/app/cdash/app/Model/BuildGroup.php b/app/cdash/app/Model/BuildGroup.php index f31cf05882..a2b251f0c9 100644 --- a/app/cdash/app/Model/BuildGroup.php +++ b/app/cdash/app/Model/BuildGroup.php @@ -17,11 +17,13 @@ namespace CDash\Model; +use App\Enums\BuildGroupType; use App\Models\BuildGroup as EloquentBuildGroup; use CDash\Database; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; +use InvalidArgumentException; class BuildGroup { @@ -42,7 +44,7 @@ public function __construct() 'endtime' => Carbon::create(1980), 'description' => '', 'summaryemail' => 0, - 'type' => 'Daily', + 'type' => BuildGroupType::DAILY, 'includesubprojectotal' => 1, 'emailcommitters' => 0, ]); @@ -233,12 +235,20 @@ public function GetType(): string|false Log::error('BuildGroup GetType(): Id not set'); return false; } - return $this->eloquent_model->type; + return $this->eloquent_model->type->value; } - public function SetType(string $type): void + public function SetType(string|BuildGroupType $type): void { - $this->eloquent_model->type = $type; + if ($type instanceof BuildGroupType) { + $this->eloquent_model->type = $type; + } else { + $this->eloquent_model->type = match ($type) { + 'Daily' => BuildGroupType::DAILY, + 'Latest' => BuildGroupType::LATEST, + default => throw new InvalidArgumentException("Invalid build group type: $type"), + }; + } } /** diff --git a/database/migrations/2026_09_10_163431_buildgroup_type_enum.php b/database/migrations/2026_09_10_163431_buildgroup_type_enum.php new file mode 100644 index 0000000000..3d78720e79 --- /dev/null +++ b/database/migrations/2026_09_10_163431_buildgroup_type_enum.php @@ -0,0 +1,31 @@ +