forked from GetDKAN/dkan
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdkan.install
162 lines (141 loc) · 5.12 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
<?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');
}
}
/**
* Remove modules on upgrade to 7.x-1.13.
* Conditional Fields, Entity RDF, RDF UI, RDF Extensions.
*/
function dkan_update_7003() {
$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_7004() {
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');
}
/**
* Disable the dkan_default_content module.
*/
function dkan_update_7005() {
db_update('system')
->fields(array('status' => '0',))
->condition ('name', 'dkan_default_content')
->execute();
}