11
11
use App \Entity \Problem ;
12
12
use App \Entity \Submission ;
13
13
use App \Entity \SubmissionFile ;
14
+ use App \Entity \SubmissionSource ;
14
15
use App \Entity \Team ;
15
16
use App \Entity \User ;
16
17
use App \Utils \FreezeData ;
@@ -438,7 +439,7 @@ public function submitSolution(
438
439
Contest |int $ contest ,
439
440
Language |string $ language ,
440
441
array $ files ,
441
- ? string $ source = null ,
442
+ SubmissionSource $ source = SubmissionSource:: UNKNOWN ,
442
443
?string $ juryMember = null ,
443
444
Submission |int |null $ originalSubmission = null ,
444
445
?string $ entryPoint = null ,
@@ -569,7 +570,7 @@ public function submitSolution(
569
570
570
571
if (!empty ($ entryPoint ) && !preg_match (self ::FILENAME_REGEX , $ entryPoint )) {
571
572
$ message = sprintf ("Entry point '%s' contains illegal characters. " , $ entryPoint );
572
- if ($ forceImportInvalid || $ source === ' shadowing ' ) {
573
+ if ($ forceImportInvalid || $ source === SubmissionSource:: SHADOWING ) {
573
574
$ importError = $ message ;
574
575
} else {
575
576
return null ;
@@ -610,15 +611,15 @@ public function submitSolution(
610
611
}
611
612
if (!preg_match (self ::FILENAME_REGEX , $ file ->getClientOriginalName ())) {
612
613
$ message = sprintf ("Illegal filename '%s'. " , $ file ->getClientOriginalName ());
613
- if ($ forceImportInvalid || $ source === ' shadowing ' ) {
614
+ if ($ forceImportInvalid || $ source === SubmissionSource:: SHADOWING ) {
614
615
$ importError = $ message ;
615
616
} else {
616
617
return null ;
617
618
}
618
619
}
619
620
$ totalSize += $ file ->getSize ();
620
621
621
- if ($ source !== ' shadowing ' && $ language ->getFilterCompilerFiles ()) {
622
+ if ($ source !== SubmissionSource:: SHADOWING && $ language ->getFilterCompilerFiles ()) {
622
623
$ matchesExtension = false ;
623
624
foreach ($ language ->getExtensions () as $ extension ) {
624
625
if (str_ends_with ($ file ->getClientOriginalName (), '. ' . $ extension )) {
@@ -632,7 +633,7 @@ public function submitSolution(
632
633
}
633
634
}
634
635
635
- if ($ source !== ' shadowing ' && $ language ->getFilterCompilerFiles () && $ extensionMatchCount === 0 ) {
636
+ if ($ source !== SubmissionSource:: SHADOWING && $ language ->getFilterCompilerFiles () && $ extensionMatchCount === 0 ) {
636
637
$ message = sprintf (
637
638
"None of the submitted files match any of the allowed " .
638
639
"extensions for %s (allowed: %s) " ,
@@ -647,7 +648,7 @@ public function submitSolution(
647
648
648
649
if ($ totalSize > $ sourceSize * 1024 ) {
649
650
$ message = sprintf ("Submission file(s) are larger than %d kB. " , $ sourceSize );
650
- if ($ forceImportInvalid || $ source === ' shadowing ' ) {
651
+ if ($ forceImportInvalid || $ source === SubmissionSource:: SHADOWING ) {
651
652
$ importError = $ message ;
652
653
} else {
653
654
return null ;
@@ -660,7 +661,7 @@ public function submitSolution(
660
661
// SQL transaction time below.
661
662
// Only do this for problem import submissions, as we do not want this for re-submitted submissions nor
662
663
// submissions that come through the API, e.g. when doing a replay of an old contest.
663
- if ($ this ->dj ->checkrole ('jury ' ) && $ source == ' problem import ' ) {
664
+ if ($ this ->dj ->checkrole ('jury ' ) && $ source === SubmissionSource:: PROBLEM_IMPORT ) {
664
665
$ results = null ;
665
666
foreach ($ files as $ file ) {
666
667
$ fileResult = self ::getExpectedResults (file_get_contents ($ file ->getRealPath ()),
@@ -726,7 +727,7 @@ public function submitSolution(
726
727
$ this ->em ->flush ();
727
728
728
729
$ this ->dj ->maybeCreateJudgeTasks ($ judging ,
729
- $ source === ' problem import ' ? JudgeTask::PRIORITY_LOW : JudgeTask::PRIORITY_DEFAULT );
730
+ $ source === SubmissionSource:: PROBLEM_IMPORT ? JudgeTask::PRIORITY_LOW : JudgeTask::PRIORITY_DEFAULT );
730
731
}
731
732
732
733
$ this ->em ->wrapInTransaction (function () use ($ contest , $ submission ) {
@@ -755,7 +756,7 @@ public function submitSolution(
755
756
$ language ->getLangid (), $ problem ->getProblem ()->getProbid ()));
756
757
757
758
$ this ->dj ->auditlog ('submission ' , $ submission ->getSubmitid (), 'added ' ,
758
- 'via ' . ( $ source ?? ' unknown ' ) , null , $ contest ->getCid ());
759
+ 'via ' . $ source-> value , null , $ contest ->getCid ());
759
760
760
761
if (Utils::difftime ((float )$ contest ->getEndtime (), $ submitTime ) <= 0 ) {
761
762
$ this ->logger ->info (
0 commit comments