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

E_WARNING in core_calendar_get_calendar_events web service function

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      To reproduce the error checkout the first commit and run vendor/bin/phpunit core_calendar_externallib_testcase calendar/tests/externallib_test.php

      You should get an error similar to:

      1) core_calendar_externallib_testcase::test_get_calendar_events Undefined variable: courses

      With the full commit applied run: vendor/bin/phpunit core_calendar_externallib_testcase calendar/tests/externallib_test.php

      All the tests should now pass.

      Show
      To reproduce the error checkout the first commit and run vendor/bin/phpunit core_calendar_externallib_testcase calendar/tests/externallib_test.php You should get an error similar to: 1) core_calendar_externallib_testcase::test_get_calendar_events Undefined variable: courses With the full commit applied run: vendor/bin/phpunit core_calendar_externallib_testcase calendar/tests/externallib_test.php All the tests should now pass.
    • Affected Branches:
      MOODLE_27_STABLE, MOODLE_28_STABLE, MOODLE_29_STABLE
    • Fixed Branches:
      MOODLE_28_STABLE, MOODLE_29_STABLE
    • Pull from Repository:
    • Pull Master Branch:

      Description

      If the user making the call to core_calendar_get_calendar_events does not have the 'moodle/calendar:manageentries' capability then an array called $courses is not generated. This leads to an E_WARNING in_array() expects parameter 2 to be array, null given

      The issue is in core_calendar_external::get_calendar_events() in calendar/externallib.php

      The code that does not set the $courses array:

              // Let us findout courses that we can return events from.
              if (!$hassystemcap) {
                  foreach ($params['events']['courseids'] as $id) {
                     try {
                          $context = context_course::instance($id);
                          self::validate_context($context);
                          $funcparam['courses'][] = $id;
                      } catch (Exception $e) {
                          $warnings[] = array(
                              'item' => 'course',
                              'itemid' => $id,
                              'warningcode' => 'nopermissions',
                              'message' => 'No access rights in course context '.$e->getMessage().$e->getTraceAsString()
                          );
                          continue;
                      }
                  }
              } else {
                  $courses = $params['events']['courseids'];
                  $funcparam['courses'] = $courses;
              }
      

      The code that generates the warning:

                      if (($eventobj->courseid == $SITE->id) ||
                                  (!empty($eventobj->groupid) && in_array($eventobj->groupid, $groups)) ||
                                  (!empty($eventobj->courseid) && in_array($eventobj->courseid, $courses)) ||
                                  ($USER->id == $eventobj->userid) ||
                                  (calendar_edit_event_allowed($eventid))) {
                          $events[$eventid] = $event;
                      } else {
                          $warnings[] = array('item' => $eventid, 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to view this event');
                      }
      

      I think this may mean that course events may not show up correctly in the web service.

        Attachments

          Activity

            People

            Assignee:
            nmagill Neill Magill
            Reporter:
            nmagill Neill Magill
            Peer reviewer:
            Jun Pataleta
            Integrator:
            Eloy Lafuente (stronk7)
            Tester:
            Eloy Lafuente (stronk7)
            Participants:
            Component watchers:
            Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              11/Jan/16