Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/Enums/BuildGroupType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace App\Enums;

enum BuildGroupType: string
{
case DAILY = 'Daily';
case LATEST = 'Latest';
}
4 changes: 3 additions & 1 deletion app/Models/BuildGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Enums\BuildGroupType;
use Database\Factories\BuildGroupFactory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand All @@ -22,7 +23,7 @@
* @property int $summaryemail
* @property int $includesubprojectotal // Should this be a boolean?
* @property int $emailcommitters // Should this be a boolean?
* @property string $type
* @property BuildGroupType $type
*
* @mixin Builder<BuildGroup>
*/
Expand Down Expand Up @@ -57,6 +58,7 @@ class BuildGroup extends Model
'summaryemail' => 'integer',
'includesubprojectotal' => 'integer',
'emailcommitters' => 'integer',
'type' => BuildGroupType::class,
];

/**
Expand Down
18 changes: 14 additions & 4 deletions app/cdash/app/Model/BuildGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -42,7 +44,7 @@ public function __construct()
'endtime' => Carbon::create(1980),
'description' => '',
'summaryemail' => 0,
'type' => 'Daily',
'type' => BuildGroupType::DAILY,
'includesubprojectotal' => 1,
'emailcommitters' => 0,
]);
Expand Down Expand Up @@ -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"),
};
}
}

/**
Expand Down
31 changes: 31 additions & 0 deletions database/migrations/2026_09_10_163431_buildgroup_type_enum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration {
public function up(): void
{
// We drop the type first in case the database has been truncated previously.
DB::statement('DROP TYPE IF EXISTS buildgrouptype');
DB::statement("CREATE TYPE buildgrouptype AS ENUM ('Daily', 'Latest')");

DB::statement('ALTER TABLE buildgroup ALTER COLUMN type DROP DEFAULT');

DB::statement("
ALTER TABLE buildgroup
ALTER COLUMN \"type\" TYPE buildgrouptype
USING CASE \"type\"
WHEN 'Daily' THEN 'Daily'::buildgrouptype
WHEN 'Latest' THEN 'Latest'::buildgrouptype
ELSE 'Daily'::buildgrouptype
END
");

DB::statement("ALTER TABLE buildgroup ALTER COLUMN type SET DEFAULT 'Daily'::buildgrouptype");
}

public function down(): void
{
}
};