Skip to content

Commit

Permalink
MDL-83990 course: ensure course start/end dates set in external call.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Jan 29, 2025
1 parent c5d94d2 commit 228ef37
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion course/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,8 @@ public static function create_courses($courses) {
$params = self::validate_parameters(self::create_courses_parameters(),
array('courses' => $courses));

$courseconfig = get_config('moodlecourse');

$availablethemes = core_component::get_plugin_list('theme');
$availablelangs = get_string_manager()->get_list_of_translations();

Expand All @@ -967,6 +969,14 @@ public static function create_courses($courses) {
throw new moodle_exception('errorinvalidparam', 'webservice', '', 'shortname');
}

// Make sure start/end date are correctly set.
if (!array_key_exists('startdate', $course)) {
$course['startdate'] = usergetmidnight(time());
}
if (!array_key_exists('enddate', $course) && $courseconfig->courseenddateenabled) {
$course['enddate'] = $course['startdate'] + $courseconfig->courseduration;
}

// Make sure lang is valid
if (array_key_exists('lang', $course)) {
if (empty($availablelangs[$course['lang']])) {
Expand Down Expand Up @@ -995,7 +1005,6 @@ public static function create_courses($courses) {
}

//set default value for completion
$courseconfig = get_config('moodlecourse');
if (completion_info::is_enabled_for_site()) {
if (!array_key_exists('enablecompletion', $course)) {
$course['enablecompletion'] = $courseconfig->enablecompletion;
Expand Down

0 comments on commit 228ef37

Please sign in to comment.