Mercurial > hg > isophonics-drupal-site
comparison core/modules/comment/src/CommentStorageSchema.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
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 $schema['comment_field_data']['indexes'] += [ | |
21 'comment__status_pid' => ['pid', 'status'], | |
22 'comment__num_new' => [ | |
23 'entity_id', | |
24 'entity_type', | |
25 'comment_type', | |
26 'status', | |
27 'created', | |
28 'cid', | |
29 'thread', | |
30 ], | |
31 'comment__entity_langcode' => [ | |
32 'entity_id', | |
33 'entity_type', | |
34 'comment_type', | |
35 'default_langcode', | |
36 ], | |
37 ]; | |
38 | |
39 return $schema; | |
40 } | |
41 | |
42 /** | |
43 * {@inheritdoc} | |
44 */ | |
45 protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) { | |
46 $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping); | |
47 $field_name = $storage_definition->getName(); | |
48 | |
49 if ($table_name == 'comment_field_data') { | |
50 // Remove unneeded indexes. | |
51 unset($schema['indexes']['comment_field__pid__target_id']); | |
52 unset($schema['indexes']['comment_field__entity_id__target_id']); | |
53 | |
54 switch ($field_name) { | |
55 case 'thread': | |
56 // Improves the performance of the comment__num_new index defined | |
57 // in getEntitySchema(). | |
58 $schema['fields'][$field_name]['not null'] = TRUE; | |
59 break; | |
60 | |
61 case 'created': | |
62 $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE); | |
63 break; | |
64 | |
65 case 'uid': | |
66 $this->addSharedTableFieldForeignKey($storage_definition, $schema, 'users', 'uid'); | |
67 } | |
68 } | |
69 | |
70 return $schema; | |
71 } | |
72 | |
73 } |