Skip to content

Instantly share code, notes, and snippets.

@kvnm
Created May 30, 2016 21:29
Show Gist options
  • Save kvnm/37d96431308b1da393a3cc792b68d2c2 to your computer and use it in GitHub Desktop.
Save kvnm/37d96431308b1da393a3cc792b68d2c2 to your computer and use it in GitHub Desktop.
Retroactively bulk assign all existing nodes with taxonomy terms to their respective workbench_access sections. Useful if you've got a workbench_access scheme based on taxonomy terms that have existed for some time before launching access control.
/**
* Retroactively bulk assigns all existing nodes w/ taxonomy terms
* to their respective workbench_access sections.
*/
function custom_workbench_retroactive_assign_all() {
$active = workbench_access_get_active_tree();
if (!$active) {
return;
}
$tree = $active['tree'];
workbench_access_build_tree($tree);
$options = workbench_access_options($tree, $active['active']);
if (empty($options)) {
return;
}
foreach ($tree as $tid => $leaf) {
$nids = array();
if (is_numeric($tid)) {
$nids = taxonomy_select_nodes($tid, FALSE, FALSE);
}
if (!empty($nids)) {
workbench_access_mass_update($nids, $tid, $active['access_scheme']);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment