function workbench_moderation_update_7003 in Workbench Moderation 7
Same name and namespace in other branches
- 7.3 workbench_moderation.install \workbench_moderation_update_7003()
Use "revision" instead of "version" when referring to node revisions.
File
- ./
workbench_moderation.install, line 281 - Install file for the Workbench Moderation module.
Code
function workbench_moderation_update_7003() {
$old_permission = 'unpublish live version';
$new_permission = 'unpublish live revision';
// Which roles have the old permission?
$roles = db_select('role_permission', 'role_permission')
->condition('permission', $old_permission)
->condition('module', 'workbench_moderation')
->fields('role_permission', array(
'rid',
))
->execute()
->fetchCol();
// Grant these roles the new permission. Normally, this would use
// user_role_grant_permissions(), but since update hooks run regardless of
// whether a module is enabled, we can't guarantee that workbench_moderation
// permissions will be available when user.module invokes hook_permission().
foreach ($roles as $rid) {
db_merge('role_permission')
->key(array(
'rid' => $rid,
'permission' => $new_permission,
))
->fields(array(
'module' => 'workbench_moderation',
))
->execute();
}
// Delete all grants of the old permission.
db_delete('role_permission')
->condition('permission', $old_permission)
->condition('module', 'workbench_moderation')
->execute();
return t('The renamed permission was updated for !count roles.', array(
'!count' => count($roles),
));
}