Daily Archives: November 19, 2011

Porting BIM to Moodle 2 – Step 1

The wife’s out for some culture so I find myself late on a Saturday night taking the initial steps in the second attempt to port BIM to Moodle 2. Started reading Mike Churchward’s blog series on porting modules to Moodle 2.

Time moves on, and almost a week later I’m putting the finishing touches on this post/development journal entry. It gives a brief summary (mostly for my records) of what I’ve done to get a version of BIM that is being recognised by Moodle 2.1. Not sure how well it is working, but Moodle 2.1 is creating tables and recognising the plugin as being available for use in courses.

The next step will involve experimenting with just how well BIM is working with Moodle 2.1 and fixing what needs to be done. This will involve finishing some of the following.

Upgrading Moodle

Of course, it’s a good 6/7 months since I touched Moodle. So I should probably start by upgrading to the latest version of Moodle, which seems to be 2.1.2.

It is going to take sometime to get back into this.

Oh look at that, Moodle 2.1 requires the next version of PHP. Thankfully some kind soul has produced a dmg file with Xampp and Moodle 2.1 for Mac OSX. Let’s install that.

That was relatively painless. Moodle 2.1 up and going.

The plan for git

The source code for BIM is hosted on BIM. The previous attempt at BIM2 is also hosted there, need to figure out what to do with this new version…..yes folks, I’m that out of it as a developer.

Ohh, there’s a GUI client for Mac OSX now. Looks okay.

This seems to be the approach. More on this tomorrow.

The plan is

  • Tag the existing bim code as 1.0 (and v1.0 just for good measure – i.e. re-learning git).
  • Create a bim2 branch and then a develop branch from there.
    git checkout -b bim2
  • Convert the Moodle 2 branch into a Moodle 2 module.
    This will be the step-by-step process I start from now, with a vague set of steps something like
    • Do minimum to get Moodle 2 to recognise bim.
    • Comment out everything that creates errors.
    • Gradually bring bits back and convert them to Moodle 2 “format”.

    Be interesting to see how long that plan lasts.

Get Moodle 2.1 to recognise the bim module

With the code in place (~/mod), when I login as admin to the local Moodle installation, there is the notice that bim is ready to install. Now’s when we find out what is missing. There’s the error

Plugin “mod_bim” is defective or outdated, can not continue, sorry.

The error causing this is

Missing mandatory en language pack.

If I go looking for the code, it’s looking for the file $fullmod/lang/en/$mod.php. More information here and this checklist

I’d gotten a fair bit of the way through this conversion process when errors were causing me concern. After a few more side tracks I discovered the following.

Oh dear, simply syntax errors. Need to check those. Using this little bit of shell

for name in *.php
do
php -d display_errors=1 -l $name
done

Fixed up all of those and now have a bit of success, good news this late on a Saturday afternoon, bim is being recognised by Moodle 2.1

Language strings

From the the checklist

  • DONE rename language folder (en_utf8 to en)
  • DONE Change $a to {$a}
  • Change popup help files to _help lang strings and shorten.
    Need to run up Moodle 1.9 so I can double check where the help strings are going etc.

    Some of these are quite long, I can see some Moodle docs in my future, including:

    • Manage marking help “manageMarking.html”
    • yourStudents.html
    • opml.html
    • unregisteredDetails.html
    • registeredDetails.html
    • changingosts.html
    • mods.html
  • DONE Add $string[‘pluginname’] to lang file
  • DONE Add $string[‘pluginadministration’] to lang file

So, does that change the Moodle 2.1 complaints about BIM?

Yes it does. A big green tick and success. You know it’s not going to be that easy. Ahh, internal server error. Have to remove the bim code entirely to get Moodle to start up again. Will remove it via Moodle, stick the code back in to see if the problem was due to a time out issue.

Time to go through the rest of the checklist.

Database

Also drawing on the DB layer 2.0 migration docs

  • DONELeave empty db/update.php file
  • DONENew $DB global objects with functions replace old db functions
    There is a PHP script that checks for functions.
  • $DB parameters swapped to ?
  • DONEAdd and strip slashes no longer required
  • DONERemove use of ENUM and ENUMVALUES in install.xml file
  • DONERemove STATEMENTS section in install.xml file, use db/install.php or db/log.php instead.
  • DONE not used..check use of sql_substr()
  • Get_records() etc now always returning arrays, empty array in case of no records found.
  • Db functions throw errors not return false on error
  • DB functions offer strictness parameters e.g MUST_EXIST
  • DONE Update version.php numbers (esp required)
  • DONEIn version.php add $module->requires = 2010080300; // Requires this Moodle version

More insights from page on upgrading plugin tables

Page display

  • New $OUTPUT header and footer functions
    Done the basics at the top level. Need to do more work on this.
  • Navigation links need to use $PAGE->navbar
  • Make sure that you instantiate the moodle form before any call to $OUTPUT->header()
  • Create a renderer
  • DONE (not used) Change the way image urls are displayed (not $CFG->pixpath any more)
  • CSS changes

    • DONE (not used) Change styles.php to styles.css
    • Change page id to new structure e.g. course-format-studyplan to page-course-view-studyplan

Forms

  • Param_clean parameter type removed
  • type required parameter for optional_and required_param
  • Replace file form elements with new filepicker
  • Replace htmleditor with editor form field type
  • Change setHelpButton to addHelpButton. (You need to change the arguments, but the new ones are simpler.)

Roles and permissions

  • DONE array name to $capabilities in access.php
  • DONE Remove references to admin in access.php
  • DONE Rename legacy to archetypes in access.php
  • DONE Add manager archetype in access.php
  • Ensure require_login as well as require_capability checks
  • DONE (not used) isguest() is depreicated, use !isloggedin() || isguestuser() instead

Progress

Somewhere in all of that, things got a bit much. Need to do this differently, for now.

Empty slate and slowly copy stuff in, starting with index.php. index.php requires a valid course id with a bim activity to work directly. But bim is showing up in Moodle 2.1 okay.