diff --git a/app/Utils/TestCreator.php b/app/Utils/TestCreator.php index 2d3e239765..a4c8b42e96 100755 --- a/app/Utils/TestCreator.php +++ b/app/Utils/TestCreator.php @@ -24,6 +24,7 @@ use CDash\Model\Build; use CDash\Model\Image; use ErrorException; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; /** @@ -136,46 +137,46 @@ public function create(Build $build): void } } - $outputid = TestOutput::firstOrCreate([ - 'path' => $this->testPath, - 'command' => $this->testCommand, - 'output' => $this->testOutput, - ])->id; - - // build2test - $buildtest = new Test(); - $buildtest->buildid = $build->Id; - $buildtest->outputid = $outputid; - $buildtest->status = $this->testStatus; - $buildtest->details = $this->testDetails; - $buildtest->time = "$this->buildTestTime"; - $buildtest->testname = $this->testName; - $buildtest->starttime = $this->testStartTime; - - // Note: the newstatus column is currently handled in - // ctestparserutils::compute_test_difference. This gets updated when we call - // Build::ComputeTestTiming. - $buildtest->save(); - - foreach ($this->measurements as $measurement) { - $measurement->testid = $buildtest->id; - $measurement->save(); - } + DB::transaction(function () use ($build): void { + $outputid = TestOutput::select('id')->firstOrCreate([ + 'path' => $this->testPath, + 'command' => $this->testCommand, + 'output' => $this->testOutput, + ])->id; + + // Note: the newstatus column is currently handled in + // ctestparserutils::compute_test_difference. This gets updated when we call + // Build::ComputeTestTiming. + $buildtest = Test::create([ + 'buildid' => $build->Id, + 'outputid' => $outputid, + 'status' => $this->testStatus, + 'details' => $this->testDetails, + 'time' => "$this->buildTestTime", + 'testname' => $this->testName, + 'starttime' => $this->testStartTime, + ]); + + foreach ($this->measurements as $measurement) { + $measurement->testid = $buildtest->id; + $measurement->save(); + } - // Give measurements to the buildtest model so we can properly calculate - // proctime later on. - $buildtest->measurements = $this->measurements; - $build->AddTest($buildtest); + // Give measurements to the buildtest model so we can properly calculate + // proctime later on. + $buildtest->measurements = $this->measurements; + $build->AddTest($buildtest); - foreach ($this->labels as $label) { - $label->Test = $buildtest; - $label->Insert(); - $buildtest->addLabel($label); - } + foreach ($this->labels as $label) { + $label->Test = $buildtest; + $label->Insert(); + $buildtest->addLabel($label); + } - // test2image - foreach ($this->images as $image) { - $this->saveImage($image, $buildtest->id); - } + // test2image + foreach ($this->images as $image) { + $this->saveImage($image, $buildtest->id); + } + }); } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 761d5a7843..1231fd901c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -7050,12 +7050,6 @@ parameters: count: 1 path: app/Utils/TestCreator.php - - - rawMessage: 'Property App\Models\Test::$time (float) does not accept string.' - identifier: assign.propertyType - count: 1 - path: app/Utils/TestCreator.php - - rawMessage: Property App\Utils\TestCreator::$alreadyCompressed has no type specified. identifier: missingType.property