forked from GetDKAN/dkan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dkan.install
253 lines (220 loc) · 8.64 KB
/
dkan.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
<?php
/**
* @file
* Install functions and update hooks for DKAN profile.
*/
/**
* Reverts dkan_sitewide to add Markdown filter. Sets up roleassign feature.
*/
function dkan_update_7001() {
module_load_include("profile", "dkan");
dkan_bueditor_markdown_install();
}
/**
* Rename a field.
*
* Addapted from field_rename_rename_fields() in 'Field Rename' module.
*
* @param string $old_field_name
* The old name of the field.
* @param string $new_field_name
* The new name of the field.
*/
function dkan_rename_field($old_field_name, $new_field_name) {
$messages = array();
// Read field data.
$old_field = field_read_field($old_field_name);
if (empty($old_field)) {
$messages[] = t('The field %old_field_name does not exist so it cannot be renamed.', array('%old_field_name' => $old_field_name));
return $messages;
}
try {
// Update {field_config}.
db_update('field_config')
->fields(array('field_name' => $new_field_name))
->condition('id', $old_field['id'])
->execute();
// Update {field_config_instance}.
db_update('field_config_instance')
->fields(array('field_name' => $new_field_name))
->condition('field_id', $old_field['id'])
->execute();
// The tables that need updating in the form 'old_name' => 'new_name'.
$tables = array(
'field_data_' . $old_field_name => 'field_data_' . $new_field_name,
'field_revision_' . $old_field_name => 'field_revision_' . $new_field_name,
);
// Iterate through tables to be redefined and renamed.
foreach ($tables as $old_table => $new_table) {
// Iterate through the field's columns. For example, a 'text' field will
// have columns 'value' and 'format'.
foreach ($old_field['columns'] as $column_name => $column_definition) {
// Column names are in the format {field_name}_{column_name}.
$old_column_name = $old_field_name . '_' . $column_name;
$new_column_name = $new_field_name . '_' . $column_name;
// If there is an index for the field, drop and then re-add it.
$has_index = isset($old_field['indexes'][$column_name]) && ($old_field['indexes'][$column_name] == array($column_name));
if ($has_index) {
db_drop_index($old_table, $old_column_name);
}
// Rename the column.
db_change_field($old_table, $old_column_name, $new_column_name, $column_definition);
if ($has_index) {
db_drop_index($old_table, $new_column_name);
db_add_index($old_table, $new_column_name, array($new_column_name));
}
}
// The new table may exist e.g. due to having been included in a feature
// that was reverted prior to this update being run. If so, we need to
// drop the new table so that the old one can be renamed.
if (db_table_exists($new_table)) {
db_drop_table($new_table);
}
// Rename the table.
db_rename_table($old_table, $new_table);
}
}
catch (Exception $e) {
$messages[] = t('The field %old_field_name could not be renamed because there was an error: %error.',
array('%old_field_name' => $old_field_name, '%error' => $e->getMessage()));
}
cache_clear_all('*', 'cache_field', TRUE);
return $messages;
}
/**
* Update the default jquery library to 1.10.
*/
function dkan_update_7002() {
if (version_compare(variable_get('jquery_update_jquery_version'), '1.10', '<')) {
variable_set('jquery_update_jquery_version', '1.10');
}
}
/**
* Disable the dkan_default_content module.
*/
function dkan_update_7005() {
db_update('system')
->fields(array('status' => '0'))
->condition('name', 'dkan_default_content')
->execute();
}
/**
* We need to revert field instances.
*
* This is required for the next update in another case
* we have problem with new fields added on version 12.
*/
function dkan_update_7006() {
module_enable(array('field_hidden'));
features_revert(array('dkan_datastore' => array('field_base', 'field_instance')));
}
/**
* Resource group field.
*
* Groups cannot be edited manually on resources anymore. Group affiliation
* will be inherited from parent datasets. This update hook was added to be sure
* that all resources that do not have groups assigned are synchronized and
* updated with the groups from the parent datasets.
*/
function dkan_update_7007(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['max'] = db_query("SELECT COUNT(DISTINCT fdr.field_dataset_ref_target_id) FROM {node} n LEFT JOIN {field_data_field_dataset_ref} fdr ON fdr.entity_id=n.nid LEFT JOIN {og_membership} og ON n.nid=og.etid WHERE n.type='resource' AND og.etid IS NULL AND fdr.field_dataset_ref_target_id IN (SELECT etid FROM {og_membership} WHERE etid IN (SELECT field_dataset_ref_target_id FROM {field_data_field_dataset_ref}))")->fetchField();
}
// Get all resources without group but the parent dataset has groups.
$result = db_query("SELECT DISTINCT fdr.field_dataset_ref_target_id FROM {node} n LEFT JOIN {field_data_field_dataset_ref} fdr ON fdr.entity_id=n.nid LEFT JOIN {og_membership} og ON n.nid=og.etid WHERE n.type='resource' AND og.etid IS NULL AND fdr.field_dataset_ref_target_id IN (SELECT etid FROM {og_membership} WHERE etid IN (SELECT field_dataset_ref_target_id FROM {field_data_field_dataset_ref})) LIMIT 0,10");
foreach ($result as $item) {
// Simulate a empty original.
// The 'dkan_dataset_sync_groups' function synchronizes
// the groups only when a change on the dataset is detected.
$original = new stdClass();
$original->type = 'dataset';
$original->og_group_ref = array();
$dataset = node_load($item->field_dataset_ref_target_id);
$dataset->original = $original;
dkan_dataset_sync_groups($dataset);
$sandbox['progress']++;
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
return t('All resources without group were updated.');
}
/**
* Point source menu to the command menu center in dkan workflow roles.
*/
function dkan_update_7008() {
if (module_exists('dkan_workflow')) {
dkan_workflow_admin_menu_source();
}
}
/**
* Flush client site colorizer file to grab new updates.
*/
function dkan_update_7009() {
$theme = $GLOBALS['theme'];
$instance = $theme;
variable_del('colorizer_' . $instance . '_files');
colorizer_clearcache();
cache_clear_all();
}
/**
* Disable/uninstall deprecated dkan_dataset_api, enable open_data_schema_map.
*/
function dkan_update_7010() {
if (module_exists('dkan_dataset_api')) {
module_disable(array('dkan_dataset_api'));
drupal_uninstall_modules(array('dkan_dataset_api'));
module_enable(array('open_data_schema_map'));
}
}
/**
* Update copyright information.
*/
function dkan_update_7011() {
$settings = variable_get('theme_nuboot_radix_settings', array());
if ($settings['copyright']['value'] == 'Powered by <a href="http://nucivic.com/dkan">DKAN</a>, a project of <a href="http://nucivic.com">NuCivic</a>') {
$settings['copyright']['value'] = t('Powered by <a href="http://getdkan.com/">DKAN</a>, a project of <a href="http://granicus.com">Granicus</a>');
variable_set('theme_nuboot_radix_settings', $settings);
}
}
/**
* Clean up db on upgrade to 7.x-1.13.
*
* Deprecated modules: Conditional Fields, Entity RDF, RDF UI, RDF Extensions.
*/
function dkan_update_7012() {
$modules = array(
'conditional_fields',
'entity_rdf',
'rdfui',
'rdfx',
);
db_delete('system')
->condition('name', $modules, 'IN')
->condition('type', 'module')
->execute();
db_drop_table('conditional_fields');
db_drop_table('rdfx_namespaces');
db_drop_table('rdfx_term_details');
db_drop_table('rdfx_term_domains');
db_drop_table('rdfx_term_inverses');
db_drop_table('rdfx_term_ranges');
db_drop_table('rdfx_term_superclasses');
db_drop_table('rdfx_term_superproperties');
db_drop_table('rdfx_term_types');
db_drop_table('rdfx_terms');
db_drop_table('rdfx_vocabulary_details');
db_drop_table('rdfx_vocabulary_graphs');
}
/**
* Remove deprecated test and theme directories.
*/
function dkan_update_7013() {
drush_delete_dir('profiles/dkan/modules/dkan/dkan_dataset/fonts');
drush_delete_dir('profiles/dkan/modules/dkan/dkan_dataset/tests');
drush_delete_dir('profiles/dkan/modules/dkan/dkan_datastore/tests');
drush_delete_dir('profiles/dkan/modules/dkan/dkan_datastore/modules/dkan_datastore_api/tests');
drush_delete_dir('profiles/dkan/modules/dkan/dkan_datastore/modules/dkan_datastore_fast_import/test');
drush_delete_dir('profiles/dkan/modules/dkan/dkan_workflow/test');
drush_delete_dir('profiles/dkan/themes/contrib/nuboot_radix');
drush_delete_dir('profiles/dkan/themes/contrib/omega');
}