annotate core/modules/comment/src/CommentStorageSchema.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
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\comment;
Chris@0 4
Chris@0 5 use Drupal\Core\Entity\ContentEntityTypeInterface;
Chris@0 6 use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;
Chris@0 7 use Drupal\Core\Field\FieldStorageDefinitionInterface;
Chris@0 8
Chris@0 9 /**
Chris@0 10 * Defines the comment schema handler.
Chris@0 11 */
Chris@0 12 class CommentStorageSchema extends SqlContentEntityStorageSchema {
Chris@0 13
Chris@0 14 /**
Chris@0 15 * {@inheritdoc}
Chris@0 16 */
Chris@0 17 protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
Chris@0 18 $schema = parent::getEntitySchema($entity_type, $reset);
Chris@0 19
Chris@4 20 if ($data_table = $this->storage->getDataTable()) {
Chris@4 21 $schema[$data_table]['indexes'] += [
Chris@4 22 'comment__status_pid' => ['pid', 'status'],
Chris@4 23 'comment__num_new' => [
Chris@4 24 'entity_id',
Chris@4 25 'entity_type',
Chris@4 26 'comment_type',
Chris@4 27 'status',
Chris@4 28 'created',
Chris@4 29 'cid',
Chris@4 30 'thread',
Chris@4 31 ],
Chris@4 32 'comment__entity_langcode' => [
Chris@4 33 'entity_id',
Chris@4 34 'entity_type',
Chris@4 35 'comment_type',
Chris@4 36 'default_langcode',
Chris@4 37 ],
Chris@4 38 ];
Chris@4 39 }
Chris@0 40
Chris@0 41 return $schema;
Chris@0 42 }
Chris@0 43
Chris@0 44 /**
Chris@0 45 * {@inheritdoc}
Chris@0 46 */
Chris@0 47 protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
Chris@0 48 $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
Chris@0 49 $field_name = $storage_definition->getName();
Chris@0 50
Chris@0 51 if ($table_name == 'comment_field_data') {
Chris@0 52 // Remove unneeded indexes.
Chris@0 53 unset($schema['indexes']['comment_field__pid__target_id']);
Chris@0 54 unset($schema['indexes']['comment_field__entity_id__target_id']);
Chris@0 55
Chris@0 56 switch ($field_name) {
Chris@0 57 case 'thread':
Chris@0 58 // Improves the performance of the comment__num_new index defined
Chris@0 59 // in getEntitySchema().
Chris@0 60 $schema['fields'][$field_name]['not null'] = TRUE;
Chris@0 61 break;
Chris@0 62
Chris@0 63 case 'created':
Chris@0 64 $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
Chris@0 65 break;
Chris@0 66
Chris@0 67 case 'uid':
Chris@0 68 $this->addSharedTableFieldForeignKey($storage_definition, $schema, 'users', 'uid');
Chris@0 69 }
Chris@0 70 }
Chris@0 71
Chris@0 72 return $schema;
Chris@0 73 }
Chris@0 74
Chris@0 75 }