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

plugins which assign new capabilities cannot be upgraded/installed

    XMLWordPrintable

    Details

    • Story Points:
      2
    • Sprint:
      Internationals - 3.8 Sprint 5, Internationals - 3.8 Sprint 6, Internationals - 3.8 Sprint 7

      Description

      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

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rezaie9 Shamim Rezaie
                Reporter:
                zorkzork Dom Royko
                Peer reviewer:
                Simey Lameze
                Participants:
                Component watchers:
                Matteo Scaramuccia, Andrew Nicols, Mathew May, Michael Hawkins, Shamim Rezaie, Simey Lameze, Amaia Anabitarte, Bas Brands, Carlos Escobedo, Sara Arjona (@sarjona), Víctor Déniz Falcón
              • Votes:
                5 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 day, 1 hour, 30 minutes
                  1d 1h 30m