annotate core/modules/comment/src/CommentStorageSchema.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
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@18 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@17 21 if ($data_table = $this->storage->getDataTable()) {
Chris@17 22 $schema[$data_table]['indexes'] += [
Chris@17 23 'comment__status_pid' => ['pid', 'status'],
Chris@17 24 'comment__num_new' => [
Chris@17 25 'entity_id',
Chris@17 26 'entity_type',
Chris@17 27 'comment_type',
Chris@17 28 'status',
Chris@17 29 'created',
Chris@17 30 'cid',
Chris@17 31 'thread',
Chris@17 32 ],
Chris@17 33 'comment__entity_langcode' => [
Chris@17 34 'entity_id',
Chris@17 35 'entity_type',
Chris@17 36 'comment_type',
Chris@17 37 'default_langcode',
Chris@17 38 ],
Chris@17 39 ];
Chris@17 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@18 64 case 'entity_type':
Chris@18 65 case 'field_name':
Chris@18 66 assert($storage_definition instanceof RequiredFieldStorageDefinitionInterface);
Chris@18 67 if ($storage_definition->isStorageRequired()) {
Chris@18 68 // The 'entity_type' and 'field_name' are required so they also need
Chris@18 69 // to be marked as NOT NULL.
Chris@18 70 $schema['fields'][$field_name]['not null'] = TRUE;
Chris@18 71 }
Chris@18 72 break;
Chris@18 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 }