Cannot update existing capability in a module

Cannot update existing capability in a module

بواسطة - lior gil
عدد الردود: 4
صورة Core developers

I'm working on Moodle 2.7 and I've been trying to change some of the capabilities in a module I'm building.

The change was in some of the archetypes in access.php

After a couple of times of editing the file, increasing and module version and running Moodle's upgrade without any results I looked at the code and found out the bad news.

Looks like there's no way the change the archetypes content of the capabilities after they've been added during the module's initial installation.

My question is, is there a way to make Moodle update the changes in the file? So far I haven't found an existing solution.

متوسط التقييمات: -
رداً على lior gil

Re: Cannot update existing capability in a module

بواسطة - Davo Smith
صورة Core developers صورة Particularly helpful Moodlers صورة Peer reviewers صورة Plugin developers

After a capability has been created, the only way to change which roles it is assigned to (other than manually changing the database entries), is to edit the role definitions via the UI (site admin > users > permissions > define roles). This is exactly as it should be - once the code has setup the default capability assignments on a site, the end user should be in control of which roles have which capabilities (it would cause confusion if a capability overridden by the site admin suddenly reverted during a plugin upgrade).

رداً على lior gil

Re: Cannot update existing capability in a module

بواسطة - Darko Miletić
صورة Core developers صورة Plugin developers

If you need to perform subsequent update of existing capabilities you would have to use upgrade.php facility. Write the code that will run through all roles and update them accordingly.

I suggest to look into role_change_permission API in accesslib.php.

رداً على Darko Miletić

Re: Cannot update existing capability in a module

بواسطة - lior gil
صورة Core developers

I figured as much but still hoped there's somewhere a hidden option to solve this. Seems like using the upgrade procedure is indeed the best option. Thanks.