Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-65668

plugins which assign new capabilities cannot be upgraded/installed

XMLWordPrintable

    • 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:

      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

       

            rezaie9 Shamim Rezaie
            zorkzork Dom Royko
            Simey Lameze Simey Lameze
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Votes:
            6 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 7 hours, 15 minutes
                1d 7h 15m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.