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