diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index ec05c1a..991f2b4 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -60,6 +60,16 @@ class Entity implements IteratorAggregate, EntityInterface { protected $isDefaultRevision = TRUE; /** + * The last time this entity was updated, in seconds since the Unix Epoch. + * + * The number itself is relatively useless but can be subtracted from the current + * value of time() to give the age of the last update, in seconds. + * + * @var int + */ + protected $lastUpdateTime; + + /** * Constructs an Entity object. * * @param array $values @@ -120,6 +130,27 @@ public function setNewRevision($value = TRUE) { } /** + * Implements \Drupal\Core\Entity\EntityInterface::lastUpdate(). + */ + public function lastUpdate() { + return $lastUpdateTime; + } + + /** + * Implements \Drupal\Core\Entity\EntityInterface::timeSinceUpdate(). + */ + public function timeSinceUpdate() { + return time() - $lastUpdateTime; + } + + /** + * Implements \Drupal\Core\Entity\EntityInterface::update(). + */ + public function update() { + $lastUpdateTime = time(); + } + + /** * Implements \Drupal\Core\Entity\EntityInterface::entityType(). */ public function entityType() { diff --git a/core/lib/Drupal/Core/Entity/EntityInterface.php b/core/lib/Drupal/Core/Entity/EntityInterface.php index e965b8e..da6b737 100644 --- a/core/lib/Drupal/Core/Entity/EntityInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityInterface.php @@ -89,6 +89,27 @@ public function setNewRevision($value = TRUE); public function enforceIsNew($value = TRUE); /** + * Returns time of last update to the entity, in seconds since the Unix epoch. + * + * @return int + * The time of the last update. + */ + public function lastUpdate(); + + /** + * Returns time since the last update to the entity, in seconds. + * + * @return int + * The time since the last update. + */ + public function timeSinceUpdate(); + + /** + * Sets $lastUpdateTime to the current time. + */ + public function update(); + + /** * Returns the type of the entity. * * @return