From e7bc91579b2b389ae2636b2cdb925ea9d8593a64 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Wed, 23 Jul 2014 14:56:52 +0800 Subject: [PATCH] MDL-41639 tool_uploaduser: Automatically create cohorts if not found --- admin/tool/uploaduser/index.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/admin/tool/uploaduser/index.php b/admin/tool/uploaduser/index.php index b50156ffc2f..e0bddc3c412 100644 --- a/admin/tool/uploaduser/index.php +++ b/admin/tool/uploaduser/index.php @@ -850,6 +850,15 @@ if ($formdata = $mform2->is_cancelled()) { $cohort = $DB->get_record('cohort', array('id'=>$addcohort)); } else { $cohort = $DB->get_record('cohort', array('idnumber'=>$addcohort)); + if (empty($cohort) && has_capability('moodle/cohort:manage', context_system::instance())) { + // Cohort was not found. Create a new one. + $cohortid = cohort_add_cohort((object)array( + 'idnumber' => $addcohort, + 'name' => $addcohort, + 'contextid' => context_system::instance()->id + )); + $cohort = $DB->get_record('cohort', array('id'=>$cohortid)); + } } if (empty($cohort)) {