Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\taxonomy;
|
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 term schema handler.
|
Chris@0
|
11 */
|
Chris@0
|
12 class TermStorageSchema 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@17
|
18 $schema = parent::getEntitySchema($entity_type, $reset);
|
Chris@0
|
19
|
Chris@17
|
20 if ($data_table = $this->storage->getDataTable()) {
|
Chris@17
|
21 $schema[$data_table]['indexes'] += [
|
Chris@17
|
22 'taxonomy_term__tree' => ['vid', 'weight', 'name'],
|
Chris@17
|
23 'taxonomy_term__vid_name' => ['vid', 'name'],
|
Chris@17
|
24 ];
|
Chris@17
|
25 }
|
Chris@0
|
26
|
Chris@0
|
27 $schema['taxonomy_index'] = [
|
Chris@0
|
28 'description' => 'Maintains denormalized information about node/term relationships.',
|
Chris@0
|
29 'fields' => [
|
Chris@0
|
30 'nid' => [
|
Chris@0
|
31 'description' => 'The {node}.nid this record tracks.',
|
Chris@0
|
32 'type' => 'int',
|
Chris@0
|
33 'unsigned' => TRUE,
|
Chris@0
|
34 'not null' => TRUE,
|
Chris@0
|
35 'default' => 0,
|
Chris@0
|
36 ],
|
Chris@0
|
37 'tid' => [
|
Chris@0
|
38 'description' => 'The term ID.',
|
Chris@0
|
39 'type' => 'int',
|
Chris@0
|
40 'unsigned' => TRUE,
|
Chris@0
|
41 'not null' => TRUE,
|
Chris@0
|
42 'default' => 0,
|
Chris@0
|
43 ],
|
Chris@0
|
44 'status' => [
|
Chris@0
|
45 'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
|
Chris@0
|
46 'type' => 'int',
|
Chris@0
|
47 'not null' => TRUE,
|
Chris@0
|
48 'default' => 1,
|
Chris@0
|
49 ],
|
Chris@0
|
50 'sticky' => [
|
Chris@0
|
51 'description' => 'Boolean indicating whether the node is sticky.',
|
Chris@0
|
52 'type' => 'int',
|
Chris@0
|
53 'not null' => FALSE,
|
Chris@0
|
54 'default' => 0,
|
Chris@0
|
55 'size' => 'tiny',
|
Chris@0
|
56 ],
|
Chris@0
|
57 'created' => [
|
Chris@0
|
58 'description' => 'The Unix timestamp when the node was created.',
|
Chris@0
|
59 'type' => 'int',
|
Chris@0
|
60 'not null' => TRUE,
|
Chris@0
|
61 'default' => 0,
|
Chris@0
|
62 ],
|
Chris@0
|
63 ],
|
Chris@0
|
64 'primary key' => ['nid', 'tid'],
|
Chris@0
|
65 'indexes' => [
|
Chris@0
|
66 'term_node' => ['tid', 'status', 'sticky', 'created'],
|
Chris@0
|
67 ],
|
Chris@0
|
68 'foreign keys' => [
|
Chris@0
|
69 'tracked_node' => [
|
Chris@0
|
70 'table' => 'node',
|
Chris@0
|
71 'columns' => ['nid' => 'nid'],
|
Chris@0
|
72 ],
|
Chris@0
|
73 'term' => [
|
Chris@0
|
74 'table' => 'taxonomy_term_data',
|
Chris@0
|
75 'columns' => ['tid' => 'tid'],
|
Chris@0
|
76 ],
|
Chris@0
|
77 ],
|
Chris@0
|
78 ];
|
Chris@0
|
79
|
Chris@0
|
80 return $schema;
|
Chris@0
|
81 }
|
Chris@0
|
82
|
Chris@0
|
83 /**
|
Chris@0
|
84 * {@inheritdoc}
|
Chris@0
|
85 */
|
Chris@0
|
86 protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
|
Chris@0
|
87 $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
|
Chris@0
|
88 $field_name = $storage_definition->getName();
|
Chris@0
|
89
|
Chris@0
|
90 if ($table_name == 'taxonomy_term_field_data') {
|
Chris@0
|
91 // Remove unneeded indexes.
|
Chris@0
|
92 unset($schema['indexes']['taxonomy_term_field__vid__target_id']);
|
Chris@0
|
93 unset($schema['indexes']['taxonomy_term_field__description__format']);
|
Chris@0
|
94
|
Chris@0
|
95 switch ($field_name) {
|
Chris@0
|
96 case 'weight':
|
Chris@0
|
97 // Improves the performance of the taxonomy_term__tree index defined
|
Chris@0
|
98 // in getEntitySchema().
|
Chris@0
|
99 $schema['fields'][$field_name]['not null'] = TRUE;
|
Chris@0
|
100 break;
|
Chris@0
|
101
|
Chris@0
|
102 case 'name':
|
Chris@0
|
103 $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
|
Chris@0
|
104 break;
|
Chris@0
|
105 }
|
Chris@0
|
106 }
|
Chris@0
|
107
|
Chris@0
|
108 return $schema;
|
Chris@0
|
109 }
|
Chris@0
|
110
|
Chris@18
|
111 /**
|
Chris@18
|
112 * {@inheritdoc}
|
Chris@18
|
113 */
|
Chris@18
|
114 protected function getDedicatedTableSchema(FieldStorageDefinitionInterface $storage_definition, ContentEntityTypeInterface $entity_type = NULL) {
|
Chris@18
|
115 $dedicated_table_schema = parent::getDedicatedTableSchema($storage_definition, $entity_type);
|
Chris@18
|
116
|
Chris@18
|
117 // Add an index on 'bundle', 'delta' and 'parent_target_id' columns to
|
Chris@18
|
118 // increase the performance of the query from
|
Chris@18
|
119 // \Drupal\taxonomy\TermStorage::getVocabularyHierarchyType().
|
Chris@18
|
120 if ($storage_definition->getName() === 'parent') {
|
Chris@18
|
121 /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
|
Chris@18
|
122 $table_mapping = $this->storage->getTableMapping();
|
Chris@18
|
123 $dedicated_table_name = $table_mapping->getDedicatedDataTableName($storage_definition);
|
Chris@18
|
124
|
Chris@18
|
125 unset($dedicated_table_schema[$dedicated_table_name]['indexes']['bundle']);
|
Chris@18
|
126 $dedicated_table_schema[$dedicated_table_name]['indexes']['bundle_delta_target_id'] = [
|
Chris@18
|
127 'bundle',
|
Chris@18
|
128 'delta',
|
Chris@18
|
129 $table_mapping->getFieldColumnName($storage_definition, 'target_id'),
|
Chris@18
|
130 ];
|
Chris@18
|
131 }
|
Chris@18
|
132
|
Chris@18
|
133 return $dedicated_table_schema;
|
Chris@18
|
134 }
|
Chris@18
|
135
|
Chris@0
|
136 }
|