You are here

public function StateFlowEntity::get_latest_revision in State Machine 7.3

Get the latest revision id.

Parameters

int $entity_id: The entity id of the entity to fetch the latest revision id for. DEPRECATED!

Return value

int|FALSE The latest revision id or FALSE on failure.

File

modules/state_flow_entity/plugins/state_flow_entity.inc, line 780
State Flow implementation of the State Machine class.

Class

StateFlowEntity
@file State Flow implementation of the State Machine class.

Code

public function get_latest_revision($entity_id = NULL) {
  $entity_type = $this
    ->get_entity_type();
  $entity_info = entity_get_info($entity_type);
  if (isset($entity_info['revision table'])) {
    $id_key = $entity_info['entity keys']['id'];
    $revision_key = $entity_info['entity keys']['revision'];
    if (empty($entity_id)) {
      $entity_id = $this->object->{$id_key};
    }
    $query = db_select($entity_info['revision table'])
      ->fields($entity_info['revision table'], array(
      $revision_key,
    ))
      ->condition($id_key, $entity_id)
      ->orderBy('timestamp', 'DESC')
      ->range(0, 1);
    return $query
      ->execute()
      ->fetchField();
  }
  return FALSE;
}