function scheduler_update_7100 in Scheduler 7
Update roles with new 'View Scheduled Content' permission.
File
- ./
scheduler.install, line 97 - Installation file for Scheduler module.
Code
function scheduler_update_7100() {
// Retrieve all roles that have both the 'administer nodes' and 'schedule
// (un)publishing of nodes' permissions.
// @see http://www.drupal.org/node/2355401
$query = db_select('role_permission', 'r');
$query
->fields('r', array(
'rid',
));
$query
->condition('r.permission', 'administer nodes', '=');
$query
->addJoin('INNER', 'role_permission', 'r2', 'r.rid = r2.rid');
$query
->condition('r2.permission', 'schedule (un)publishing of nodes', '=');
// Grant these roles the 'view scheduled content' permission.
if ($roles_to_update = $query
->execute()
->fetchCol()) {
foreach ($roles_to_update as $rid) {
// Use db_merge not db_insert in case the role already has the permission.
$query = db_merge('role_permission');
$query
->key(array(
'rid' => $rid,
'permission' => 'view scheduled content',
'module' => 'scheduler',
));
$query
->fields(array(
'rid' => $rid,
'permission' => 'view scheduled content',
'module' => 'scheduler',
));
$query
->execute();
}
}
return format_plural(count($roles_to_update), '1 role updated with view scheduled content permission.', '@count roles updated with view scheduled content permission.');
}