-
Notifications
You must be signed in to change notification settings - Fork 5
/
diff.install
157 lines (143 loc) · 5.96 KB
/
diff.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
<?php
/**
* Implements hook_uninstall().
*/
function diff_uninstall() {
// Clear diff config entries from all node type settings.
$node_types = node_type_get_types();
foreach ($node_types as $type_name => $node_data) {
$config = config("node.type.$type_name");
$config->clear('settings.diff_show_preview_changes_node');
$config->clear('settings.diff_enable_revisions_page_node');
$config->clear('settings.diff_view_mode_preview_node');
$config->save();
}
}
/**
* Some config settings were incorrect in diff version 1.x-3.2.0
* Recover any incorrect existing settings.
*/
function diff_update_1001()
{
$config = config('diff.settings');
$settings = $config->get();
if (isset($settings['diff_admin_path_node'])) {
$config->set('diff_admin_path.node', $config->get('diff_admin_path_node'));
$config->clear('diff_admin_path_node');
}
if (isset($settings['diff_admin_path_user'])) {
$config->set('diff_admin_path.user', $config->get('diff_admin_path_user'));
$config->clear('diff_admin_path_user');
}
if (isset($settings['diff_default_state_node'])) {
$config->set('diff_default_state.node', $config->get('diff_default_state_node'));
$config->clear('diff_default_state_node');
}
if (isset($settings['diff_default_state_user'])) {
$config->set('diff_default_state.user', $config->get('diff_default_state_user'));
$config->clear('diff_default_state_user');
}
if (isset($settings['diff_show_header_node'])) {
$config->set('diff_show_header.node', $config->get('diff_show_header_node'));
$config->clear('diff_show_header_node');
}
if (isset($settings['diff_show_header_user'])) {
$config->set('diff_show_header.user', $config->get('diff_show_header_user'));
$config->clear('diff_show_header_user');
}
if (isset($settings['diff_additional_options_node'])) {
$config->set('diff_additional_options.node', $config->get('diff_additional_options_node'));
$config->clear('diff_additional_options_node');
}
if (isset($settings['diff_additional_options_user'])) {
$config->set('diff_additional_options.user', $config->get('diff_additional_options_user'));
$config->clear('diff_additional_options_user');
}
foreach (field_info_fields() as $field) {
$setting_name = $field['module'] . '_field_' . $field['type'];
if (isset($settings['diff_' . $setting_name . '_default_options'])) {
$config->set("diff_field_default_options.$setting_name", $config->get('diff_' . $setting_name . '_default_options'));
$config->clear('diff_' . $setting_name . '_default_options');
}
}
$config->save();
// Make sure no diff variables are left in database.
db_delete('variable')
->condition('name','diff'. '%', 'LIKE')
->execute();
}
/**
* Move diff settings from variables to config.
*/
function diff_update_1000()
{
// Migrate variables to config.
$config = config('diff.settings');
$config->set('diff_theme', update_variable_get('diff_theme', 'default'));
$config->set('diff_radio_behavior', update_variable_get('diff_radio_behavior', 'simple'));
$config->set('diff_context_lines_leading', update_variable_get('diff_context_lines_leading', '2'));
$config->set('diff_context_lines_trailing', update_variable_get('diff_context_lines_trailing', '2'));
$config->set('diff_show_diff_inline_node_bundles', update_variable_get('diff_show_diff_inline_node_bundles', array()));
$config->set('diff_admin_path.node', update_variable_get('diff_admin_path_node', 1));
$config->set('diff_admin_path.user', update_variable_get('diff_admin_path_user', 1));
$config->set('diff_default_state.node', update_variable_get('diff_default_state_node', 'raw'));
$config->set('diff_default_state.user', update_variable_get('diff_default_state_user', 'raw'));
$config->set('diff_show_header.node', update_variable_get('diff_show_header_node', 1));
$config->set('diff_show_header.user', update_variable_get('diff_show_header_user', 0));
$config->set('diff_additional_options.node', update_variable_get('diff_additional_options_node', array()));
$config->set('diff_additional_options.user', update_variable_get('diff_additional_options_user', array()));
foreach (field_info_fields() as $field) {
$setting_name = $field['module'] . '_field_' . $field['type'];
$config->set("diff_field_default_options.$setting_name", update_variable_get("diff_{$field['module']}_field_{$field['type']}_default_options", array()));
}
$config->save();
// Delete variables.
update_variable_del('diff_theme');
update_variable_del('diff_radio_behavior');
update_variable_del('diff_context_lines_leading');
update_variable_del('diff_context_lines_trailing');
update_variable_del('diff_show_diff_inline_node_bundles');
update_variable_del('diff_admin_path_node');
update_variable_del('diff_admin_path_user');
update_variable_del('diff_default_state_node');
update_variable_del('diff_default_state_user');
update_variable_del('diff_show_header_node');
update_variable_del('diff_show_header_user');
update_variable_del('diff_additional_options_node');
update_variable_del('diff_additional_options_user');
update_variable_del('diff_additional_options_user');
foreach (field_info_fields() as $field) {
update_variable_del("diff_{$field['module']}_field_{$field['type']}_default_options");
}
}
/**
* Implements hook_update_last_removed().
*/
function diff_update_last_removed() {
return 7306;
}
/**
* Set default values for config settings.
*/
function diff_update_1002() {
$config = config('diff.settings');
$new = array(
'diff_show_diff_inline_node_bundles',
'diff_field_default_options',
);
foreach ($new as $key) {
$existing = $config->get($key);
if (empty($existing)) {
$config->set($key, array());
}
}
$config->save();
}
/**
* Set default state display mode.
*/
function diff_update_1003() {
// The other display mode "raw_plain" was removed.
config_set('diff.settings', 'diff_default_state.node', 'raw');
config_set('diff.settings', 'diff_default_state.user', 'raw');
}