Cannot update existing capability in a module

Cannot update existing capability in a module

by lior gil -
Number of replies: 4
Picture of 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.

Average of ratings: -
In reply to lior gil

Re: Cannot update existing capability in a module

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

I would also like to know the answer to that question.

Joseph

In reply to lior gil

Re: Cannot update existing capability in a module

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of 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).

Average of ratings: Useful (1)
In reply to lior gil

Re: Cannot update existing capability in a module

by Darko Miletić -
Picture of Core developers Picture of 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.

Average of ratings: Useful (1)
In reply to Darko Miletić

Re: Cannot update existing capability in a module

by lior gil -
Picture of 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.