Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-83990

Courses created via webservice have a default startdate of "0"

XMLWordPrintable

    • MOODLE_404_STABLE
    • MOODLE_404_STABLE, MOODLE_405_STABLE, MOODLE_500_STABLE
    • MDL-83990-404
    • MDL-83990-405
    • Hide

      Prerequisite

      1. Log in as admin
      2. Go to Site administration > Advanced features and set Enable web services to Yes
      3. Go to Site administration > Server > Web services > Manage protocols and enable REST protocol
      4. Go to Site administration > Server > Web services > External services and Add an External service
        Set the following fields:
        • Name: Test Service
        • Enabled: Yes
      5. Add functions to the service "Test Service" and choose the function with the name core_course_create_courses
      6. Go to Site administration > Server > Web services > Manage tokens
      7. Click "Create a token"
      8. Create a token for the admin user, select the service "Test Service"
      9. Save the token and use it to replace the string <TOKEN> in the web service calls below.

      Testing

      1. Navigate to Site administration > Courses >  Default settings > Course default settings
        • Course end date enabled by default: Yes
        • Course duration: 7 days
      2. Run the following command to use default/current time:

        $ curl --silent '<WWWROOT>/webservice/rest/server.php?moodlewsrestformat=json' --data 'wstoken=<TOKEN>&wsfunction=core_course_create_courses&courses[0][fullname]=Course1&courses[0][shortname]=C1&courses[0][categoryid]=1' | python -m "json.tool"
        

      3. Run the following command to use defined time (01/01/25 -> 21/01/25):

        $ curl --silent '<WWWROOT>/webservice/rest/server.php?moodlewsrestformat=json' --data 'wstoken=<TOKEN>&wsfunction=core_course_create_courses&courses[0][fullname]=Course2&courses[0][shortname]=C2&courses[0][categoryid]=1&courses[0][startdate]=1735689600&courses[0][enddate]=1737417600' | python -m "json.tool"
        

      4. Navigate to Reports from user menu
      5. Create report from Courses report source
        • Include default setup: No
      6. In report editor, add the following columns:
        • Course > Course start date
        • Course > Course end date
      7. Confirm Course1 start date is the beginning of the current day, and end date is a week later
      8. Confirm Course2 start date is 1 January 2025, and end date is 21 January 2025
      Show
      Prerequisite Log in as admin Go to Site administration > Advanced features and set Enable web services to Yes Go to Site administration > Server > Web services > Manage protocols and enable REST protocol Go to Site administration > Server > Web services > External services and Add an External service Set the following fields: Name: Test Service Enabled: Yes Add functions to the service " Test Service " and choose the function with the name core_course_create_courses Go to Site administration > Server > Web services > Manage tokens Click " Create a token" Create a token for the admin user, select the service " Test Service " Save the token and use it to replace the string <TOKEN> in the web service calls below. Testing Navigate to Site administration > Courses >  Default settings > Course default settings Course end date enabled by default: Yes Course duration: 7 days Run the following command to use default/current time: $ curl --silent '<WWWROOT>/webservice/rest/server.php?moodlewsrestformat=json' --data 'wstoken=<TOKEN>&wsfunction=core_course_create_courses&courses[0][fullname]=Course1&courses[0][shortname]=C1&courses[0][categoryid]=1' | python -m "json.tool" Run the following command to use defined time (01/01/25 -> 21/01/25): $ curl --silent '<WWWROOT>/webservice/rest/server.php?moodlewsrestformat=json' --data 'wstoken=<TOKEN>&wsfunction=core_course_create_courses&courses[0][fullname]=Course2&courses[0][shortname]=C2&courses[0][categoryid]=1&courses[0][startdate]=1735689600&courses[0][enddate]=1737417600' | python -m "json.tool" Navigate to Reports from user menu Create report from Courses report source Include default setup: No In report editor, add the following columns: Course > Course start date Course > Course end date Confirm Course1 start date is the beginning of the current day, and end date is a week later Confirm Course2 start date is 1 January 2025, and end date is 21 January 2025
    • Hide

      Code verified against automated checks.

      Checked MDL-83990 using repository: https://github.com/paulholden/moodle.git

      More information about this report

      Built on: Tue Mar 18 17:28:17 UTC 2025

      Show
      Code verified against automated checks. Checked MDL-83990 using repository: https://github.com/paulholden/moodle.git MOODLE_404_STABLE (0 errors / 0 warnings) [branch: MDL-83990-404 | CI Job ] MOODLE_405_STABLE (0 errors / 0 warnings) [branch: MDL-83990-405 | CI Job ] main (0 errors / 0 warnings) [branch: MDL-83990 | CI Job ] More information about this report Built on: Tue Mar 18 17:28:17 UTC 2025
    • Show
      Launching automatic jobs for branch MDL-83990 -404 https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/18650/ PHPUnit (sqlsrv) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/63889/ Behat (NonJS - boost and classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/63890/ Behat (Firefox - boost) Launching automatic jobs for branch MDL-83990 -405 https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/18651/ PHPUnit (sqlsrv) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/63891/ Behat (NonJS - boost and classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/63892/ Behat (Firefox - boost) Launching automatic jobs for branch MDL-83990 https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/18652/ PHPUnit (sqlsrv) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/63893/ Behat (NonJS - boost and classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/63894/ Behat (Firefox - boost) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/63895/ Behat (Firefox - classic) https://ci.moodle.org/view/Testing/job/DEV.01%20-%20Developer-requested%20Behat/63896/ App tests (stable app version) Built on: Tue Mar 18 18:25:20 UTC 2025

      When creating a course via webservice (Function core_course_create_courses), the request can specify a startdate. However, if no startdate is given, Moodle defaults to "0" (meaning: 01.01.1970 00:00:00 UTC). This is a surprising default in my opinion.

      As the standard 'weekly sections' format calculates the end date from the start date and number of sections, the newly created course is long over, meaning: The course is not shown as currently running course, and is even suggested for data deletion if there is a retention period set for course data that does not include the 70s.

      I might miss something that makes 0 the "correct" default. Is there a reason, or could we update the API for course creation to set the current date as default?

            pholden Paul Holden
            steditor Stefan Neubert
            Daniel Ziegenberg Daniel Ziegenberg
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Mihail Geshoski Mihail Geshoski
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 10 minutes
                1h 10m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.