Skip to content

Commit 0c51106

Browse files
committed
Fallback to case insensitive searching in some cases
Perform case insensitive searches for projects and build groups. The background here is that MySQL performs case insensitive searches by default, while Postgres does not. Thus, the motivation behind this change is to reduce the impact on our users as CDash instances are being migrated from MySQL to Postgres.
1 parent e47b15e commit 0c51106

File tree

7 files changed

+125
-2
lines changed

7 files changed

+125
-2
lines changed

app/Models/Build.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function comments(): HasMany
211211
*/
212212
public function buildGroups(): BelongsToMany
213213
{
214-
return $this->belongsToMany(BuildGroup::class, 'build2group', 'groupid', 'buildid');
214+
return $this->belongsToMany(BuildGroup::class, 'build2group', 'buildid', 'groupid');
215215
}
216216

217217
/**

app/cdash/app/Model/BuildGroup.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ public function GetGroupIdFromRule(Build $build): int
456456
}
457457

458458
// If we reach this far, none of the rules matched.
459-
// Just use the default group for the build type.
459+
// Try to use the default group for the build type.
460460
$default_model = EloquentBuildGroup::where([
461461
'name' => $build->Type,
462462
'projectid' => $build->ProjectId,
@@ -465,6 +465,19 @@ public function GetGroupIdFromRule(Build $build): int
465465
return $default_model->id;
466466
}
467467

468+
// If that failed, perform a case insensitive search for the build type.
469+
// This is to better support users of CDash instances that migrated from
470+
// MySQL to Postgres.
471+
$type_lower = strtolower($build->Type);
472+
$default_model = EloquentBuildGroup::whereRaw(
473+
'LOWER(name) = ? AND projectid = ?',
474+
[$type_lower, $build->ProjectId]
475+
)->first();
476+
if ($default_model !== null) {
477+
return $default_model->id;
478+
}
479+
480+
// When all else fails, put the build in the Experimental group.
468481
return EloquentBuildGroup::where([
469482
'name' => 'Experimental',
470483
'projectid' => (int) $build->ProjectId,

app/cdash/app/Model/Project.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,17 @@ public function FindByName($name): bool
308308
$this->Fill();
309309
return true;
310310
}
311+
312+
// Do a case insensitive search to more gracefully support users of
313+
// CDash instances that migrated from MySQL to Postgres.
314+
$name_lower = strtolower($this->Name);
315+
$project_row = EloquentProject::whereRaw('LOWER(name) = ?', [$name_lower])->first();
316+
if ($project_row !== null) {
317+
$this->Id = $project_row->id;
318+
$this->Name = $project_row->name;
319+
return true;
320+
}
321+
311322
return false;
312323
}
313324

app/cdash/tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ add_feature_test(/Feature/GraphQL/BuildCommandOutputTypeTest)
214214

215215
add_feature_test(/Feature/Submission/Instrumentation/BuildInstrumentationTest)
216216

217+
add_feature_test(/Feature/Submission/CaseInsensitivity/CaseInsensitivityTest)
218+
217219
add_feature_test(/Feature/RouteAccessTest)
218220

219221
add_feature_test(/Feature/Monitor)

phpstan-baseline.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29440,6 +29440,16 @@ parameters:
2944029440
count: 2
2944129441
path: tests/Feature/SlowPageTest.php
2944229442

29443+
-
29444+
message: "#^Dynamic call to static method Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\HasMany\\<App\\\\Models\\\\Build\\>\\:\\:count\\(\\)\\.$#"
29445+
count: 1
29446+
path: tests/Feature/Submission/CaseInsensitivity/CaseInsensitivityTest.php
29447+
29448+
-
29449+
message: "#^Dynamic call to static method Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\HasMany\\<App\\\\Models\\\\Build\\>\\:\\:first\\(\\)\\.$#"
29450+
count: 1
29451+
path: tests/Feature/Submission/CaseInsensitivity/CaseInsensitivityTest.php
29452+
2944329453
-
2944429454
message: "#^Dynamic call to static method Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\HasMany\\<App\\\\Models\\\\SiteInformation\\>\\:\\:count\\(\\)\\.$#"
2944529455
count: 1
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace Tests\Feature\Submission\CaseInsensitivity;
4+
5+
use App\Models\Build;
6+
use App\Models\BuildGroup;
7+
use App\Models\Project;
8+
use Tests\TestCase;
9+
use Tests\Traits\CreatesProjects;
10+
use Tests\Traits\CreatesSubmissions;
11+
12+
class CaseInsensitivityTest extends TestCase
13+
{
14+
use CreatesProjects;
15+
use CreatesSubmissions;
16+
17+
private BuildGroup $buildgroup;
18+
private Project $project;
19+
20+
protected function setUp(): void
21+
{
22+
parent::setUp();
23+
24+
$this->project = $this->makePublicProject();
25+
26+
// The trait doesn't initialize the default buildgroups for us, so we do it manually
27+
$legacy_project = new \CDash\Model\Project();
28+
$legacy_project->Id = $this->project->id;
29+
$legacy_project->InitialSetup();
30+
31+
$this->project->refresh();
32+
33+
// The XML file associated with this test uses 'my-custom-group' instead.
34+
$this->buildgroup = BuildGroup::create([
35+
'name' => 'My-Custom-Group',
36+
'projectid' => $this->project->id,
37+
]);
38+
}
39+
40+
protected function tearDown(): void
41+
{
42+
$this->project->delete();
43+
44+
parent::tearDown();
45+
}
46+
47+
/**
48+
* Test that submissions are parsed successfully when the case doesn't match
49+
* for their project and build group names.
50+
*/
51+
public function testCaseInsensitiveSubmission(): void
52+
{
53+
$this->submitFiles(strtoupper($this->project->name), [
54+
base_path('tests/Feature/Submission/CaseInsensitivity/data/Build.xml'),
55+
]);
56+
57+
self::assertEquals($this->project->builds()->count(), 1);
58+
59+
$build = $this->project->builds()->first();
60+
self::assertNotNull($build);
61+
62+
$group_from_build = $build->buildGroups()->first();
63+
self::assertNotNull($group_from_build);
64+
65+
self::assertEquals($group_from_build->id, $this->buildgroup->id);
66+
}
67+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Site BuildName="test_case_insensitivity"
3+
BuildStamp="20250522-1338-my-custom-group"
4+
Name="localhost"
5+
Generator="ctest-3.31"
6+
CompilerName=""
7+
CompilerVersion=""
8+
OSName="macOS"
9+
Hostname="localhost"
10+
>
11+
<Build>
12+
<StartDateTime>May 22 09:38 EDT</StartDateTime>
13+
<StartBuildTime>1747921120</StartBuildTime>
14+
<BuildCommand>cmake --build . --config "Release"</BuildCommand>
15+
<Log Encoding="base64" Compression="bin/gzip"/>
16+
<EndDateTime>May 22 09:38 EDT</EndDateTime>
17+
<EndBuildTime>1747921122</EndBuildTime>
18+
<ElapsedMinutes>0</ElapsedMinutes>
19+
</Build>
20+
</Site>

0 commit comments

Comments
 (0)