function workflow_update_workflows_full_object in Workflow 7
For use by CRUD only, save everything from the CRUD formed object.
Parameters
$workflow: A fully loaded workflow object to save the states of.
Return value
Returns whether the workflow was saved fully.
See also
workflow_get_workflows_full_object
1 call to workflow_update_workflows_full_object()
- workflow_features_revert in ./
workflow.features.inc - Implements hook_features_revert().
File
- ./
workflow.features.inc, line 104 - Integrates workflow with features.
Code
function workflow_update_workflows_full_object($workflow) {
$workflow = (object) $workflow;
// Given a workflow in the format returned from export.
// First we grab the states, transitions and node_maps out.
$states = isset($workflow->states) ? $workflow->states : array();
$transitions = isset($workflow->transitions) ? $workflow->transitions : array();
$node_types = isset($workflow->node_types) ? $workflow->node_types : array();
unset($workflow->states, $workflow->transitions, $workflow->node_types);
// Then make a workflow so we can track by wid.
if ($orig_workflow = Workflow::getWorkflowByName($workflow->name)) {
$workflow->wid = $orig_workflow->wid;
}
workflow_update_workflows($workflow, FALSE);
// @todo: deprecated function.
// Cancel out if workflow failed to save.
if (!isset($workflow->wid) || empty($workflow->wid)) {
return FALSE;
}
// Workflow is now a fully vetted workflow object. We have NOT created a creation state with this.
// Then make states, marking state name to state sid.
$active_states = array();
foreach ($states as $state) {
$state = (object) $state;
$state->wid = $workflow->wid;
if ($orig_state = reset(workflow_get_workflow_states_by_wid_state($state->wid, $state->state))) {
$state->sid = $orig_state->sid;
}
workflow_update_workflow_states($state);
$active_states[$state->state] = $state->sid;
}
// Delete any states *not* in our original construction.
foreach (workflow_get_workflow_states_by_wid($workflow->wid) as $state) {
if (!in_array($state->sid, $active_states)) {
workflow_delete_workflow_states_by_sid($state->sid);
}
}
// Then make transitions with the state mapping.
$active_transitions = array();
foreach ($transitions as $transition) {
$transition = (object) $transition;
$transition->sid = $active_states[$transition->state];
$transition->target_sid = $active_states[$transition->target_state];
// Roles are exported by rolename, so need to translate to RID.
$transition->roles = !empty($transition->roles) ? _workflow_roles_to_rids($transition->roles) : '';
workflow_update_workflow_transitions($transition);
$active_transitions[] = $transition->tid;
}
// Delete any transitions in our workflow that are *not* in our original construction.
foreach (workflow_get_workflow_transitions_by_wid($workflow->wid) as $transition) {
if (!in_array($transition->tid, $active_transitions)) {
workflow_delete_workflow_transitions_by_tid($transition->tid);
}
}
// Then add the node_type mapping.
foreach ($node_types as $node_type) {
$node_type = (object) array(
'type' => $node_type,
'wid' => $workflow->wid,
);
// Insert, nodes only have one workflow. Insert will delete any prior workflow assoc.
workflow_insert_workflow_type_map($node_type);
}
return TRUE;
}