Browse files

MDL-32477 allow cloning of plugin permissions from core

Please note it is discouraged to clone from different plugin type because the upgrade order is not guaranteed.
  • Loading branch information...
1 parent bd44a3b commit b3f60ef6965cb36403b8135b569001b0b44d24e8 @skodak skodak committed Apr 19, 2012
Showing with 2 additions and 1 deletion.
  1. +2 −1 lib/accesslib.php
View
3 lib/accesslib.php
@@ -3443,6 +3443,7 @@ function update_capabilities($component = 'moodle') {
}
}
// Add new capabilities to the stored definition.
+ $existingcaps = $DB->get_records_menu('capabilities', array(), 'id', 'id, name');
foreach ($newcaps as $capname => $capdef) {
$capability = new stdClass();
$capability->name = $capname;
@@ -3453,7 +3454,7 @@ function update_capabilities($component = 'moodle') {
$DB->insert_record('capabilities', $capability, false);
- if (isset($capdef['clonepermissionsfrom']) && in_array($capdef['clonepermissionsfrom'], $storedcaps)){
+ if (isset($capdef['clonepermissionsfrom']) && in_array($capdef['clonepermissionsfrom'], $existingcaps)){
if ($rolecapabilities = $DB->get_records('role_capabilities', array('capability'=>$capdef['clonepermissionsfrom']))){
foreach ($rolecapabilities as $rolecapability){
//assign_capability will update rather than insert if capability exists

0 comments on commit b3f60ef

Please sign in to comment.