annotate core/modules/comment/src/CommentStorageSchema.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
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@5 8 use Drupal\Core\Field\RequiredFieldStorageDefinitionInterface;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Defines the comment schema handler.
Chris@0 12 */
Chris@0 13 class CommentStorageSchema extends SqlContentEntityStorageSchema {
Chris@0 14
Chris@0 15 /**
Chris@0 16 * {@inheritdoc}
Chris@0 17 */
Chris@0 18 protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
Chris@0 19 $schema = parent::getEntitySchema($entity_type, $reset);
Chris@0 20
Chris@4 21 if ($data_table = $this->storage->getDataTable()) {
Chris@4 22 $schema[$data_table]['indexes'] += [
Chris@4 23 'comment__status_pid' => ['pid', 'status'],
Chris@4 24 'comment__num_new' => [
Chris@4 25 'entity_id',
Chris@4 26 'entity_type',
Chris@4 27 'comment_type',
Chris@4 28 'status',
Chris@4 29 'created',
Chris@4 30 'cid',
Chris@4 31 'thread',
Chris@4 32 ],
Chris@4 33 'comment__entity_langcode' => [
Chris@4 34 'entity_id',
Chris@4 35 'entity_type',
Chris@4 36 'comment_type',
Chris@4 37 'default_langcode',
Chris@4 38 ],
Chris@4 39 ];
Chris@4 40 }
Chris@0 41
Chris@0 42 return $schema;
Chris@0 43 }
Chris@0 44
Chris@0 45 /**
Chris@0 46 * {@inheritdoc}
Chris@0 47 */
Chris@0 48 protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
Chris@0 49 $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
Chris@0 50 $field_name = $storage_definition->getName();
Chris@0 51
Chris@0 52 if ($table_name == 'comment_field_data') {
Chris@0 53 // Remove unneeded indexes.
Chris@0 54 unset($schema['indexes']['comment_field__pid__target_id']);
Chris@0 55 unset($schema['indexes']['comment_field__entity_id__target_id']);
Chris@0 56
Chris@0 57 switch ($field_name) {
Chris@0 58 case 'thread':
Chris@0 59 // Improves the performance of the comment__num_new index defined
Chris@0 60 // in getEntitySchema().
Chris@0 61 $schema['fields'][$field_name]['not null'] = TRUE;
Chris@0 62 break;
Chris@0 63
Chris@5 64 case 'entity_type':
Chris@5 65 case 'field_name':
Chris@5 66 assert($storage_definition instanceof RequiredFieldStorageDefinitionInterface);
Chris@5 67 if ($storage_definition->isStorageRequired()) {
Chris@5 68 // The 'entity_type' and 'field_name' are required so they also need
Chris@5 69 // to be marked as NOT NULL.
Chris@5 70 $schema['fields'][$field_name]['not null'] = TRUE;
Chris@5 71 }
Chris@5 72 break;
Chris@5 73
Chris@0 74 case 'created':
Chris@0 75 $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
Chris@0 76 break;
Chris@0 77
Chris@0 78 case 'uid':
Chris@0 79 $this->addSharedTableFieldForeignKey($storage_definition, $schema, 'users', 'uid');
Chris@0 80 }
Chris@0 81 }
Chris@0 82
Chris@0 83 return $schema;
Chris@0 84 }
Chris@0 85
Chris@0 86 }