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

Calendar import: Undefined variable in cron when updating calendar subscriptions

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.5.6, 2.6.3, 2.7
    • Fix Version/s: 2.6.5, 2.7.2
    • Component/s: Calendar
    • Labels:
    • Testing Instructions:
      Hide
      • Run unit tests :

        vendor/bin/phpunit core_calendar_lib_testcase calendar/tests/lib_test.php
        

      • As a teacher, go in the calendar and click on the "Manage subscriptions" button
      • Add a new calendar import using a "calendar URL" set "Update interval" to "Daily"
        You can use the moodle.org calendar events URL : https://moodle.org/calendar/export_execute.php?preset_what=all&preset_time=recentupcoming&userid=1&authtoken=a8bcfee2fb868a05357f650bd65dc0699b026524
      • Invalidate the URL you just set, one way or another. I think the easiest way for tests would be to change the value directly in the moodle database (mdl_event_subscriptions). As you are already there, also change the "lastupdated" value so that the update wil be run in the next cron. Another way would be to delete the distant calendar.
      • Purge caches
      • Run the cron. You should see the following line saying there's an error updating the calendar subscription:

        ...
        Updating calendar subscription Test calendar 1 in course 0
        Error updating calendar subscription: The given iCal URL is invalid.
        ...
        

      Show
      Run unit tests : vendor/bin/phpunit core_calendar_lib_testcase calendar/tests/lib_test.php As a teacher, go in the calendar and click on the "Manage subscriptions" button Add a new calendar import using a "calendar URL" set "Update interval" to "Daily" You can use the moodle.org calendar events URL : https://moodle.org/calendar/export_execute.php?preset_what=all&preset_time=recentupcoming&userid=1&authtoken=a8bcfee2fb868a05357f650bd65dc0699b026524 Invalidate the URL you just set, one way or another. I think the easiest way for tests would be to change the value directly in the moodle database (mdl_event_subscriptions). As you are already there, also change the "lastupdated" value so that the update wil be run in the next cron. Another way would be to delete the distant calendar. Purge caches Run the cron. You should see the following line saying there's an error updating the calendar subscription: ... Updating calendar subscription Test calendar 1 in course 0 Error updating calendar subscription: The given iCal URL is invalid. ...
    • Affected Branches:
      MOODLE_25_STABLE, MOODLE_26_STABLE, MOODLE_27_STABLE
    • Fixed Branches:
      MOODLE_26_STABLE, MOODLE_27_STABLE
    • Pull Master Branch:
      MDL-45765-master

      Description

      It seems there's a bug (Undefined variable) in the cron when updating calendar subscriptions and that one or all the URL to update are invalid (404 http error code or anything not 200).

      To reproduce :

      • As a teacher, go in a course calendar and click on the "Manage subscriptions" button
      • Add a new calendar import using a "calendar URL". set "Update interval" to "Daily"
      • Invalidate the URL you just set, one way or another. I think the easiest way for tests would be to change the value directly in the moodle database (mdl_event_subscriptions). As you are already there, also change the "lastupdated" value so that the update wil be run in the next cron
      • Run the cron. Here's a example of what you should see :

        ...
        Updating calendar subscriptions:
        ... started 13:18:59. Current memory use 33.2Mo.
        Updating calendar subscription AME6501 in course 0
        PHP Notice:  Undefined variable: log in /app/apache2/htdocs/moodlebranche/calendar/lib.php on line 3136
        ...
        

        NOTE : Be sure there's no other calendar subscription update cause the problem won't appear

      I dug the code a bit and found what's wrong :
      When a URL is invalid, the calendar_get_icalendar function in calendar/lib.php throws an exception. This exception is catch in calendar_cron function.
      Problem is, when one or all the calendars to update have invalid URL then the "$log" variable is undefined on line "mtrace(trim(strip_tags($log)));"

      Here's an easy way to fix the problem :

               try {
                   $log = calendar_update_subscription_events($sub->id);
               } catch (moodle_exception $ex) {
      -
      +            $log = 'Error when updating calendar subcription';
               }
               mtrace(trim(strip_tags($log)));
           }
      

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                3 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  8/Sep/14