-
Bug
-
Resolution: Won't Fix
-
Minor
-
None
-
3.5.5, 3.6 regressions, 3.6.4
-
MOODLE_35_STABLE, MOODLE_36_STABLE
-
MDL-65668-master -
-
0
-
Internationals - 3.8 Sprint 5, Internationals - 3.8 Sprint 6, Internationals - 3.8 Sprint 7, Internationals - 3.8 Sprint 8
During plugin installation, new capabilities (defined in db/access.php) are created only after db/install.php is run. As a consequence of https://tracker.moodle.org/browse/MDL-64971, if we call assign_capability() in the install script, the function will throw an error because the capability does not yet exist in the database.
As a result, any plugin which assigns new capabilities in db/install.php or db/upgrade.php currently cannot be upgraded, and/or breaks the phpunit init script. Plugins known to be affected:
https://moodle.org/plugins/block_demostudent
https://moodle.org/plugins/mod_adobeconnect
STEPS TO REPRODUCE:
- Install vanilla Moodle 3.6.4
- Install the block_demostudent plugin https://moodle.org/plugins/block_demostudent
- Run the phpunit init script, admin/tool/phpunit/cli/init.php
EXPECTED (and working in Moodle 3.6.2 and 3.5.4):
++ Sucess ++
ACTUAL (as of Moodle 3.6.4 and 3.5.5):
Default exception handler: Coding error detected, it must be fixed by a programmer: Capability 'block/demostudent:seedemostudentblock' was not found! This has to be fixed in code. Debug:
Error code: codingerror
- line 1351 of /lib/accesslib.php: coding_exception thrown
- line 45 of /blocks/demostudent/db/install.php: call to assign_capability()
- line 979 of /lib/upgradelib.php: call to xmldb_block_demostudent_install()
- line 520 of /lib/upgradelib.php: call to upgrade_plugins_blocks()
- line 1852 of /lib/upgradelib.php: call to upgrade_plugins()
- line 491 of /lib/installlib.php: call to upgrade_noncore()
- line 461 of /lib/phpunit/classes/util.php: call to install_cli_database()
- line 150 of /admin/tool/phpunit/cli/util.php: call to phpunit_util::install_site()
POSSIBLE SOLUTIONS
In lib/upgradelib.php, update_capabilities() is typically called immediately after a component's xmldb_$component_install() function. We could create the capabilities before calling the install function. If this would not have any negative consequences, it seems like the cleanest solution.
If there is a way to resolve this within the plugins, then let's update the plugin documentation to specify where in the code newly created capabilities should be assigned.
Related:
https://moodle.org/mod/forum/discuss.php?d=384596
https://github.com/iomad/iomad/issues/1116
https://docs.moodle.org/dev/Upgrade_API#install.php
https://docs.moodle.org/dev/NEWMODULE_Adding_capabilities
- has a non-specific relationship to
-
MDL-65726 Unittests fail if a plugin creates a role on install
- Closed