-
Notifications
You must be signed in to change notification settings - Fork 11
/
paragraphs.install
245 lines (223 loc) · 6.14 KB
/
paragraphs.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
/**
* @file
* Install, update and uninstall functions for the paragraphs module.
*/
/**
* Implements hook_schema().
*/
function paragraphs_schema() {
$schema = array();
$schema['paragraphs_item'] = array(
'description' => 'Stores information about paragraph items.',
'fields' => array(
'item_id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique paragraph item ID.',
),
'revision_id' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'Default revision ID.',
),
'bundle' => array(
'description' => 'The Paragraph type of this item.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'field_name' => array(
'description' => 'Field name of the host entity.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'archived' => array(
'description' => 'Boolean indicating whether the Paragraphs item is archived.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'status' => array(
'description' => 'Boolean indicating whether the Paragraphs item is published.',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
),
'primary key' => array('item_id'),
);
$schema['paragraphs_item_revision'] = array(
'description' => 'Stores revision information about Paragraph items.',
'fields' => array(
'revision_id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique revision ID.',
),
'item_id' => array(
'type' => 'int',
'not null' => TRUE,
'description' => 'Paragraph item ID.',
),
),
'primary key' => array('revision_id'),
'indexes' => array(
'item_id' => array('item_id'),
),
'foreign keys' => array(
'versioned_paragraphs_item' => array(
'table' => 'paragraphs_item',
'columns' => array('item_id' => 'item_id'),
),
),
);
// Entity Cache is now in core, include the entity cache schema by default.
$cache_schema = backdrop_get_schema_unprocessed('system', 'cache');
$cache_schema['description'] = 'Cache table used to store paragraphs_item entity records.';
$schema['cache_entity_paragraphs_item'] = $cache_schema;
return $schema;
}
/**
* Implements hook_field_schema().
*/
function paragraphs_field_schema($field) {
$columns = array();
if ($field['type'] == 'paragraphs') {
$columns = array(
'value' => array(
'type' => 'int',
'not null' => FALSE,
'description' => 'The Paragraph item id.',
),
'revision_id' => array(
'type' => 'int',
'not null' => FALSE,
'description' => 'The Paragraph item revision id.',
),
);
}
return array(
'columns' => $columns,
);
}
/**
* Implements hook_requirements().
*/
function paragraphs_requirements($phase) {
$t = get_t();
$requirements = array();
// Make sure schema version is appropriate.
if (backdrop_get_installed_schema_version('paragraphs') == 7102) {
backdrop_set_installed_schema_version('paragraphs', 999);
}
if ($phase == 'runtime') {
if (!module_exists('entity_plus')) {
$requirements['paragraphs'] = array(
'title' => $t('Paragraphs'),
'value' => $t('Required module is not installed'),
'description' => $t('Paragraphs requires the Entity Plus module to be installed.'),
'severity' => REQUIREMENT_ERROR,
);
}
}
return $requirements;
}
/**
* Implements hook_uninstall().
*/
function paragraphs_uninstall() {
if (db_table_exists('cache_entity_paragraphs_item')) {
db_drop_table('cache_entity_paragraphs_item');
}
}
/**
* Implements hook_update_last_removed().
*/
function paragraphs_update_last_removed() {
return 7101;
}
/**
* Update {paragraphs_bundle} schema to include label and description fields.
*/
function paragraphs_update_1000() {
if (!db_table_exists('paragraphs_bundle')) {
return;
}
$fields = array(
'label' => array(
'description' => 'A user-facing label for this Paragraph type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'A brief description of this Paragraph type.',
'type' => 'text',
'not null' => FALSE,
'size' => 'medium',
'default' => NULL,
),
);
foreach ($fields as $key => $field) {
if (!db_field_exists('paragraphs_bundle', $key)) {
db_add_field('paragraphs_bundle', $key, $field);
}
}
// Set initial label value equal to name.
db_update('paragraphs_bundle')
->expression('label', 'name')
->execute();
}
/**
* Updates paragraphs bundle to CMI.
*/
function paragraphs_update_1001() {
if (!db_table_exists('paragraphs_bundle')) {
return;
}
$bundles = array();
$query = db_select('paragraphs_bundle', 'pb')
->fields('pb')
->orderBy('pb.bundle', 'ASC');
foreach ($query->execute() as $bundle_object) {
$bundles[$bundle_object->bundle] = $bundle_object;
}
foreach ($bundles as $bundle) {
paragraphs_bundle_save($bundle);
}
db_drop_table('paragraphs_bundle');
}
/**
* Ensure entity cache table is created for Paragraphs items.
*/
function paragraphs_update_1002() {
module_load_include('module', 'paragraphs');
paragraphs_ensure_entitycache_table();
}
/**
* Add status field for paragraphs bundle and item.
*/
function paragraphs_update_1003() {
$status = array(
'description' => 'Boolean indicating whether the paragraph item is published.',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
);
db_add_field('paragraphs_item', 'status', $status);
}
/**
* Drop paragraphs_bundle table.
*/
function paragraphs_update_1004() {
if (!db_table_exists('paragraphs_bundle')) {
return;
}
// New installs were creating the table from the schema, but the config is all
// in CMI now. The schema is now removed but need to ensure the table is
// dropped.
db_drop_table('paragraphs_bundle');
}