-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathding_library.install
More file actions
166 lines (147 loc) · 4.34 KB
/
ding_library.install
File metadata and controls
166 lines (147 loc) · 4.34 KB
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
<?php
// Install and update hooks for ding_library.
function ding_library_install() {
// Disable default OG member rules
db_update('rules_config')
->fields(array('active' => 0))
->condition(db_or()
->condition('name', 'rules_og_member_active')
->condition('name', 'rules_og_member_pending')
->condition('name', 'rules_og_group_content_notification'))
->execute();
}
/**
* Update blocks.
*/
function ding_library_update_7001() {
$default_theme = variable_get('theme_default', 'bartik');
// Delete menu_block menu, not needed anymore.
db_delete('block')
->condition('module', 'menu_block')
->condition('delta', 'ding_content-main-lvl1')
->condition('theme', $default_theme)
->execute();
// Delete any left over library_menus.
db_delete('block')
->condition('module', 'ding_library')
->condition('delta', 'library_menu')
->condition('theme', $default_theme)
->execute();
// Add the new ding_menu.
db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache', 'title'))->values(array(
'module' => 'ding_library',
'delta' => 'ding_menu',
'theme' => $default_theme,
'status' => 1,
'weight' => 1,
'region' => 'header',
'pages' => '',
'cache' => -1,
'title' => '<none>',
)
)->execute();
return t('Updated menu block.');
}
/**
* Disable default OG member rules.
*/
function ding_library_update_7002() {
db_update('rules_config')
->fields(array('active' => 0))
->condition(db_or()
->condition('name', 'rules_og_member_active')
->condition('name', 'rules_og_member_pending')
->condition('name', 'rules_og_group_content_notification'))
->execute();
}
/**
* Enable i18n_menu so we can have translated menus.
*/
function ding_library_update_7003() {
// Enable i18n_menu and its dependencies.
module_enable(array('i18n_menu'), TRUE);
}
/**
* Ding2 has been removed from profiles
*/
function ding_library_update_7004() {
$openlayers_source = variable_get('openlayers_source', FALSE);
if ($openlayers_source == 'profiles/ding2/libraries/openlayers/OpenLayers.js') {
variable_set('openlayers_source', 'profiles/artesis/libraries/openlayers/OpenLayers.js');
}
}
/**
* Switch OpenLayer handler to OSM from Google.
*/
function ding_library_update_7005() {
// Step 1: Truncate `cache_geocoder` table.
db_truncate('cache_geocoder')->execute();
// Step 2: Update `field_geocode` settings.
$instance = field_info_instance('node', 'field_geocode', 'ding_library');
$instance['widget']['settings']['geocoder_handler'] = 'openstreetmap_nominatim';
$instance['widget']['settings']['handler_settings'] = [];
try {
field_update_instance($instance);
}
catch (Exception $exception) {
watchdog_exception('ding_library', $exception, 'We had problems on field instance updating.');
}
// Step 3: Re-save library nodes.
$nodes = db_select('node', 'n')
->fields('n', ['nid'])
->condition('status', 1)
->condition('type', 'ding_library')
->execute()
->fetchCol();
foreach ($nodes as $node) {
try {
node_save(node_load($node));
}
catch (Exception $e) {
watchdog_exception('ding_library', $e, 'We had problems on node saving.');
}
}
}
/**
* Refresh libraries coordinates.
*/
function ding_library_update_7006() {
// Step 1: Truncate `cache_geocoder` table.
db_truncate('cache_geocoder')->execute();
// Step 2: Disable geocoder empty results cache functionality.
variable_set('geocoder_cache_empty_results', 0);
// Step 3: Re-save library nodes.
$nodes = db_select('node', 'n')
->fields('n', ['nid'])
->condition('status', 1)
->condition('type', 'ding_library')
->execute()
->fetchCol();
foreach ($nodes as $node) {
try {
node_save(node_load($node));
}
catch (Exception $e) {
watchdog_exception('ding_library', $e, 'We had problems on node saving.');
}
}
}
/**
* Re-save library nodes.
*/
function ding_library_update_7007(&$sandbox) {
$nodes = db_select('node', 'n')
->fields('n', ['nid'])
->condition('status', 1)
->condition('type', 'ding_library')
->execute()
->fetchCol();
foreach ($nodes as $node) {
try {
node_save(node_load($node));
}
catch (Exception $e) {
watchdog_exception('ding_library', $e, 'We had problems on node saving.');
}
}
}