You are here

function entity_modified_last in Entity modified 7

Retrieve the last time an entity was modified.

1 call to entity_modified_last()
entity_modified_nodequeue_nodes_last in modules/entity_modified_nodequeue/entity_modified_nodequeue.module

File

./entity_modified.module, line 57
Hook implementations and frequently used functions for entity modified module.

Code

function entity_modified_last($entity_type, $entity) {
  $name = entity_modified_property_name($entity_type);

  // If native modified timestamp known.
  if ($name) {
    return $entity->{$name};
  }

  // Retrieve entity's last modified from our custom table.
  list($entity_id) = entity_extract_ids($entity_type, $entity);
  $modified_timestamp = db_query('SELECT modified FROM {entity_modified} WHERE entity_type = :entity_type AND entity_id = :entity_id', array(
    ':entity_type' => $entity_type,
    ':entity_id' => $entity_id,
  ))
    ->fetchField();

  // If not found then use '1' as inserting something in a read-only operation
  // is a bad idea.
  if (!$modified_timestamp) {
    $modified_timestamp = 1;
  }
  return $modified_timestamp;
}