diff --git a/admin/tool/uploaduser/index.php b/admin/tool/uploaduser/index.php index ec37326945e..dcf16e41b09 100644 --- a/admin/tool/uploaduser/index.php +++ b/admin/tool/uploaduser/index.php @@ -1039,6 +1039,7 @@ if ($formdata = $mform2->is_cancelled()) { if ($roleid) { // Find duration and/or enrol status. $timeend = 0; + $timestart = $today; $status = null; if (isset($user->{'enrolstatus'.$i})) { @@ -1054,16 +1055,23 @@ if ($formdata = $mform2->is_cancelled()) { } } + if (!empty($user->{'enroltimestart'.$i})) { + $parsedtimestart = strtotime($user->{'enroltimestart'.$i}); + if ($parsedtimestart !== false) { + $timestart = $parsedtimestart; + } + } + if (!empty($user->{'enrolperiod'.$i})) { $duration = (int)$user->{'enrolperiod'.$i} * 60*60*24; // convert days to seconds if ($duration > 0) { // sanity check - $timeend = $today + $duration; + $timeend = $timestart + $duration; } } else if ($manualcache[$courseid]->enrolperiod > 0) { - $timeend = $today + $manualcache[$courseid]->enrolperiod; + $timeend = $timestart + $manualcache[$courseid]->enrolperiod; } - $manual->enrol_user($manualcache[$courseid], $user->id, $roleid, $today, $timeend, $status); + $manual->enrol_user($manualcache[$courseid], $user->id, $roleid, $timestart, $timeend, $status); $a = new stdClass(); $a->course = $shortname; diff --git a/admin/tool/uploaduser/locallib.php b/admin/tool/uploaduser/locallib.php index e389f8064e4..46b8bc4e3f7 100644 --- a/admin/tool/uploaduser/locallib.php +++ b/admin/tool/uploaduser/locallib.php @@ -204,7 +204,7 @@ function uu_validate_user_upload_columns(csv_import_reader $cir, $stdfields, $pr // hack: somebody wrote uppercase in csv file, but the system knows only lowercase profile field $newfield = $lcfield; - } else if (preg_match('/^(sysrole|cohort|course|group|type|role|enrolperiod|enrolstatus)\d+$/', $lcfield)) { + } else if (preg_match('/^(sysrole|cohort|course|group|type|role|enrolperiod|enrolstatus|enroltimestart)\d+$/', $lcfield)) { // special fields for enrolments $newfield = $lcfield; diff --git a/admin/tool/uploaduser/tests/behat/upload_users.feature b/admin/tool/uploaduser/tests/behat/upload_users.feature index ffd9140ce20..49c72b82f18 100644 --- a/admin/tool/uploaduser/tests/behat/upload_users.feature +++ b/admin/tool/uploaduser/tests/behat/upload_users.feature @@ -145,3 +145,30 @@ Feature: Upload users And I should see "Users created: 4" And I press "Continue" And I log out + + @javascript + Scenario: Upload users setting their enrol date and period + Given the following "courses" exist: + | fullname | shortname | category | + | Maths | math102 | 0 | + # Upload the users. + And I change window size to "large" + And I log in as "admin" + And I navigate to "Users > Accounts > Upload users" in site administration + When I upload "lib/tests/fixtures/upload_users_enrol_date_period.csv" file to "File" filemanager + And I press "Upload users" + Then I should see "Upload users preview" + And I press "Upload users" + # Check user enrolment start date and period + When I am on "Maths" course homepage + Then I navigate to course participants + And I click on "Manual enrolments" "link" in the "Student One" "table_row" + Then I should see "1 January 2019" in the "Enrolment starts" "table_row" + And I should not see "Enrolment ends" + And I click on "Close" "button" + Then I click on "Manual enrolments" "link" in the "Student Two" "table_row" + And I should see "2 January 2020" in the "Enrolment starts" "table_row" + And I should see "12 January 2020" in the "Enrolment ends" "table_row" + And I click on "Close" "button" + And I log out + diff --git a/lib/tests/fixtures/upload_users_enrol_date_period.csv b/lib/tests/fixtures/upload_users_enrol_date_period.csv new file mode 100644 index 00000000000..a1d0c22eca5 --- /dev/null +++ b/lib/tests/fixtures/upload_users_enrol_date_period.csv @@ -0,0 +1,3 @@ +username,password,firstname,lastname,email,course1,enroltimestart1,enrolperiod1 +student1,Student1#,Student,One,student1@example.com,math102,2019-01-01, +student2,Student2#,Student,Two,student2@example.com,math102,2020-01-02,10