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