public function StateFlowEntity::write_history in State Machine 7.3
Write the transaction to the history table.
Parameters
int $uid: The user id.
string $log: The message to log.
Return value
object The history entity object.
1 call to StateFlowEntity::write_history()
- StateFlowEntity::entity_saved in modules/
state_flow_entity/ plugins/ state_flow_entity.inc - Called by hook_entity_insert() / hook_entity_update().
File
- modules/
state_flow_entity/ plugins/ state_flow_entity.inc, line 672 - State Flow implementation of the State Machine class.
Class
- StateFlowEntity
- @file State Flow implementation of the State Machine class.
Code
public function write_history($uid, $log = '') {
// Start with what the db has.
$history_entity = $this
->get_history_entity();
// @todo, this was added to accommodate the double saving that happens with
// node forms.
// Reevaluate if necessary.
if (empty($log) && !empty($history_entity->event_comment)) {
$log = $history_entity->event_comment;
}
$entity_type = $this
->get_entity_type();
$entity_info = entity_get_info($entity_type);
$id_key = $entity_info['entity keys']['id'];
$revision_key = $entity_info['entity keys']['revision'];
// Apply current settings.
if (!empty($this->object->{$revision_key})) {
$history_entity->revision_id = $this->object->{$revision_key};
}
else {
$history_entity->revision_id = NULL;
}
if (!empty($this->object->{$id_key})) {
$history_entity->entity_id = $this->object->{$id_key};
}
else {
$history_entity->entity_id = NULL;
}
$history_entity->from_state = $history_entity->state;
$history_entity->state = $this
->get_current_state();
$history_entity->timestamp = REQUEST_TIME;
$history_entity->uid = $uid;
$history_entity->log = $log;
if (!empty($state)) {
$history_entity->state = $state;
}
$history_entity->entity_type = $entity_type;
// Often we are writing a new history entity and this property doesn't
// exist.
// The way node form submitting requires writing a history on form submit
// and then updating it in entity_update when the new vid is available. That
// means a hid might be present.
if (empty($history_entity->hid)) {
$primary_keys = array();
}
else {
$primary_keys = array(
'hid',
);
}
// @todo, tests needed here.
field_attach_presave('state_flow_history_entity', $history_entity);
// Update the state_flow_history table.
drupal_write_record('state_flow_history', $history_entity, $primary_keys);
// Update field tables.
field_attach_update('state_flow_history_entity', $history_entity);
$this
->set_history_entity($history_entity);
return $history_entity;
}