Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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);
19
20     if ($data_table = $this->storage->getDataTable()) {
21       $schema[$data_table]['indexes'] += [
22         'taxonomy_term__tree' => ['vid', 'weight', 'name'],
23         'taxonomy_term__vid_name' => ['vid', 'name'],
24       ];
25     }
26
27     $schema['taxonomy_index'] = [
28       'description' => 'Maintains denormalized information about node/term relationships.',
29       'fields' => [
30         'nid' => [
31           'description' => 'The {node}.nid this record tracks.',
32           'type' => 'int',
33           'unsigned' => TRUE,
34           'not null' => TRUE,
35           'default' => 0,
36         ],
37         'tid' => [
38           'description' => 'The term ID.',
39           'type' => 'int',
40           'unsigned' => TRUE,
41           'not null' => TRUE,
42           'default' => 0,
43         ],
44         'status' => [
45           'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
46           'type' => 'int',
47           'not null' => TRUE,
48           'default' => 1,
49         ],
50         'sticky' => [
51           'description' => 'Boolean indicating whether the node is sticky.',
52           'type' => 'int',
53           'not null' => FALSE,
54           'default' => 0,
55           'size' => 'tiny',
56         ],
57         'created' => [
58           'description' => 'The Unix timestamp when the node was created.',
59           'type' => 'int',
60           'not null' => TRUE,
61           'default' => 0,
62         ],
63       ],
64       'primary key' => ['nid', 'tid'],
65       'indexes' => [
66         'term_node' => ['tid', 'status', 'sticky', 'created'],
67       ],
68       'foreign keys' => [
69         'tracked_node' => [
70           'table' => 'node',
71           'columns' => ['nid' => 'nid'],
72         ],
73         'term' => [
74           'table' => 'taxonomy_term_data',
75           'columns' => ['tid' => 'tid'],
76         ],
77       ],
78     ];
79
80     return $schema;
81   }
82
83   /**
84    * {@inheritdoc}
85    */
86   protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
87     $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
88     $field_name = $storage_definition->getName();
89
90     if ($table_name == 'taxonomy_term_field_data') {
91       // Remove unneeded indexes.
92       unset($schema['indexes']['taxonomy_term_field__vid__target_id']);
93       unset($schema['indexes']['taxonomy_term_field__description__format']);
94
95       switch ($field_name) {
96         case 'weight':
97           // Improves the performance of the taxonomy_term__tree index defined
98           // in getEntitySchema().
99           $schema['fields'][$field_name]['not null'] = TRUE;
100           break;
101
102         case 'name':
103           $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
104           break;
105       }
106     }
107
108     return $schema;
109   }
110
111 }