diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 391a255..fc859ba 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -5,6 +5,7 @@ * Install, update and uninstall functions for the Comment module. */ +use Drupal\Core\Entity\EntityTypeInterface; use Drupal\field\Entity\FieldConfig; /** @@ -48,7 +49,7 @@ function comment_schema() { 'type' => 'varchar', 'not null' => TRUE, 'default' => 'node', - 'length' => 255, + 'length' => EntityTypeInterface::ID_MAX_LENGTH, 'description' => 'The entity_type of the entity to which this comment is a reply.', ), 'field_name' => array( diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 0336e1c..2291cea 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -161,7 +161,7 @@ function comment_theme() { * @todo Move to the comment manager and replace by a entity query? */ function comment_count_unpublished() { - $count = db_query('SELECT COUNT(cid) FROM {comment} WHERE status = :status', array( + $count = db_query('SELECT COUNT(cid) FROM {comment_field_data} WHERE status = :status', array( ':status' => CommentInterface::NOT_PUBLISHED, ))->fetchField(); return t('Unapproved comments (@count)', array('@count' => $count)); @@ -218,7 +218,7 @@ function comment_field_config_insert(FieldConfigInterface $field) { function comment_field_instance_config_delete(FieldInstanceConfigInterface $instance) { if ($instance->getType() == 'comment') { // Delete all comments that used by the entity bundle. - $comments = db_query("SELECT cid FROM {comment} WHERE entity_type = :entity_type AND field_name = :field_name", array( + $comments = db_query("SELECT cid FROM {comment_field_data} WHERE entity_type = :entity_type AND field_name = :field_name", array( ':entity_type' => $instance->getEntityTypeId(), ':field_name' => $instance->getName(), ))->fetchCol(); @@ -288,7 +288,7 @@ function comment_new_page_count($num_comments, $new_replies, ContentEntityInterf // thread with a new comment. // 1. Find all the threads with a new comment. - $unread_threads_query = db_select('comment') + $unread_threads_query = db_select('comment_field_data') ->fields('comment', array('thread')) ->condition('entity_id', $entity->id()) ->condition('entity_type', $entity->getEntityTypeId()) @@ -312,7 +312,7 @@ function comment_new_page_count($num_comments, $new_replies, ContentEntityInterf $first_thread = substr($first_thread, 0, -1); // Find the number of the first comment of the first unread thread. - $count = db_query('SELECT COUNT(*) FROM {comment} WHERE entity_id = :entity_id + $count = db_query('SELECT COUNT(*) FROM {comment_field_data} WHERE entity_id = :entity_id AND entity_type = :entity_type AND field_name = :field_name AND status = :status AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < :thread', array( @@ -617,7 +617,7 @@ function comment_add(EntityInterface $entity, $field_name = 'comment', $pid = NU * to consider the trailing "/" so we use a substring only. */ function comment_get_thread(EntityInterface $entity, $field_name, $mode, $comments_per_page, $pager_id = 0) { - $query = db_select('comment', 'c') + $query = db_select('comment_field_data', 'c') ->extend('Drupal\Core\Database\Query\PagerSelectExtender'); if ($pager_id) { $query->element($pager_id); @@ -634,7 +634,7 @@ function comment_get_thread(EntityInterface $entity, $field_name, $mode, $commen ->addMetaData('field_name', $field_name) ->limit($comments_per_page); - $count_query = db_select('comment', 'c'); + $count_query = db_select('comment_field_data', 'c'); $count_query->addExpression('COUNT(*)'); $count_query ->condition('c.entity_id', $entity->id()) @@ -1077,7 +1077,7 @@ function comment_num_new($entity_id, $entity_type, $field_name = NULL, $timestam $timestamp = ($timestamp > HISTORY_READ_LIMIT ? $timestamp : HISTORY_READ_LIMIT); // Use the timestamp to retrieve the number of new comments. - $query = db_select('comment', 'c'); + $query = db_select('comment_field_data', 'c'); $query->addExpression('COUNT(cid)'); $query->condition('c.entity_type', $entity_type) ->condition('c.entity_id', $entity_id) @@ -1116,8 +1116,8 @@ function comment_num_new($entity_id, $entity_type, $field_name = NULL, $timestam function comment_get_display_ordinal($cid, FieldDefinitionInterface $field_definition) { // Count how many comments (c1) are before $cid (c2) in display order. This is // the 0-based display ordinal. - $query = db_select('comment', 'c1'); - $query->innerJoin('comment', 'c2', 'c2.entity_id = c1.entity_id AND c2.entity_type = c1.entity_type AND c2.field_name = c1.field_name'); + $query = db_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'); $query->addExpression('COUNT(*)', 'count'); $query->condition('c2.cid', $cid); if (!user_access('administer comments')) { diff --git a/core/modules/comment/src/CommentStatistics.php b/core/modules/comment/src/CommentStatistics.php index fbbdff4..afb4d56 100644 --- a/core/modules/comment/src/CommentStatistics.php +++ b/core/modules/comment/src/CommentStatistics.php @@ -179,7 +179,7 @@ public function update(CommentInterface $comment) { return; } - $query = $this->database->select('comment', 'c'); + $query = $this->database->select('comment_field_data', 'c'); $query->addExpression('COUNT(cid)'); $count = $query->condition('c.entity_id', $comment->getCommentedEntityId()) ->condition('c.entity_type', $comment->getCommentedEntityTypeId()) @@ -190,7 +190,7 @@ public function update(CommentInterface $comment) { if ($count > 0) { // Comments exist. - $last_reply = $this->database->select('comment', 'c') + $last_reply = $this->database->select('comment_field_data', 'c') ->fields('c', array('cid', 'name', 'changed', 'uid')) ->condition('c.entity_id', $comment->getCommentedEntityId()) ->condition('c.entity_type', $comment->getCommentedEntityTypeId()) diff --git a/core/modules/comment/src/CommentStorage.php b/core/modules/comment/src/CommentStorage.php index 2cffb5e..40eec16 100644 --- a/core/modules/comment/src/CommentStorage.php +++ b/core/modules/comment/src/CommentStorage.php @@ -61,26 +61,26 @@ public static function createInstance(ContainerInterface $container, EntityTypeI /** * {@inheritdoc} - */ + * protected function buildQuery($ids, $revision_id = FALSE) { $query = parent::buildQuery($ids, $revision_id); // Specify additional fields from the user table. - $query->innerJoin('users', 'u', 'base.uid = u.uid'); + //$query->innerJoin('users', 'u', 'base.uid = u.uid'); // @todo: Move to a computed 'name' field instead. - $query->addField('u', 'name', 'registered_name'); + //$query->addField('u', 'name', 'registered_name'); return $query; - } + }*/ /** * {@inheritdoc} - */ + * protected function mapFromStorageRecords(array $records) { // Prepare standard comment fields. foreach ($records as $record) { $record->name = $record->uid ? $record->registered_name : $record->name; } return parent::mapFromStorageRecords($records); - } + }*/ /** * {@inheritdoc} @@ -93,7 +93,7 @@ public function updateEntityStatistics(CommentInterface $comment) { * {@inheritdoc} */ public function getMaxThread(EntityInterface $comment) { - $query = $this->database->select('comment', 'c') + $query = $this->database->select('comment_field_data', 'c') ->condition('entity_id', $comment->getCommentedEntityId()) ->condition('field_name', $comment->getFieldName()) ->condition('entity_type', $comment->getCommentedEntityTypeId()); @@ -106,7 +106,7 @@ public function getMaxThread(EntityInterface $comment) { * {@inheritdoc} */ public function getMaxThreadPerThread(EntityInterface $comment) { - $query = $this->database->select('comment', 'c') + $query = $this->database->select('comment_field_data', 'c') ->condition('entity_id', $comment->getCommentedEntityId()) ->condition('field_name', $comment->getFieldName()) ->condition('entity_type', $comment->getCommentedEntityTypeId()) @@ -120,7 +120,7 @@ public function getMaxThreadPerThread(EntityInterface $comment) { * {@inheritdoc} */ public function getChildCids(array $comments) { - return $this->database->select('comment', 'c') + return $this->database->select('comment_field_data', 'c') ->fields('c', array('cid')) ->condition('pid', array_keys($comments)) ->execute() @@ -135,19 +135,16 @@ public function getSchema() { // Marking the respective fields as NOT NULL makes the indexes more // performant. - $schema['comment']['fields']['pid']['not null'] = TRUE; - $schema['comment']['fields']['status']['not null'] = TRUE; - $schema['comment']['fields']['entity_id']['not null'] = TRUE; - $schema['comment']['fields']['created']['not null'] = TRUE; - $schema['comment']['fields']['thread']['not null'] = TRUE; - - unset($schema['comment']['indexes']['field__pid']); - unset($schema['comment']['indexes']['field__entity_id']); - $schema['comment']['indexes'] += array( + $schema['comment_field_data']['fields']['created']['not null'] = TRUE; + $schema['comment_field_data']['fields']['thread']['not null'] = TRUE; + + unset($schema['comment_field_data']['indexes']['comment_field__pid__target_id']); + unset($schema['comment_field_data']['indexes']['comment_field__entity_id__target_id']); + $schema['comment_field_data']['indexes'] += array( 'comment__status_pid' => array('pid', 'status'), 'comment__num_new' => array( 'entity_id', - array('entity_type', 32), + 'entity_type', 'comment_type', 'status', 'created', @@ -156,13 +153,13 @@ public function getSchema() { ), 'comment__entity_langcode' => array( 'entity_id', - array('entity_type', 32), + 'entity_type', 'comment_type', - 'langcode', + 'default_langcode', ), 'comment__created' => array('created'), ); - $schema['comment']['foreign keys'] += array( + $schema['comment_field_data']['foreign keys'] += array( 'comment__author' => array( 'table' => 'users', 'columns' => array('uid' => 'uid'), diff --git a/core/modules/comment/src/Entity/Comment.php b/core/modules/comment/src/Entity/Comment.php index 1164756..a36aa5e 100644 --- a/core/modules/comment/src/Entity/Comment.php +++ b/core/modules/comment/src/Entity/Comment.php @@ -34,6 +34,7 @@ * "translation" = "Drupal\comment\CommentTranslationHandler" * }, * base_table = "comment", + * data_table = "comment_field_data", * uri_callback = "comment_uri", * fieldable = TRUE, * translatable = TRUE, @@ -228,6 +229,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['subject'] = FieldDefinition::create('string') ->setLabel(t('Subject')) ->setDescription(t('The comment title or subject.')) + ->setTranslatable(TRUE) ->setSetting('max_length', 64); $fields['uid'] = FieldDefinition::create('entity_reference') @@ -279,7 +281,8 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['entity_type'] = FieldDefinition::create('string') ->setLabel(t('Entity type')) - ->setDescription(t('The entity type to which this comment is attached.')); + ->setDescription(t('The entity type to which this comment is attached.')) + ->setSetting('max_length', EntityTypeInterface::ID_MAX_LENGTH); $fields['comment_type'] = FieldDefinition::create('entity_reference') ->setLabel(t('Comment Type')) @@ -289,7 +292,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['field_name'] = FieldDefinition::create('string') ->setLabel(t('Comment field name')) ->setDescription(t('The field name through which this comment was added.')) - ->setSetting('max_length', 32); + ->setSetting('max_length', FieldConfig::NAME_MAX_LENGTH); return $fields; }