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