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

E_WARNING in core_calendar_get_calendar_events web service function

    XMLWordPrintable

Details

    • MOODLE_27_STABLE, MOODLE_28_STABLE, MOODLE_29_STABLE
    • MOODLE_28_STABLE, MOODLE_29_STABLE
    • 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.

    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

            nmagill Neill Magill
            nmagill Neill Magill
            Jun Pataleta Jun Pataleta
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Andrew Lyons, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              11/Jan/16