diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index fa5caee..113ca84 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -80,17 +80,6 @@ const COMMENT_OPEN = 2; /** - * The time cutoff for comments marked as read for entity types other node. - * - * Comments changed before this time are always marked as read. - * Comments changed after this time may be marked new, updated, or read, - * depending on their state for the current user. Defaults to 30 days ago. - * - * @todo Remove when http://drupal.org/node/1029708 lands. - */ -define('COMMENT_NEW_LIMIT', REQUEST_TIME - 30 * 24 * 60 * 60); - -/** * Implements hook_help(). */ function comment_help($path, $arg) { @@ -1162,31 +1151,18 @@ function comment_load($cid, $reset = FALSE) { * Entity type of the entity to which the comments are attached. * @param string $field_name * (optional) The field_name to count comments for. Defaults to NULL. - * @param $timestamp - * Time to count from (defaults to time of last user access - * to node). + * @param int $timestamp + * (optional) Time to count from (defaults to time at which the current user + * last viewed the entity). * - * @return + * @return int|false * The number of new comments or FALSE if the user is not logged in. */ function comment_num_new($entity_id, $entity_type, $field_name = NULL, $timestamp = 0) { if (\Drupal::currentUser()->isAuthenticated() && \Drupal::moduleHandler()->moduleExists('history')) { // Retrieve the timestamp at which the current user last viewed this entity. if (!$timestamp) { - if ($entity_type == 'node') { - $timestamp = history_read($entity_id); - } - else { - $function = $entity_type . '_last_viewed'; - if (function_exists($function)) { - $timestamp = $function($entity_id); - } - else { - // Default to 30 days ago. - // @todo Remove once http://drupal.org/node/1029708 lands. - $timestamp = COMMENT_NEW_LIMIT; - } - } + $timestamp = \Drupal::service('history.manager')->read($entity_type, array($entity_id)); } $timestamp = ($timestamp > HISTORY_READ_LIMIT ? $timestamp : HISTORY_READ_LIMIT); @@ -1208,7 +1184,6 @@ function comment_num_new($entity_id, $entity_type, $field_name = NULL, $timestam else { return FALSE; } - } /** diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php index b312dec..45c2953 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php @@ -157,7 +157,7 @@ function setEnvironment(array $info) { // comment_num_new() relies on history_read(), so ensure that no one has // seen the node of this comment. - \Drupal::service('history.manager')->deleteByEntity('node', $this->node->id()); + \Drupal::service('history.manager')->deleteByEntity($this->node); } else { $cids = db_query("SELECT cid FROM {comment}")->fetchCol(); diff --git a/core/modules/history/history.module b/core/modules/history/history.module index 69eca26..303b879 100644 --- a/core/modules/history/history.module +++ b/core/modules/history/history.module @@ -117,7 +117,7 @@ function history_node_view_alter(&$build, EntityInterface $node, EntityDisplay $ * Implements hook_node_delete(). */ function history_node_delete(EntityInterface $node) { - \Drupal::service('history.manager')->deleteByEntity('node', $node->id()); + \Drupal::service('history.manager')->deleteByEntity($node); } /** @@ -126,7 +126,7 @@ function history_node_delete(EntityInterface $node) { function history_user_cancel($edit, $account, $method) { switch ($method) { case 'user_cancel_reassign': - \Drupal::service('history.manager')->deleteByUid($account->id()); + \Drupal::service('history.manager')->deleteByUser($account); break; } } @@ -135,7 +135,7 @@ function history_user_cancel($edit, $account, $method) { * Implements hook_user_delete(). */ function history_user_delete($account) { - \Drupal::service('history.manager')->deleteByUid($account->id()); + \Drupal::service('history.manager')->deleteByUser($account); } /** diff --git a/core/modules/history/lib/Drupal/history/HistoryManager.php b/core/modules/history/lib/Drupal/history/HistoryManager.php index 84ff5b5..7e0fd29 100644 --- a/core/modules/history/lib/Drupal/history/HistoryManager.php +++ b/core/modules/history/lib/Drupal/history/HistoryManager.php @@ -8,6 +8,7 @@ namespace Drupal\history; use Drupal\Core\Database\Connection; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Session\AccountInterface; /** @@ -113,9 +114,9 @@ public function purge() { /** * {@inheritdoc} */ - public function deleteByUid($uid) { + public function deleteByUser(AccountInterface $account) { $this->connection->delete('history') - ->condition('uid', $uid) + ->condition('uid', $account->id()) ->execute(); // Clean static cache. $this->resetCache(); @@ -124,13 +125,13 @@ public function deleteByUid($uid) { /** * {@inheritdoc} */ - public function deleteByEntity($entity_type, $entity_id) { + public function deleteByEntity(EntityInterface $entity) { $this->connection->delete('history') - ->condition('entity_id', $entity_id) - ->condition('entity_type', $entity_type) + ->condition('entity_id', $entity->id()) + ->condition('entity_type', $entity->entityType()) ->execute(); // Clean static cache. - unset($this->history[$entity_type][$entity_id]); + unset($this->history[$entity->entityType()][$entity->id()]); } /** diff --git a/core/modules/history/lib/Drupal/history/HistoryManagerInterface.php b/core/modules/history/lib/Drupal/history/HistoryManagerInterface.php index 79e0fb3..7430c13 100644 --- a/core/modules/history/lib/Drupal/history/HistoryManagerInterface.php +++ b/core/modules/history/lib/Drupal/history/HistoryManagerInterface.php @@ -7,6 +7,7 @@ namespace Drupal\history; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Session\AccountInterface; /** @@ -50,20 +51,18 @@ public function purge(); /** * Deletes history of the user account. * - * @param int $uid - * The user account id to purge history + * @param \Drupal\Core\Session\AccountInterface $account + * The user account to purge history */ - public function deleteByUid($uid); + public function deleteByUser(AccountInterface $account); /** * Deletes history for the given entity. * - * @param string $entity_type - * The entity type. - * @param int $entity_id - * The entity ID that has been read. + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity that history should be deleted. */ - public function deleteByEntity($entity_type, $entity_id); + public function deleteByEntity(EntityInterface $entity); /** * Resets the static cache. diff --git a/core/modules/node/node.install b/core/modules/node/node.install index be48b65..2a8b104 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -732,14 +732,7 @@ function node_update_8012() { 'description' => 'The type of the entity that was read.', 'type' => 'varchar', 'not null' => TRUE, - 'default' => 'node', - 'length' => 255, - )); - // Remove default value. - db_add_field('history', 'entity_type', array( - 'description' => 'The type of the entity that was read.', - 'type' => 'varchar', - 'not null' => TRUE, + 'initial' => 'node', 'length' => 255, )); // Rename the field.