Note: You are currently viewing documentation for Moodle 3.3. Up-to-date documentation for the latest stable version of Moodle is probably available here: Themes 2.0 adding upgrade code.

Development:Themes 2.0 adding upgrade code

From MoodleDocs
Revision as of 02:04, 29 March 2011 by Sam Hemelryk (talk | contribs) (New page: As theme's have got considerably more advanced in Moodle 2 there is now on occasion a need to write upgrade code for a theme. This quick tutorial looks at just how to do that. ==Why?== As...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

As theme's have got considerably more advanced in Moodle 2 there is now on occasion a need to write upgrade code for a theme. This quick tutorial looks at just how to do that.

Why?

As part of the Moodle 2 revamp theme's have been given the same abilities as many of the other plugin types within Moodle. They are now able to have settings pages, database tables, they can override renderers, and they can do all sorts of great things. Unfortunately this change has its positives and negatives, on the positive you can now really get some cool stuff happening within a theme, the downside is just like any other plugin you need to think about those who are already using your theme when you make changes. If you are changing the name of a setting, or if you are changing the database schema for the theme you will need to add upgrade code to your theme so that those who are already using your theme are moved along nicely and don't lose the effort they've put into customising and setting up your theme.

Step 1: version.php

For those of you who are already familiar with writing Moodle plugins you will be familiar with the version.php, however for many themer's the reality is that they've never gone beyond adding a settings page so this will be new.

The version.php file is a requirement for many plugin types, however for theme's it is optional. The idea is that it contains just two or three lines of code that the tell Moodle what version the plugin is and a little bit about where it is meant to be, or what version of Moodle it requires.

The following is an example of what a version.php file for a theme looks like.

<?php

/**

* This is the version.php file for my theme.
*/

$plugin->version = 2011032900; $plugin->maturity = MATURITY_STABLE; $plugin->requires = 2011021100;