|
2 | 2 |
|
3 | 3 | namespace App\Http\Controllers; |
4 | 4 |
|
| 5 | +use App\Enums\SubmissionValidationType; |
5 | 6 | use App\Exceptions\BadSubmissionException; |
6 | 7 | use App\Jobs\ProcessSubmission; |
7 | 8 | use App\Models\Site; |
@@ -73,7 +74,7 @@ private function submitProcess(): Response |
73 | 74 | @set_time_limit(0); |
74 | 75 |
|
75 | 76 | $statusarray = []; |
76 | | - |
| 77 | + $responseMessage = ''; |
77 | 78 | $projectname = $_GET['project'] ?? ''; |
78 | 79 |
|
79 | 80 | if (strlen($projectname) === 0) { |
@@ -146,34 +147,29 @@ private function submitProcess(): Response |
146 | 147 | // Figure out what type of XML file this is. |
147 | 148 | $stored_filename = 'inbox/' . $filename; |
148 | 149 | $xml_info = []; |
149 | | - try { |
150 | | - $xml_info = SubmissionUtils::get_xml_type(Storage::readStream($stored_filename), $stored_filename); |
151 | | - } catch (BadSubmissionException $e) { |
152 | | - $xml_info['xml_handler'] = ''; |
153 | | - $message = "Could not determine submission file type for: '{$stored_filename}'"; |
154 | | - Log::warning($message); |
155 | | - if ((bool) config('cdash.validate_xml_submissions') === true) { |
156 | | - $this->failProcessing($filename, 400, $message); |
157 | | - } |
158 | | - } |
| 150 | + $xml_info = SubmissionUtils::get_xml_type(Storage::readStream($stored_filename), $stored_filename); |
| 151 | + |
159 | 152 | if ($xml_info['xml_handler'] !== '') { |
160 | 153 | // If validation is enabled and if this file has a corresponding schema, validate it |
161 | 154 | $validation_errors = []; |
162 | 155 | try { |
163 | 156 | $validation_errors = $xml_info['xml_handler']::validate($stored_filename); |
164 | 157 | } catch (FileNotFoundException|UnableToReadFile $e) { |
165 | | - Log::warning($e->getMessage()); |
166 | | - if ((bool) config('cdash.validate_xml_submissions') === true) { |
167 | | - $this->failProcessing($filename, 400, "XML validation failed for $filename:" . PHP_EOL . $e->getMessage()); |
168 | | - } |
| 158 | + $message = $e->getMessage(); |
| 159 | + report($message); |
| 160 | + $this->failProcessing($filename, 500, "Unable to read file for validation $filename:" . PHP_EOL . $message); |
169 | 161 | } |
170 | 162 | if (count($validation_errors) > 0) { |
171 | 163 | $error_string = implode(PHP_EOL, $validation_errors); |
172 | | - |
| 164 | + $message = "XML validation failed: Found issues with file $filename:"; |
173 | 165 | // We always log validation failures, but we only send messages back to the client if configured to do so |
174 | | - Log::warning("Submission validation failed for file '$filename':" . PHP_EOL); |
175 | | - if ((bool) config('cdash.validate_xml_submissions') === true) { |
176 | | - $this->failProcessing($filename, 400, "XML validation failed: rejected file $filename:" . PHP_EOL . $error_string); |
| 166 | + Log::info($message); |
| 167 | + $fullMessage = $message . PHP_EOL . $error_string; |
| 168 | + if (config('cdash.validate_submissions') === SubmissionValidationType::REJECT) { |
| 169 | + $this->failProcessing($filename, 400, $fullMessage); |
| 170 | + } |
| 171 | + if (config('cdash.validate_submissions') === SubmissionValidationType::WARN) { |
| 172 | + $responseMessage .= $fullMessage; |
177 | 173 | } |
178 | 174 | } |
179 | 175 | } |
@@ -219,8 +215,12 @@ private function submitProcess(): Response |
219 | 215 | Artisan::call('submission:queue'); |
220 | 216 | } |
221 | 217 |
|
222 | | - $statusarray['status'] = 'OK'; |
223 | 218 | $statusarray['message'] = ''; |
| 219 | + if ($responseMessage !== '') { |
| 220 | + $statusarray['message'] = $responseMessage; |
| 221 | + } |
| 222 | + |
| 223 | + $statusarray['status'] = 'OK'; |
224 | 224 | if ($buildid !== null) { |
225 | 225 | $statusarray['buildId'] = $buildid; |
226 | 226 | } |
|
0 commit comments