Mercurial > hg > cmmr2012-drupal-site
diff core/modules/comment/src/CommentStorage.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children | 12f9dff5fda9 |
line wrap: on
line diff
--- a/core/modules/comment/src/CommentStorage.php Thu Feb 28 11:14:44 2019 +0000 +++ b/core/modules/comment/src/CommentStorage.php Thu Feb 28 13:11:55 2019 +0000 @@ -3,6 +3,7 @@ namespace Drupal\comment; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; @@ -43,9 +44,11 @@ * Cache backend instance to use. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache + * The memory cache. */ - public function __construct(EntityTypeInterface $entity_info, Connection $database, EntityManagerInterface $entity_manager, AccountInterface $current_user, CacheBackendInterface $cache, LanguageManagerInterface $language_manager) { - parent::__construct($entity_info, $database, $entity_manager, $cache, $language_manager); + public function __construct(EntityTypeInterface $entity_info, Connection $database, EntityManagerInterface $entity_manager, AccountInterface $current_user, CacheBackendInterface $cache, LanguageManagerInterface $language_manager, MemoryCacheInterface $memory_cache) { + parent::__construct($entity_info, $database, $entity_manager, $cache, $language_manager, $memory_cache); $this->currentUser = $current_user; } @@ -59,7 +62,8 @@ $container->get('entity.manager'), $container->get('current_user'), $container->get('cache.entity'), - $container->get('language_manager') + $container->get('language_manager'), + $container->get('entity.memory_cache') ); } @@ -67,7 +71,7 @@ * {@inheritdoc} */ public function getMaxThread(CommentInterface $comment) { - $query = $this->database->select('comment_field_data', 'c') + $query = $this->database->select($this->getDataTable(), 'c') ->condition('entity_id', $comment->getCommentedEntityId()) ->condition('field_name', $comment->getFieldName()) ->condition('entity_type', $comment->getCommentedEntityTypeId()) @@ -81,7 +85,7 @@ * {@inheritdoc} */ public function getMaxThreadPerThread(CommentInterface $comment) { - $query = $this->database->select('comment_field_data', 'c') + $query = $this->database->select($this->getDataTable(), 'c') ->condition('entity_id', $comment->getCommentedEntityId()) ->condition('field_name', $comment->getFieldName()) ->condition('entity_type', $comment->getCommentedEntityTypeId()) @@ -98,8 +102,9 @@ public function getDisplayOrdinal(CommentInterface $comment, $comment_mode, $divisor = 1) { // Count how many comments (c1) are before $comment (c2) in display order. // This is the 0-based display ordinal. - $query = $this->database->select('comment_field_data', 'c1'); - $query->innerJoin('comment_field_data', 'c2', 'c2.entity_id = c1.entity_id AND c2.entity_type = c1.entity_type AND c2.field_name = c1.field_name'); + $data_table = $this->getDataTable(); + $query = $this->database->select($data_table, 'c1'); + $query->innerJoin($data_table, 'c2', 'c2.entity_id = c1.entity_id AND c2.entity_type = c1.entity_type AND c2.field_name = c1.field_name'); $query->addExpression('COUNT(*)', 'count'); $query->condition('c2.cid', $comment->id()); if (!$this->currentUser->hasPermission('administer comments')) { @@ -133,6 +138,7 @@ public function getNewCommentPageNumber($total_comments, $new_comments, FieldableEntityInterface $entity, $field_name) { $field = $entity->getFieldDefinition($field_name); $comments_per_page = $field->getSetting('per_page'); + $data_table = $this->getDataTable(); if ($total_comments <= $comments_per_page) { // Only one page of comments. @@ -146,7 +152,7 @@ // Threaded comments. // 1. Find all the threads with a new comment. - $unread_threads_query = $this->database->select('comment_field_data', 'comment') + $unread_threads_query = $this->database->select($data_table, 'comment') ->fields('comment', ['thread']) ->condition('entity_id', $entity->id()) ->condition('entity_type', $entity->getEntityTypeId()) @@ -171,7 +177,7 @@ $first_thread = substr($first_thread, 0, -1); // Find the number of the first comment of the first unread thread. - $count = $this->database->query('SELECT COUNT(*) FROM {comment_field_data} WHERE entity_id = :entity_id + $count = $this->database->query('SELECT COUNT(*) FROM {' . $data_table . '} WHERE entity_id = :entity_id AND entity_type = :entity_type AND field_name = :field_name AND status = :status @@ -192,7 +198,7 @@ * {@inheritdoc} */ public function getChildCids(array $comments) { - return $this->database->select('comment_field_data', 'c') + return $this->database->select($this->getDataTable(), 'c') ->fields('c', ['cid']) ->condition('pid', array_keys($comments), 'IN') ->condition('default_langcode', 1) @@ -258,7 +264,8 @@ * to consider the trailing "/" so we use a substring only. */ public function loadThread(EntityInterface $entity, $field_name, $mode, $comments_per_page = 0, $pager_id = 0) { - $query = $this->database->select('comment_field_data', 'c'); + $data_table = $this->getDataTable(); + $query = $this->database->select($data_table, 'c'); $query->addField('c', 'cid'); $query ->condition('c.entity_id', $entity->id()) @@ -278,7 +285,7 @@ $query->element($pager_id); } - $count_query = $this->database->select('comment_field_data', 'c'); + $count_query = $this->database->select($data_table, 'c'); $count_query->addExpression('COUNT(*)'); $count_query ->condition('c.entity_id', $entity->id()) @@ -324,7 +331,7 @@ * {@inheritdoc} */ public function getUnapprovedCount() { - return $this->database->select('comment_field_data', 'c') + return $this->database->select($this->getDataTable(), 'c') ->condition('status', CommentInterface::NOT_PUBLISHED, '=') ->condition('default_langcode', 1) ->countQuery()