From b23aa8fc777b8431c4cb0e8d1d126ccf4a5d392e Mon Sep 17 00:00:00 2001 From: William Allen <16820599+williamjallen@users.noreply.github.com> Date: Tue, 30 Dec 2025 17:04:13 -0500 Subject: [PATCH] Add foreign key constraint to project logo ID --- app/cdash/app/Model/Project.php | 10 ++++----- app/cdash/include/common.php | 2 +- ...ject_logo_image_foreign_key_constraint.php | 22 +++++++++++++++++++ phpstan-baseline.neon | 6 ----- resources/js/vue/components/EditProject.vue | 6 ++--- resources/views/components/header.blade.php | 2 +- tests/Spec/edit-project.spec.js | 2 +- 7 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 database/migrations/2025_12_30_213518_project_logo_image_foreign_key_constraint.php diff --git a/app/cdash/app/Model/Project.php b/app/cdash/app/Model/Project.php index a2819bdc3c..6f187ffdca 100644 --- a/app/cdash/app/Model/Project.php +++ b/app/cdash/app/Model/Project.php @@ -50,7 +50,7 @@ class Project public $BugTrackerUrl; public $BugTrackerNewIssueUrl; public $BugTrackerType; - public $ImageId; + public ?int $ImageId = null; public $Public; public $CoverageThreshold; public $TestingDataUrl; @@ -146,7 +146,7 @@ public function Save(): bool 'testtimemaxstatus' => (int) $this->TestTimeMaxStatus, 'emailmaxitems' => (int) $this->EmailMaxItems, 'emailmaxchars' => (int) $this->EmailMaxChars, - 'imageid' => $this->ImageId ?? 0, + 'imageid' => $this->ImageId, 'ldapfilter' => $this->LdapFilter, 'banner' => $this->Banner, ]); @@ -180,13 +180,13 @@ public function FindByName($name): bool } /** Get the logo id */ - private function GetLogoId(): int + private function GetLogoId(): ?int { if (!$this->Filled) { $this->Fill(); } - return $this->Id > 0 ? $this->ImageId : 0; + return $this->Id > 0 ? $this->ImageId : null; } /** Fill in all the information from the database */ @@ -297,7 +297,7 @@ public function AddLogo($contents, string $filetype) $image->Extension = $filetype; $imgid = $this->GetLogoId(); - if ($imgid > 0) { + if ($imgid !== null) { $image->Id = $imgid; } diff --git a/app/cdash/include/common.php b/app/cdash/include/common.php index 3c790d3f44..75c5c179fa 100644 --- a/app/cdash/include/common.php +++ b/app/cdash/include/common.php @@ -601,7 +601,7 @@ function get_dashboard_JSON($projectname, $date, &$response): void $response['public'] = $project->Public; $response['previousdate'] = $previousdate; $response['nextdate'] = $nextdate; - $response['logoid'] = $project->ImageId ?? 0; + $response['logoid'] = $project->ImageId; $response['nightlytime'] = date('H:i T', strtotime($project_array['nightlytime'])); if (empty($project_array['homeurl'])) { $response['home'] = 'index.php?project=' . urlencode($project_array['name']); diff --git a/database/migrations/2025_12_30_213518_project_logo_image_foreign_key_constraint.php b/database/migrations/2025_12_30_213518_project_logo_image_foreign_key_constraint.php new file mode 100644 index 0000000000..a8013dc4f0 --- /dev/null +++ b/database/migrations/2025_12_30_213518_project_logo_image_foreign_key_constraint.php @@ -0,0 +1,22 @@ + Current logo: - + [none] { - if (response.data.imageid > 0) { + if (response.data.imageid !== null) { this.previewLogo = null; this.uploadedLogo = null; // Use a decache to force the logo to refresh even if the imageid didn't change. diff --git a/resources/views/components/header.blade.php b/resources/views/components/header.blade.php index e8c4d10e6f..c40dbdeb4e 100755 --- a/resources/views/components/header.blade.php +++ b/resources/views/components/header.blade.php @@ -50,7 +50,7 @@ href="{{ url('/')}}" @endif > - @if(isset($project) && $logoid > 0) + @if(isset($project) && $logoid !== null) @else diff --git a/tests/Spec/edit-project.spec.js b/tests/Spec/edit-project.spec.js index 36d90e74d9..30bc0def6a 100644 --- a/tests/Spec/edit-project.spec.js +++ b/tests/Spec/edit-project.spec.js @@ -62,7 +62,7 @@ beforeEach(() => { ErrorsFilter: '', Filled: true, Id: 1, - ImageId: 0, + ImageId: 1, MaxUploadQuota: 10, Name: 'MyTestingProject', NightlyTime: '01:00:00 UTC',