Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\user;
|
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 user schema handler.
|
Chris@0
|
11 */
|
Chris@0
|
12 class UserStorageSchema 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);
|
Chris@0
|
19
|
Chris@17
|
20 if ($data_table = $this->storage->getDataTable()) {
|
Chris@17
|
21 $schema[$data_table]['unique keys'] += [
|
Chris@17
|
22 'user__name' => ['name', 'langcode'],
|
Chris@17
|
23 ];
|
Chris@17
|
24 }
|
Chris@0
|
25
|
Chris@0
|
26 return $schema;
|
Chris@0
|
27 }
|
Chris@0
|
28
|
Chris@0
|
29 /**
|
Chris@0
|
30 * {@inheritdoc}
|
Chris@0
|
31 */
|
Chris@0
|
32 protected function processIdentifierSchema(&$schema, $key) {
|
Chris@0
|
33 // The "users" table does not use serial identifiers.
|
Chris@0
|
34 if ($key != $this->entityType->getKey('id')) {
|
Chris@0
|
35 parent::processIdentifierSchema($schema, $key);
|
Chris@0
|
36 }
|
Chris@0
|
37 }
|
Chris@0
|
38
|
Chris@0
|
39 /**
|
Chris@0
|
40 * {@inheritdoc}
|
Chris@0
|
41 */
|
Chris@0
|
42 protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
|
Chris@0
|
43 $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
|
Chris@0
|
44 $field_name = $storage_definition->getName();
|
Chris@0
|
45
|
Chris@0
|
46 if ($table_name == 'users_field_data') {
|
Chris@0
|
47 switch ($field_name) {
|
Chris@0
|
48 case 'name':
|
Chris@0
|
49 // Improves the performance of the user__name index defined
|
Chris@0
|
50 // in getEntitySchema().
|
Chris@0
|
51 $schema['fields'][$field_name]['not null'] = TRUE;
|
Chris@0
|
52 // Make sure the field is no longer than 191 characters so we can
|
Chris@0
|
53 // add a unique constraint in MySQL.
|
Chris@18
|
54 $schema['fields'][$field_name]['length'] = UserInterface::USERNAME_MAX_LENGTH;
|
Chris@0
|
55 break;
|
Chris@0
|
56
|
Chris@0
|
57 case 'mail':
|
Chris@0
|
58 $this->addSharedTableFieldIndex($storage_definition, $schema);
|
Chris@0
|
59 break;
|
Chris@0
|
60
|
Chris@0
|
61 case 'access':
|
Chris@0
|
62 case 'created':
|
Chris@0
|
63 $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
|
Chris@0
|
64 break;
|
Chris@0
|
65 }
|
Chris@0
|
66 }
|
Chris@0
|
67
|
Chris@0
|
68 return $schema;
|
Chris@0
|
69 }
|
Chris@0
|
70
|
Chris@0
|
71 }
|