function workflow_state_delete in Workflow 6
Same name and namespace in other branches
- 5.2 workflow.module \workflow_state_delete()
- 5 workflow.module \workflow_state_delete()
- 6.2 workflow.module \workflow_state_delete()
Delete a workflow state from the database, including any transitions the state was involved in and any associations with actions that were made to that transition.
Parameters
$sid: The ID of the state to delete.
$new_sid: Deleting a state will leave any nodes to which that state is assigned without a state. If $new_sid is given, it will be assigned to those orphaned nodes
2 calls to workflow_state_delete()
- workflow_admin_ui_state_delete_form_submit in workflow_admin_ui/
workflow_admin_ui.module - Submit handler for workflow state deletion form.
- workflow_deletewf in ./
workflow.module - Delete a workflow from the database. Deletes all states, transitions and node type mappings, too. Removes workflow state information from nodes participating in this workflow.
File
- ./
workflow.module, line 894 - Support workflows made up of arbitrary states.
Code
function workflow_state_delete($sid, $new_sid = NULL) {
if ($new_sid) {
// Assign nodes to new state so they are not orphaned.
// A candidate for the batch API.
$node = new stdClass();
$node->workflow_stamp = time();
$result = db_query("SELECT nid FROM {workflow_node} WHERE sid = %d", $sid);
while ($data = db_fetch_object($result)) {
$node->nid = $data->nid;
$node->_workflow = $sid;
_workflow_write_history($node, $new_sid, t('Previous state deleted'));
db_query("UPDATE {workflow_node} SET sid = %d WHERE nid = %d AND sid = %d", $new_sid, $data->nid, $sid);
}
}
else {
// Go ahead and orphan nodes.
db_query('DELETE from {workflow_node} WHERE sid = %d', $sid);
}
// Find out which transitions this state is involved in.
$preexisting = array();
$result = db_query("SELECT sid, target_sid FROM {workflow_transitions} WHERE sid = %d OR target_sid = %d", $sid, $sid);
while ($data = db_fetch_object($result)) {
$preexisting[$data->sid][$data->target_sid] = TRUE;
}
// Delete the transitions and associated actions, if any.
foreach ($preexisting as $from => $array) {
foreach (array_keys($array) as $target_id) {
$tid = workflow_get_transition_id($from, $target_id);
workflow_transition_delete($tid);
}
}
// Delete the state.
db_query("UPDATE {workflow_states} SET status = 0 WHERE sid = %d", $sid);
// Notify interested modules.
module_invoke_all('workflow', 'state delete', $sid, NULL, NULL);
}