diff --git a/app/Http/Controllers/SubmissionController.php b/app/Http/Controllers/SubmissionController.php index 2ffc192b80..77d304fd55 100644 --- a/app/Http/Controllers/SubmissionController.php +++ b/app/Http/Controllers/SubmissionController.php @@ -10,6 +10,7 @@ use App\Rules\ProjectNameRule; use App\Utils\AuthTokenUtil; use App\Utils\SubmissionUtils; +use App\Utils\SystemUtils; use App\Utils\UnparsedSubmissionProcessor; use CDash\Model\Build; use CDash\Model\Project; @@ -129,12 +130,7 @@ private function submitProcess(): Response } // Check if we can connect to the database before proceeding any further. - try { - DB::connection()->getPdo(); - if (app()->isDownForMaintenance()) { - throw new Exception(); - } - } catch (Exception) { + if (!SystemUtils::isDatabaseOnline()) { // Write a marker file so we know to process these files when the DB comes back up. if (!Storage::exists('DB_WAS_DOWN')) { Storage::put('DB_WAS_DOWN', ''); diff --git a/app/Utils/SystemUtils.php b/app/Utils/SystemUtils.php new file mode 100644 index 0000000000..67de722da2 --- /dev/null +++ b/app/Utils/SystemUtils.php @@ -0,0 +1,26 @@ +isDownForMaintenance()) { + return false; + } + + try { + DB::connection()->getPdo(); + return true; + } catch (Exception) { + return false; + } + } +} diff --git a/app/Utils/UnparsedSubmissionProcessor.php b/app/Utils/UnparsedSubmissionProcessor.php index 7d5a07966e..37bfb7a5de 100644 --- a/app/Utils/UnparsedSubmissionProcessor.php +++ b/app/Utils/UnparsedSubmissionProcessor.php @@ -86,7 +86,7 @@ public function postSubmit(): JsonResponse // Thus function will throw an exception if invalid data provided $this->parseBuildMetadata(); - if ($this->checkDatabaseConnection() && !app()->isDownForMaintenance()) { + if (SystemUtils::isDatabaseOnline()) { return $this->initializeBuild(); } @@ -213,7 +213,7 @@ public function putSubmitFile(): JsonResponse $this->parseDataFileParameters(); $ext = pathinfo($this->backupfilename, PATHINFO_EXTENSION); - $db_up = $this->checkDatabaseConnection() && !app()->isDownForMaintenance(); + $db_up = SystemUtils::isDatabaseOnline(); if ($db_up) { if (!is_numeric($this->buildid) || $this->buildid < 1) { abort(Response::HTTP_NOT_FOUND, 'Build not found'); @@ -370,17 +370,6 @@ public function parseDataFileParameters(): void $this->getAuthTokenHash(); } - /** Check if CDash's database is down. */ - private function checkDatabaseConnection(): bool - { - try { - DB::connection()->getPdo(); - return true; - } catch (Exception) { - return false; - } - } - /** Write build metadata to disk in JSON format. */ private function serializeBuildMetadata(string $uuid): void {