When recently updating one of my activity modules, I got confused with the naming convention used for "plugin" and "module" in the version.php file.
The version.php doc gives a comprehensive list of all compulsory and optional variables to be contained in that file: $plugin->version, $plugin->requires, etc. It also says:
Note! For Activity modules replace $plugin-> with $module-> in the following example!
Does using "$plugin" rather than "$module" really make any difference? When I examine the various version.php files inside moodle version 2.6 ( dev) /mod directory, only containing core modules and files, I find the following inconsistency:
"$plugin->version" : 51 occurrences (incorrect)
"$module->version" : 22 occurrences (correct)
Can someone please explain?
Joseph
So it looks like $module should be used in activities and $plugin everywhere else?
It would make more sense to me to use $plugin everywhere.
Tomek
I love those Why? - Because. moments in Moodle
Yeah, like how the "blocks" and "modules" tables are plural, but every other table is singular. Kinda trips me up sometimes when doing SQL queries by hand.
Also, some tables are "course" and "courseid". These inconsistencies are annoying, but understandable because Moodle has a long history.
In earlier versions use $module for activities and $plugin in all other add-ons.
Actually, the way it is now is as follows:
All main version.php files for modules (mod/*/version.php) use $module.
Every other version.php (including plugins for activities, eg /mod/assign/feedback/*/version.php) use $plugin.
I don't know why
Tomek
Well, modules were the first sort of add-on for Moodle, and did things a particular way. Not all of that made sense for other types of add on.
After modules came other sorts of add-on like blocks, which used to handle version numbers in a completely different way.
Then more recently we have had a move to make all different types of add-on work more consistently in common areas like install, upgrade capabilities, cron, events, etc. That is why now almost all types of plugin use $plugin in version.php. However, they decided not to break backwards compatibility for modules by requiring $module to be changed to $plugin there.
It might still happen. It could be done like this:
- Make it possible to use either $module or $plugin in mod/.../version.php.
- Add a developer debug warning advising you to update your code when the system detects you have used $module not $plugin.
- Remove support for $module.
This would need to be done over several major releases. I would vote for doing at least 1. in Moodle 2.7.
Yeah, I would also go with:
1. Make it possible to use either $module or $plugin in mod/.../version.php.
plus update of documentation asap - which means 2.7...
Tomek
Thanks, Thomasz and Darko for your replies, which do not shed much light on this matter but at least "comfort me in my doubts".
Joseph