Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / forum / forum.install
1 <?php
2
3 /**
4  * @file
5  * Install, update, and uninstall functions for the Forum module.
6  */
7
8 use Drupal\field\Entity\FieldStorageConfig;
9 use Drupal\taxonomy\Entity\Term;
10
11 /**
12  * Implements hook_install().
13  */
14 function forum_install() {
15   // Set the weight of the forum.module to 1 so it is loaded after the taxonomy.module.
16   module_set_weight('forum', 1);
17   // Do not allow to delete the forum's node type machine name.
18   $locked = \Drupal::state()->get('node.type.locked');
19   $locked['forum'] = 'forum';
20   \Drupal::state()->set('node.type.locked', $locked);
21
22   if (!\Drupal::service('config.installer')->isSyncing()) {
23     // Create a default forum so forum posts can be created.
24     $term = Term::create([
25       'name' => t('General discussion'),
26       'description' => '',
27       'parent' => [0],
28       'vid' => 'forums',
29       'forum_container' => 0,
30     ]);
31     $term->save();
32   }
33 }
34
35 /**
36  * Implements hook_uninstall().
37  */
38 function forum_uninstall() {
39   if ($field_storage = FieldStorageConfig::loadByName('node', 'taxonomy_forums')) {
40     $field_storage->delete();
41   }
42
43   if ($field_storage = FieldStorageConfig::loadByName('node', 'comment_forum')) {
44     $field_storage->delete();
45   }
46
47   if ($field_storage = FieldStorageConfig::loadByName('taxonomy_term', 'forum_container')) {
48     $field_storage->delete();
49   }
50
51   // Purge field data now to allow taxonomy and options module to be uninstalled
52   // if this is the only field remaining.
53   field_purge_batch(10);
54   // Allow to delete a forum's node type.
55   $locked = \Drupal::state()->get('node.type.locked');
56   unset($locked['forum']);
57   \Drupal::state()->set('node.type.locked', $locked);
58 }
59
60 /**
61  * Implements hook_schema().
62  */
63 function forum_schema() {
64   $schema['forum'] = [
65     'description' => 'Stores the relationship of nodes to forum terms.',
66     'fields' => [
67       'nid' => [
68         'type' => 'int',
69         'unsigned' => TRUE,
70         'not null' => TRUE,
71         'default' => 0,
72         'description' => 'The {node}.nid of the node.',
73       ],
74       'vid' => [
75         'type' => 'int',
76         'unsigned' => TRUE,
77         'not null' => TRUE,
78         'default' => 0,
79         'description' => 'Primary Key: The {node}.vid of the node.',
80       ],
81       'tid' => [
82         'type' => 'int',
83         'unsigned' => TRUE,
84         'not null' => TRUE,
85         'default' => 0,
86         'description' => 'The {taxonomy_term_data}.tid of the forum term assigned to the node.',
87       ],
88     ],
89     'indexes' => [
90       'forum_topic' => ['nid', 'tid'],
91       'tid' => ['tid'],
92     ],
93     'primary key' => ['vid'],
94     'foreign keys' => [
95       'forum_node' => [
96         'table' => 'node',
97         'columns' => [
98           'nid' => 'nid',
99           'vid' => 'vid',
100         ],
101       ],
102     ],
103   ];
104
105   $schema['forum_index'] = [
106     'description' => 'Maintains denormalized information about node/term relationships.',
107     'fields' => [
108       'nid' => [
109         'description' => 'The {node}.nid this record tracks.',
110         'type' => 'int',
111         'unsigned' => TRUE,
112         'not null' => TRUE,
113         'default' => 0,
114       ],
115       'title' => [
116         'description' => 'The node title.',
117         'type' => 'varchar',
118         'length' => 255,
119         'not null' => TRUE,
120         'default' => '',
121       ],
122       'tid' => [
123          'description' => 'The term ID.',
124          'type' => 'int',
125          'unsigned' => TRUE,
126          'not null' => TRUE,
127          'default' => 0,
128       ],
129       'sticky' => [
130         'description' => 'Boolean indicating whether the node is sticky.',
131         'type' => 'int',
132         'not null' => FALSE,
133         'default' => 0,
134         'size' => 'tiny',
135       ],
136       'created' => [
137         'description' => 'The Unix timestamp when the node was created.',
138         'type' => 'int',
139         'unsigned' => TRUE,
140         'not null' => TRUE,
141         'default' => 0,
142       ],
143       'last_comment_timestamp' => [
144         'type' => 'int',
145         'not null' => TRUE,
146         'default' => 0,
147         'description' => 'The Unix timestamp of the last comment that was posted within this node, from {comment}.timestamp.',
148       ],
149       'comment_count' => [
150         'type' => 'int',
151         'unsigned' => TRUE,
152         'not null' => TRUE,
153         'default' => 0,
154         'description' => 'The total number of comments on this node.',
155       ],
156     ],
157     'indexes' => [
158       'forum_topics' => ['nid', 'tid', 'sticky', 'last_comment_timestamp'],
159       'created' => ['created'],
160       'last_comment_timestamp' => ['last_comment_timestamp'],
161     ],
162     'foreign keys' => [
163       'tracked_node' => [
164         'table' => 'node',
165         'columns' => ['nid' => 'nid'],
166       ],
167       'term' => [
168         'table' => 'taxonomy_term_data',
169         'columns' => [
170           'tid' => 'tid',
171         ],
172       ],
173     ],
174   ];
175
176   return $schema;
177 }