User:Jonathan Harker/Import Calendar

From MoodleDocs

MDL-16660 - Import or subscribe to iCal feed in Moodle calendar. This is proposed for inclusion in core for Moodle 2.4, but in the meantime it is available as a local customisation for 2.3 and below.

This feature adds an extra form on the calendar view for importing events (that conform to the RFC-2445 iCalendar format) into the Moodle calendar, either from a calendar file, or by adding a subscription to a remote calendar URL.

Install as a local customisation

On versions 2.3 and below, this is available as a local customisation which should upon installation:

  • add a mdl_event_subscriptions table,
  • add a subscriptionid column to the mdl_event table, and
  • alter the uuid column of the mdl_event table to correctly handle RFC-2445 UIDs.

The code is available as a single commit on the Catalyst git server:

The commit needs to be cherry-picked into your Moodle code, and involves a small change to core in the calendar directory. If you have git, you can do this:

git cherry-pick MDL-16660_23_local1

And use the appropriate branch for whether you have Moodle 2.3 or 2.2 installed. If you don't have git, you can download the snapshot on this branch and copy the


directory into your Moodle's


directory, and make these changes to




manually. Do not simply overwrite files in the


directory with the ones from this branch, as that will likely introduce other changes from the history, or revert newer ones on your Moodle.

Import form in calendar view

The import subscription form should only appear on a calendar view for those users who already have the capability to add calendar events to that calendar.

Subscriptions list

The import calendar form should show you a list of existing subscriptions, if any. This list allows you to

  • Update the poll interval. This can be never, hourly, daily, weekly, monthly, or annually. Choose one from the list and click the Update button for that subscription.
  • Remove the subscription. This will also remove any events added by the subscription from the calendar. Click the Remove button.

Import Calendar form

This form will let you add a subscription from a calendar URL, or import events from an uploaded calendar file.

  • Calendar name: The name of the calendar. This is mandatory and will not accept a blank value.
  • Import from: choose either a URL or a file.
  • Calendar URL: a URL to an external ics calendar file (if you chose URL)
  • Calendar file: choose or upload a calendar file using the standard Moodle file browser (if you chose file).
  • Poll interval: Choose a value from never, hourly, daily, weekly, monthly, or annually. This field has no effect when adding events from a file.
  • Type of event: This allows you to select which calendar the events should be added to - the same as when adding a single event normally. The list should display only those calendars you have permission to add events to - at either a user, group, course or site level.
  • Group: Select which group to add events to, if you have permission to add events to one or more groups. This will show only the groups that you have permission to add events to.
  • Click Add to import the events from the calendar file, or add the calendar subscription.

Poll interval

The cron task should update calendar subscriptions as recorded in the mdl_event_subscriptions table, and as controlled by the poll interval. In the database, pollinterval is stored as a number of seconds, and calculated in cron using the current timestamp and the lastupdated field. In this way, monthly is actually anually divided by 12, rather than a strict calendar month.