Wip contrib 4320 mdl 22

Hello
  I've submitted changes to resolve upgrade issues experienced when upgrading from Moodle 1.9 to Moodle 2.2 outlined in https://tracker.moodle.org/browse/CONTRIB-4320 .  I've also published the matching change into branches for Moodle 2.3/2.4 which follow the same naming convention (didn't want to overload you with pull requests as I'm still fairly new to GitHub, so I just issued this request for the 2.2 branch.)

Please feel free to contact me with any questions, and thank you for your work on developing this module.

Regards,
Logan Reynolds