Skip to content

Fallback to case insensitive searching in some cases #2895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion app/Models/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function comments(): HasMany
*/
public function buildGroups(): BelongsToMany
{
return $this->belongsToMany(BuildGroup::class, 'build2group', 'groupid', 'buildid');
return $this->belongsToMany(BuildGroup::class, 'build2group', 'buildid', 'groupid');
}

/**
Expand Down
15 changes: 14 additions & 1 deletion app/cdash/app/Model/BuildGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public function GetGroupIdFromRule(Build $build): int
}

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

// If that failed, perform a case insensitive search for the build type.
// This is to better support users of CDash instances that migrated from
// MySQL to Postgres.
$type_lower = strtolower($build->Type);
$default_model = EloquentBuildGroup::whereRaw(
'LOWER(name) = ? AND projectid = ?',
[$type_lower, $build->ProjectId]
)->first();
if ($default_model !== null) {
return $default_model->id;
}

// When all else fails, put the build in the Experimental group.
return EloquentBuildGroup::where([
'name' => 'Experimental',
'projectid' => (int) $build->ProjectId,
Expand Down
11 changes: 11 additions & 0 deletions app/cdash/app/Model/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,17 @@ public function FindByName($name): bool
$this->Fill();
return true;
}

// Do a case insensitive search to more gracefully support users of
// CDash instances that migrated from MySQL to Postgres.
$name_lower = strtolower($this->Name);
$project_row = EloquentProject::whereRaw('LOWER(name) = ?', [$name_lower])->first();
if ($project_row !== null) {
$this->Id = $project_row->id;
$this->Name = $project_row->name;
return true;
}

return false;
}

Expand Down
2 changes: 2 additions & 0 deletions app/cdash/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ add_feature_test(/Feature/GraphQL/BuildCommandOutputTypeTest)

add_feature_test(/Feature/Submission/Instrumentation/BuildInstrumentationTest)

add_feature_test(/Feature/Submission/CaseInsensitivity/CaseInsensitivityTest)

add_feature_test(/Feature/RouteAccessTest)

add_feature_test(/Feature/Monitor)
Expand Down
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -29440,6 +29440,16 @@ parameters:
count: 2
path: tests/Feature/SlowPageTest.php

-
message: "#^Dynamic call to static method Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\HasMany\\<App\\\\Models\\\\Build\\>\\:\\:count\\(\\)\\.$#"
count: 1
path: tests/Feature/Submission/CaseInsensitivity/CaseInsensitivityTest.php

-
message: "#^Dynamic call to static method Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\HasMany\\<App\\\\Models\\\\Build\\>\\:\\:first\\(\\)\\.$#"
count: 1
path: tests/Feature/Submission/CaseInsensitivity/CaseInsensitivityTest.php

-
message: "#^Dynamic call to static method Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\HasMany\\<App\\\\Models\\\\SiteInformation\\>\\:\\:count\\(\\)\\.$#"
count: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Tests\Feature\Submission\CaseInsensitivity;

use App\Models\Build;
use App\Models\BuildGroup;
use App\Models\Project;
use Tests\TestCase;
use Tests\Traits\CreatesProjects;
use Tests\Traits\CreatesSubmissions;

class CaseInsensitivityTest extends TestCase
{
use CreatesProjects;
use CreatesSubmissions;

private BuildGroup $buildgroup;
private Project $project;

protected function setUp(): void
{
parent::setUp();

$this->project = $this->makePublicProject();

// The trait doesn't initialize the default buildgroups for us, so we do it manually
$legacy_project = new \CDash\Model\Project();
$legacy_project->Id = $this->project->id;
$legacy_project->InitialSetup();

$this->project->refresh();

// The XML file associated with this test uses 'my-custom-group' instead.
$this->buildgroup = BuildGroup::create([
'name' => 'My-Custom-Group',
'projectid' => $this->project->id,
]);
}

protected function tearDown(): void
{
$this->project->delete();

parent::tearDown();
}

/**
* Test that submissions are parsed successfully when the case doesn't match
* for their project and build group names.
*/
public function testCaseInsensitiveSubmission(): void
{
$this->submitFiles(strtoupper($this->project->name), [
base_path('tests/Feature/Submission/CaseInsensitivity/data/Build.xml'),
]);

self::assertEquals($this->project->builds()->count(), 1);

$build = $this->project->builds()->first();
self::assertNotNull($build);

$group_from_build = $build->buildGroups()->first();
self::assertNotNull($group_from_build);

self::assertEquals($group_from_build->id, $this->buildgroup->id);
}
}
20 changes: 20 additions & 0 deletions tests/Feature/Submission/CaseInsensitivity/data/Build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<Site BuildName="test_case_insensitivity"
BuildStamp="20250522-1338-my-custom-group"
Name="localhost"
Generator="ctest-3.31"
CompilerName=""
CompilerVersion=""
OSName="macOS"
Hostname="localhost"
>
<Build>
<StartDateTime>May 22 09:38 EDT</StartDateTime>
<StartBuildTime>1747921120</StartBuildTime>
<BuildCommand>cmake --build . --config "Release"</BuildCommand>
<Log Encoding="base64" Compression="bin/gzip"/>
<EndDateTime>May 22 09:38 EDT</EndDateTime>
<EndBuildTime>1747921122</EndBuildTime>
<ElapsedMinutes>0</ElapsedMinutes>
</Build>
</Site>