MDL-43127 tool_uploadcourse: Empty enrolment method is acceptable
authorFrederic Massart <fred@moodle.com>
Wed, 26 Nov 2014 09:11:35 +0000 (17:11 +0800)
committerFrederic Massart <fred@moodle.com>
Wed, 26 Nov 2014 09:11:35 +0000 (17:11 +0800)
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
admin/tool/uploadcourse/tests/helper_test.php

index 0a3e12e..5ffc677 100644 (file)
@@ -164,7 +164,10 @@ class tool_uploadcourse_helper {
         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;
index 22569e3..b10cdaf 100644 (file)
@@ -79,6 +79,7 @@ class tool_uploadcourse_helper_testcase extends advanced_testcase {
             'enrolment_5_test2' => 'test2',
             'enrolment_5_test1' => 'test1',
             'enrolment_5' => 'flatfile',
+            'enrolment_6' => '',
         );
         $expected = array(
             'self' => array(