function workflow_update_7004 in Workflow 7
Same name and namespace in other branches
- 7.2 workflow.install \workflow_update_7004()
Update contents of table workflow_scheduled_transition for new columns.
File
- ./
workflow.install, line 451 - Install, update and uninstall functions for the workflow module.
Code
function workflow_update_7004() {
// Not all module functions are available from within a hook_update_N() function.
// In order to call a function from your mymodule.module or an include file,
// you need to explicitly load that file first.
module_load_include('module', 'workflow');
foreach (WorkflowScheduledTransition::loadBetween() as $scheduled_transition) {
$entity_type = $scheduled_transition->entity_type;
// Set the correct entity_type. This will always be 'node'.
$entity_type = empty($entity_type) ? 'node' : $entity_type;
$entity_id = $scheduled_transition->entity_id;
$entity = $scheduled_transition
->setEntity($entity_type, $entity_id);
// When testing, we got Comments in the table. They should not be there, and do not have type set.
$entity_bundle = isset($entity->type) ? $entity->type : '';
if ($entity_bundle && ($workflow = workflow_get_workflows_by_type($entity_bundle, $entity_type))) {
// All missing data is set upon loading/constructing the ScheduledTransition.
if ($workflow_item = $workflow
->getWorkflowItem()) {
// Field API. The field name is set explicitely.
$instance = $workflow_item
->getInstance();
$scheduled_transition->field_name = $instance['field_name'];
}
else {
// Node API. The field_name is not set: this implies 'workflow'.
}
$scheduled_transition
->save();
}
}
}