Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / comment / src / CommentStorage.php
index 2bcda91d003b3635bd093eba40c4ce2cf5d44088..1d7f37531ca4dfbee942ed46ed7360be6fca355b 100644 (file)
@@ -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 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
    *   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 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
       $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 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
    * {@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 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
    * {@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 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
   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 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
   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 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
       // 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 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
       $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 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
    * {@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 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
    * 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 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
         $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 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
    * {@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()