-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbiblio.install
310 lines (291 loc) · 8.38 KB
/
biblio.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<?php
/**
* @file
* Install file for the biblio module.
*/
/**
* Implements hook_install().
*/
function biblio_install() {
_biblio_install_add_biblio_roles();
}
/**
* Implements hook_enable().
*/
function biblio_enable() {
biblio_add_publication_types();
}
/**
* Add biblio roles vocabulary and terms.
*/
function _biblio_install_add_biblio_roles() {
if (!$vocabulary = taxonomy_vocabulary_machine_name_load('biblio_roles')) {
$vocabulary = new stdClass();
$vocabulary->name = 'Biblio roles';
$vocabulary->machine_name = 'biblio_roles';
taxonomy_vocabulary_save($vocabulary);
}
$term = new stdClass();
$term->name = "Author";
$term->vid = $vocabulary->vid;
taxonomy_term_save($term);
$term = new stdClass();
$term->name = "Editor";
$term->vid = $vocabulary->vid;
taxonomy_term_save($term);
}
/**
* Snapshot of the schema for biblio_update_7300().
*/
function biblio_schema_7300() {
$schema['biblio'] = array(
'fields' => array(
'bid' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => '',
'unsigned' => TRUE,
),
'title' => array(
'description' => 'The title of this Biblio, always treated as non-markup plain text.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'type' => array(
'description' => 'The publication type of the biblio',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'uid' => array(
'description' => 'The Drupal user ID who created this biblio.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'created' => array(
'type' => 'int',
'not null' => TRUE,
'description' => '',
),
'changed' => array(
'type' => 'int',
'not null' => TRUE,
'description' => '',
),
'cache_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'md5 of the style name and style options.',
),
'cache' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
'description' => 'The full HTML cache of the rendered Biblio, per its cache ID.',
),
'md5' => array(
'type' => 'varchar',
'length' => '32',
'not null' => FALSE,
'description' => '',
),
),
'primary key' => array('bid'),
'indexes' => array(
'bid' => array('bid'),
),
);
$schema['biblio_contributor'] = array(
'description' => 'Contains contributor information for each publication',
'fields' => array(
'cid' => array(
'type' => 'serial',
'not null' => TRUE,
'unsigned' => TRUE,
'description' => 'Primary Key: Author ID',
),
'aka' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Also known as, links this author entry with others so you can have variation on the name, but listing by cid will find all other (aka) author entries',
),
'drupal_uid' => array(
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
'description' => 'Drupal User ID',
),
'name' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
'description' => 'Full name',
),
'lastname' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
'description' => 'Author last name',
),
'firstname' => array(
'type' => 'varchar',
'length' => '128',
'not null' => FALSE,
'default' => '',
'description' => 'Author first name',
),
'prefix' => array(
'type' => 'varchar',
'length' => '128',
'not null' => FALSE,
'default' => '',
'description' => 'Author name prefix',
),
'suffix' => array(
'type' => 'varchar',
'length' => '128',
'not null' => FALSE,
'default' => '',
'description' => 'Author name suffix',
),
'initials' => array(
'type' => 'varchar',
'length' => '10',
'not null' => FALSE,
'default' => '',
'description' => 'Author initials (including first name initial)',
),
'affiliation' => array(
'type' => 'varchar',
'length' => '255',
'not null' => FALSE,
'default' => '',
'description' => 'Author affiliation or address',
),
'literal' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Determines if the author name is allowed to be reformated by the variaous styles or should be used literally.',
),
'md5' => array(
'type' => 'varchar',
'length' => '32',
'not null' => FALSE,
'description' => '',
),
'created' => array(
'description' => 'The Unix timestamp when the entry was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the entry was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'foreign keys' => array(
'biblio_contributor' => array(
'table' => 'biblio_contributor',
'columns' => array('cid' => 'cid'),
),
),
'primary key' => array('cid'),
'indexes' => array(
'lastname' => array('lastname'),
'firstname' => array('firstname'),
'initials' => array('initials')
),
);
$schema['biblio_type'] = array(
'description' => 'Stores information about the biblio types.',
'fields' => array(
'type' => array(
'description' => 'The machine-readable name of this type.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'name' => array(
'description' => 'The human-readable name of this type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'translatable' => TRUE,
),
'description' => array(
'description' => 'A brief description of this type.',
'type' => 'text',
'not null' => TRUE,
'size' => 'medium',
'translatable' => TRUE,
),
),
'primary key' => array('type'),
);
return $schema;
}
/**
* Implements hook_schema().
*/
function biblio_schema() {
return biblio_schema_7300();
}
/**
* Upgrade Biblio schema to 3.x.
*/
function biblio_update_7300() {
// Rename the old biblio tables.
$old_biblio_tables = array(
'biblio',
'biblio_collection',
'biblio_collection_type',
'biblio_contributor',
'biblio_contributor_type',
'biblio_contributor_type_data',
'biblio_duplicates',
'biblio_field_type',
'biblio_field_type_data',
'biblio_fields',
'biblio_import_cache',
'biblio_keyword',
'biblio_keyword_data',
'biblio_type_maps',
'biblio_types',
'biblio_vtabs',
);
foreach ($old_biblio_tables as $table) {
db_rename_table($table, "_{$table}_1x");
}
db_rename_table('biblio_contributor_data', 'biblio_contributor');
$schema = biblio_schema_7300();
db_add_field('biblio_contributor', 'created', $schema['biblio_contributor']['fields']['created']);
db_add_field('biblio_contributor', 'changed', $schema['biblio_contributor']['fields']['changed']);
unset($schema['biblio_contributor']);
foreach ($schema as $table => $table_schema) {
db_create_table($table, $table_schema);
}
// Enable the new needed modules. We also enable Biblio as we need to rely on
// it and create Biblio types.
if (!module_enable(array('biblio', 'biblio_ui', 'inline_entity_form', 'date', 'entity', 'entityreference', 'field_collection', 'libraries'))) {
throw new DrupalUpdateException('Inline entity form, Date, Entity reference, Field collection and Libraries modules must be present for Biblio 3.x.');
}
_biblio_install_add_biblio_roles();
biblio_add_publication_types();
biblio_create_fields_by_bundle();
return t('Old Biblio tables were renamed and the new tables were created.');
}