From 480c254ac17c23a5a70b4d4091f1c9f4c7743bba Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 26 Nov 2014 17:11:35 +0800 Subject: [PATCH] MDL-43127 tool_uploadcourse: Empty enrolment method is acceptable Without the patch a course would not be created if it contained an enrolment method column with an empty value. e.g.: shortname,fullname,category,enrolment_1,enrolment_1_disable courserestored,Course restored,1,, courserestored2,Course restored 2,manual,1 --- admin/tool/uploadcourse/classes/helper.php | 5 ++++- admin/tool/uploadcourse/tests/helper_test.php | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/admin/tool/uploadcourse/classes/helper.php b/admin/tool/uploadcourse/classes/helper.php index 0a3e12e96982e..5ffc6779e3f2b 100644 --- a/admin/tool/uploadcourse/classes/helper.php +++ b/admin/tool/uploadcourse/classes/helper.php @@ -164,7 +164,10 @@ public static function get_enrolment_data($data, &$errors = array()) { if (!empty($enrolmethods)) { $enrolmentplugins = self::get_enrolment_plugins(); foreach ($enrolmethods as $key => $method) { - if (!array_key_exists($method, $enrolmentplugins)) { + if (empty($method)) { + // The enrolment method is not specified, we skip it. + continue; + } else if (!array_key_exists($method, $enrolmentplugins)) { // Unknown enrolment method. $unknownmethods[] = $method; continue; diff --git a/admin/tool/uploadcourse/tests/helper_test.php b/admin/tool/uploadcourse/tests/helper_test.php index 22569e3a00045..b10cdaf6c64c4 100644 --- a/admin/tool/uploadcourse/tests/helper_test.php +++ b/admin/tool/uploadcourse/tests/helper_test.php @@ -79,6 +79,7 @@ public function test_get_enrolment_data() { 'enrolment_5_test2' => 'test2', 'enrolment_5_test1' => 'test1', 'enrolment_5' => 'flatfile', + 'enrolment_6' => '', ); $expected = array( 'self' => array(