function workflow_access_features_rebuild in Workflow 7
Same name and namespace in other branches
- 7.2 workflow_access/workflow_access.features.inc \workflow_access_features_rebuild()
Implements hook_features_rebuild().
Instruct Features to insert our records (that were exported into code) into the workflow_access table.
1 call to workflow_access_features_rebuild()
- workflow_access_features_revert in workflow_access/
workflow_access.features.inc - Implements hook_features_revert().
File
- workflow_access/
workflow_access.features.inc, line 119
Code
function workflow_access_features_rebuild($module) {
$workflow_access_records = module_invoke($module, 'workflow_access_features_default_settings');
// retrieve the workflow ids
$wids = array();
foreach ($workflow_access_records as $workflow_name => $state) {
$workflow = Workflow::getWorkflowByName($workflow_name);
$wids[$workflow_name] = $workflow->wid;
}
foreach ($wids as $workflow_name => $wid) {
$states = $workflow
->getStates($all = TRUE);
foreach ($states as $state) {
// Remove all workflow access records for states belonging to this
// workflow. We don't want lingering entries - we only want the ones we're
// about to insert.
workflow_access_delete_workflow_access_by_sid($state->sid);
}
}
// Insert our workflow access records. They look like
// workflow_name[state_name][role_name] => array(grant_name => 0|1, ...)
foreach ($workflow_access_records as $workflow_name => $states) {
foreach ($states as $state_name => $records) {
$state = WorkflowState::getStatesByName($state_name, $wids[$workflow_name]);
if (is_array($state)) {
$state = array_pop($state);
}
foreach ($records as $rname => $record) {
$record['sid'] = is_array($state) ? $state[0]->sid : $state->sid;
if ($rname == WORKFLOW_FEATURES_AUTHOR_NAME) {
$record['rid'] = -1;
}
else {
$role = user_role_load_by_name($rname);
$record['rid'] = $role->rid;
}
workflow_access_insert_workflow_access_by_sid($record);
}
}
}
}