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
8 changes: 4 additions & 4 deletions app/Jobs/PerformLegacyDailyUpdates.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private function sendEmailExpectedBuilds($projectid, $currentstarttime): void
AND bg.starttime<?
AND (
bg.endtime>?
OR bg.endtime='1980-01-01 00:00:00'
OR bg.endtime IS NULL
)
AND site.id=t1.siteid
", [
Expand Down Expand Up @@ -203,10 +203,10 @@ private function addDailyChanges(int $projectid): void
BuildGroupRule::DeleteExpiredRulesForProject($project->Id, $cutoff_date);

$stmt = $db->prepare(
"SELECT id FROM buildgroup
'SELECT id FROM buildgroup
WHERE projectid = :projectid AND
endtime != '1980-01-01 00:00:00' AND
endtime < :endtime");
endtime IS NOT NULL AND
endtime < :endtime');
$query_params = [
':projectid' => $project->Id,
':endtime' => $cutoff_date,
Expand Down
12 changes: 11 additions & 1 deletion app/Models/BuildGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use Database\Factories\BuildGroupFactory;
use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -16,7 +17,7 @@
* @property string $name
* @property int $projectid
* @property Carbon $starttime
* @property Carbon $endtime
* @property ?Carbon $endtime
* @property int $autoremovetimeframe
* @property ?string $description
* @property int $summaryemail
Expand Down Expand Up @@ -93,4 +94,13 @@ public function rules(): HasMany
{
return $this->hasMany(BuildGroupRule::class, 'groupid');
}

/**
* @param Builder<$this> $query
*/
#[Scope]
protected function active(Builder $query): void
{
$query->whereNull('endtime');
}
}
4 changes: 2 additions & 2 deletions app/Services/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function initializeBuildGroups(Project $project): void
{
$common_defaults = [
'starttime' => Carbon::create(1980),
'endtime' => Carbon::create(1980),
'endtime' => null,
'type' => 'Daily',
'includesubprojectotal' => 1,
'emailcommitters' => 0,
Expand Down Expand Up @@ -121,7 +121,7 @@ public static function getBuildGroups(int $projectid): array
{
$eloquent_buildgroups = Project::findOrFail($projectid)
->buildgroups()
->where('endtime', Carbon::create(1980))
->whereNull('endtime')
->get();

$buildgroups = [];
Expand Down
3 changes: 1 addition & 2 deletions app/cdash/app/Controller/Api/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public function getDynamicBuilds(): array
LEFT JOIN buildgroupposition AS gp ON (gp.buildgroupid = bg.id)
WHERE
bg.projectid = ?
AND bg.endtime = ?
AND bg.endtime IS NULL
AND bg.type != 'Daily'
AND b2gr.starttime < ?
AND (
Expand All @@ -203,7 +203,6 @@ public function getDynamicBuilds(): array
)
", [
(int) $this->project->Id,
self::BEGIN_EPOCH,
$this->endDate,
self::BEGIN_EPOCH,
$this->endDate,
Expand Down
10 changes: 5 additions & 5 deletions app/cdash/app/Model/BuildGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct()
'projectid' => 0,
'name' => '',
'starttime' => Carbon::create(1980),
'endtime' => Carbon::create(1980),
'endtime' => null,
'description' => '',
'summaryemail' => 0,
'type' => 'Daily',
Expand Down Expand Up @@ -335,7 +335,7 @@ public function Save(): bool
$this->eloquent_model->positions()->create([
'position' => $position,
'starttime' => $this->eloquent_model->starttime,
'endtime' => $this->eloquent_model->endtime,
'endtime' => Carbon::create(1980),
]);
}
return true;
Expand Down Expand Up @@ -463,14 +463,14 @@ public static function GetBuildGroups($projectid, $begin): array
{
$buildgroups = [];

$stmt = DB::select("
$stmt = DB::select('
SELECT bg.id, bg.name, bgp.position
FROM buildgroup AS bg
LEFT JOIN buildgroupposition AS bgp ON (bgp.buildgroupid = bg.id)
WHERE bg.projectid = ? AND
bg.starttime < ? AND
(bg.endtime > ? OR bg.endtime='1980-01-01 00:00:00')
", [$projectid, $begin, $begin]);
(bg.endtime > ? OR bg.endtime IS NULL)
', [$projectid, $begin, $begin]);

foreach ($stmt as $row) {
$buildgroup = new self();
Expand Down
5 changes: 4 additions & 1 deletion app/cdash/tests/case/CDash/MultipleSubprojectsEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

use App\Http\Submission\Handlers\ActionableBuildInterface;
use App\Models\BuildGroup;
use CDash\Collection\SubscriberCollection;
use CDash\Database;
use CDash\Messaging\Notification\Email\EmailBuilder;
Expand All @@ -28,6 +29,7 @@
use CDash\Model\Subscriber;
use CDash\Test\CDashUseCaseTestCase;
use CDash\Test\UseCase\UseCase;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -125,9 +127,10 @@ public function setUp(): void
}

// Do the same for build groups
DB::table('buildgroup')->insertOrIgnore([
BuildGroup::insertOrIgnore([
'id' => 0,
'projectid' => self::$projectid,
'starttime' => Carbon::now(),
'description' => 'MultipleSubprojectsEmailTest-' . Str::uuid()->toString(),
]);
}
Expand Down
2 changes: 2 additions & 0 deletions app/cdash/tests/test_buildmodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Utils\DatabaseCleanupUtils;
use CDash\Model\Build;
use CDash\Model\BuildError;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -38,6 +39,7 @@ public function __construct()
DB::table('buildgroup')->insertOrIgnore([
'id' => 0,
'projectid' => $project->id,
'starttime' => Carbon::now(),
'description' => 'MultipleSubprojectsEmailTest-' . Str::uuid()->toString(),
]);

Expand Down
6 changes: 3 additions & 3 deletions app/cdash/tests/test_projectindb.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public function testProjectInBuildGroup(): void
$result = $this->db->query($query);
$expected = ['0' => ['name' => 'Nightly',
'starttime' => '1980-01-01 00:00:00',
'endtime' => '1980-01-01 00:00:00',
'endtime' => null,
'description' => 'Nightly builds'],
'1' => ['name' => 'Experimental',
'starttime' => '1980-01-01 00:00:00',
'endtime' => '1980-01-01 00:00:00',
'endtime' => null,
'description' => 'Experimental builds'],
'2' => ['name' => 'Continuous',
'starttime' => '1980-01-01 00:00:00',
'endtime' => '1980-01-01 00:00:00',
'endtime' => null,
'description' => 'Continuous builds']];
$this->assertEqual($result, $expected);
}
Expand Down
2 changes: 1 addition & 1 deletion database/factories/BuildGroupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function definition(): array
return [
'name' => Str::uuid()->toString(),
'starttime' => Carbon::create(1980),
'endtime' => Carbon::create(1980),
'endtime' => null,
'autoremovetimeframe' => 0,
'description' => Str::uuid()->toString(),
'summaryemail' => 0,
Expand Down
19 changes: 19 additions & 0 deletions database/migrations/2026_09_10_194315_buildgroup_times.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

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

return new class extends Migration {
public function up(): void
{
DB::statement('ALTER TABLE buildgroup ALTER COLUMN starttime DROP DEFAULT');

DB::statement('ALTER TABLE buildgroup ALTER COLUMN endtime DROP DEFAULT');
DB::statement('ALTER TABLE buildgroup ALTER COLUMN endtime DROP NOT NULL');
DB::update("UPDATE buildgroup SET endtime = NULL WHERE endtime = '1980-01-01 00:00:00'");
}

public function down(): void
{
}
};
9 changes: 9 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -23034,6 +23034,15 @@ parameters:
count: 1
path: tests/Feature/RouteAccessTest.php

-
rawMessage: '''
Call to deprecated method getBuildGroups() of class App\Services\ProjectService:
12/06/2025 Use Eloquent relationships for all new code
'''
identifier: staticMethod.deprecated
count: 1
path: tests/Feature/Services/ProjectServiceTest.php

-
rawMessage: Cannot access property $admin on App\Models\User|null.
identifier: property.nonObject
Expand Down
8 changes: 8 additions & 0 deletions tests/Feature/Services/ProjectServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,13 @@ public function testCreatesDefaultBuildGroups(): void
['Nightly', 'Continuous', 'Experimental'],
$project->buildgroups()->pluck('name')->toArray(),
);

foreach ($project->buildgroups as $buildgroup) {
self::assertNotNull($buildgroup->starttime);
self::assertNull($buildgroup->endtime);
}

$active_groups = ProjectService::getBuildGroups($project->id);
self::assertCount(3, $active_groups);
}
}