-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsimplify.install
147 lines (136 loc) · 4.58 KB
/
simplify.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
<?php
/**
* @file
* Install, update and uninstall functions for the Simplify module.
*/
/**
* Implements hook_install().
*
* Set default values in config files.
*/
function simplify_install() {
// Update module weight to allow it to run after other modules.
db_update('system')
->fields(array('weight' => 5))
->condition('name', 'simplify')
->execute();
// Global.
$config_global = config('simplify.global');
$types = array(
'nodes',
'users',
'comments',
'taxonomy',
'blocks',
);
foreach ($types as $type) {
$config_global->set($type, simplify_get_defaults($type));
}
$config_global->save();
// Nodes & comments.
$config_nodes = config('simplify.nodes');
$config_comments = config('simplify.comments');
$node_types = node_type_get_names();
foreach ($node_types as $type => $name) {
$config_nodes->set($type, simplify_get_defaults('nodes'));
$config_comments->set($type, simplify_get_defaults('comments'));
}
$config_nodes->save();
$config_comments->save();
// Taxonomy.
if (module_exists('taxonomy')) {
$config_taxonomy = config('simplify.taxonomy');
$vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
foreach ($vocabularies as $name => $vocabulary) {
$config_taxonomy->set($name, simplify_get_defaults('taxonomy'));
}
$config_taxonomy->save();
}
}
/**
* Update config files to the new format.
*/
function simplify_update_1100(&$sandbox) {
// Global.
$config_global = config('simplify.global');
$types = array(
'nodes',
'users',
'comments',
'taxonomy',
'blocks',
);
foreach ($types as $type) {
$existing_global = $config_global->get($type);
$config_global->set($type, simplify_get_defaults($type, $existing_global));
}
$config_global->save();
// Nodes & comments.
$config_nodes = config('simplify.nodes');
$config_comments = config('simplify.comments');
$node_types = node_type_get_names();
foreach ($node_types as $type => $name) {
$existing_nodes = $config_nodes->get($type);
$config_nodes->set($type, simplify_get_defaults('nodes', $existing_nodes));
$existing_comments = $config_comments->get($type);
$config_comments->set($type, simplify_get_defaults('comments', $existing_comments));
}
$config_nodes->save();
$config_comments->save();
// Taxonomy.
if (module_exists('taxonomy')) {
$config_taxonomy = config('simplify.taxonomy');
$vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
foreach ($vocabularies as $name => $vocabulary) {
$existing_taxonomy = $config_taxonomy->get($name);
$config_taxonomy->set($name, simplify_get_defaults('taxonomy', $existing_taxonomy));
}
$config_taxonomy->save();
}
}
/**
* Convert variables to config.
*/
function simplify_update_1000(&$sandbox) {
// Global.
$config_global = config('simplify.global');
$config_global->set('nodes', update_variable_get('simplify_nodes_global', array()));
$config_global->set('users', update_variable_get('simplify_users_global', array()));
$config_global->set('comments', update_variable_get('simplify_comments_global', array()));
$config_global->set('taxonomy', update_variable_get('simplify_taxonomy_global', array()));
$config_global->set('blocks', update_variable_get('simplify_blocks_global', array()));
$config_global->save();
update_variable_del('simplify_nodes_global');
update_variable_del('simplify_users_global');
update_variable_del('simplify_comments_global');
update_variable_del('simplify_taxonomy_global');
update_variable_del('simplify_blocks_global');
// Nodes & comments.
$node_types = node_type_get_names();
$config_nodes = config('simplify.nodes');
$config_comments = config('simplify.comments');
foreach ($node_types as $type => $name) {
$config_nodes->set($type, update_variable_get('simplify_nodes_' . $type, array()));
$config_comments->set($type, update_variable_get('simplify_comments_' . $type, array()));
update_variable_del('simplify_nodes_' . $type);
update_variable_del('simplify_comments_' . $type);
}
$config_nodes->save();
$config_comments->save();
// Taxonomy.
if (module_exists('taxonomy')) {
$vocabularies = taxonomy_vocabulary_load_multiple(FALSE);
$config_taxonomy = config('simplify.taxonomy');
foreach ($vocabularies as $name => $vocabulary) {
$config_taxonomy->set($name, update_variable_get('simplify_taxonomy_' . $name, array()));
update_variable_del('simplify_taxonomy_' . $name);
}
$config_taxonomy->save();
}
}
/**
* Implements hook_update_last_removed().
*/
function simplify_update_last_removed() {
return 7301;
}