-
Notifications
You must be signed in to change notification settings - Fork 1
/
mmoda.install
220 lines (188 loc) · 7.28 KB
/
mmoda.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
<?php
/**
* @file
* Install, update and uninstall functions for the mmoda module.
*/
define('D3_MIN_LIB_VERSION', '3.0');
include_once 'mmoda.lib.inc';
include_once 'help_book_content_type/mmoda_help_page.features.inc';
include_once 'help_book_content_type/mmoda_help_page.features.field_base.inc';
include_once 'help_book_content_type/mmoda_help_page.features.field_instance.inc';
include_once drupal_get_path('module', 'node_export') . '/formats/drupal.inc';
/**
* Implements hook_requirements().
*/
function mmoda_requirements($phase)
{
$module_name = basename(__FILE__, '.install');
$requirements = array();
$conflicts = array();
if ('install' == $phase and empty(variable_get($module_name . '_settings', array()))) {
$filename = 'mmoda_field_bases.php';
_mmoda_write_log_file($filename, print_r(mmoda_help_page_field_default_field_bases(), true));
foreach (mmoda_help_page_field_default_field_bases() as $field_new) {
$field_old = field_info_field($field_new['field_name']);
if (! is_null($field_old) and $field_new['field_name'] == $field_old['field_name']) {
$conflicts[] = $field_new['field_name'];
}
}
if (! empty($conflicts)) {
$clist = implode(', ', $conflicts);
$requirements[$module_name] = array(
'title' => t('title'),
'description' => t($module_name . ' : Field %clist already exists.', array(
'%clist' => $clist
)),
'severity' => REQUIREMENT_ERROR
);
}
}
if ($phase == 'runtime') {
$t = get_t();
$library = libraries_detect('d3');
$error_type = isset($library['error']) ? drupal_ucfirst($library['error']) : '';
$error_message = isset($library['error message']) ? $library['error message'] : '';
if (empty($library['installed'])) {
$requirements['D3_library'] = array(
'title' => $t('D3 library'),
'value' => $t('@e: At least @a', array(
'@e' => $error_type,
'@a' => D3_MIN_LIB_VERSION
)),
'severity' => REQUIREMENT_ERROR,
'description' => $t('!error you need to download the !D3, extract the archive and place the D3 directory in the %path directory on your server.', array(
'!error' => $error_message,
'!D3' => l($t('D3 library'), $library['download url'] ?? ''),
'%path' => 'sites/all/libraries'
))
);
} elseif (version_compare($library['version'], D3_MIN_LIB_VERSION, '>=')) {
$requirements['D3_library'] = array(
'title' => $t('D3 library'),
'severity' => REQUIREMENT_OK,
'value' => $library['version']
);
} else {
$requirements['D3_library'] = array(
'title' => $t('D3 library'),
'value' => $t('At least @a', array(
'@a' => D3_MIN_LIB_VERSION
)),
'severity' => REQUIREMENT_ERROR,
'description' => $t('You need to download a later version of the !D3 and replace the old version located in the %path directory on your server.', array(
'!D3' => l($t('D3 library'), $library['download url']),
'%path' => $library['library path']
))
);
}
}
return $requirements;
}
function mmoda_add_custom_fields()
{
foreach (mmoda_help_page_field_default_field_bases() as $field) {
field_create_field($field);
}
foreach (mmoda_help_page_field_default_field_instances() as $instance) {
if(!is_null($instance))
field_create_instance($instance);
}
}
function mmoda_del_custom_fields()
{
foreach (mmoda_help_page_field_default_field_instances() as $instance) {
if (!is_null($instance)) {
field_delete_instance($instance);
}
}
// foreach (array_keys(mmoda_help_page_field_default_field_bases()) as $field) {
// field_delete_field($field);
// }
}
/**
* Implements hook_install().
*/
function mmoda_install()
{
$module_name = basename(__FILE__, '.install');
list ($module_name) = explode('_', $module_name);
// return;
// $module_settings ['support_email'] = array('mohamed.meharga@unige.ch');
$module_settings['support_email'] = array(
'no-reply@unige.ch',
'cdci-oda-feedback@listes.unige.ch'
);
$module_settings['common']['gallery_data_request'] = 'https://www.astro.unige.ch/mmoda/dispatch-data/get_astro_entity_info_by_source_name';
// $module_settings['common']['gallery_data_request'] = 'https://cdcidev.mtmco.net/mmoda/dispatch-data/get_astro_entity_info_by_source_name';
$module_settings['common']['gallery_base_url'] = 'http://www.astro.unige.ch';
// $module_settings['common']['gallery_base_url'] = 'https://cdcidev.mtmco.net';
$module_settings['common']['dispatcher_path'] = '/dispatcher-data';
$module_settings['common']['src_name'] = '1E 1740.7-2942';
$module_settings['common']['RA'] = '265.97845833';
$module_settings['common']['DEC'] = '-29.74516667';
$module_settings['common']['T1'] = '2017-03-06T13:26:48.0';
$module_settings['common']['T2'] = '2017-03-06T15:32:27.0';
$module_settings['common']['T_format'] = 'isot';
$module_settings[$module_name . '_debug'] = true;
$module_settings['frontend_version'] = mmoda_get_frontend_version();
$module_settings['modules'] = array();
// Create role for user managers
$user_managers_role_name = 'user manager';
if (empty(user_role_load_by_name($user_managers_role_name))) {
$role = new stdClass();
$role->name = $user_managers_role_name;
user_role_save($role);
}
$role = user_role_load_by_name($user_managers_role_name);
$module_settings['user_managers_role_id'] = $role->rid;
// Override JWT link expiration time in minutes to 4 days (5760mns)
variable_set('jwt_link_expiration', 5760);
// Add node types
node_types_rebuild();
$help_page_content_type = array_key_first(mmoda_node_info());
// Default to not to be promoted
variable_set('node_options_' . $help_page_content_type, array(
'status'
));
// Disable comments
variable_set('comment_' . $help_page_content_type, COMMENT_NODE_CLOSED);
// Hide date and author information
variable_set('node_submitted_' . $help_page_content_type, FALSE);
// Disable node preview
// variable_set('node_preview_'.$help_page_content_type, 0);
// Disable menu entry
// variable_set('menu_options_'.$help_page_content_type, array(0));
// Add custom fields to book page content type
mmoda_add_custom_fields();
$book_allowed_types = variable_get('book_allowed_types', array(
'book'
));
$book_allowed_types[] = $module_name . '_help_page';
variable_set('book_allowed_types', $book_allowed_types);
variable_set('pathauto_node_' . $help_page_content_type . '_pattern', 'help/[node:book:root]/[node:title]');
_mmoda_common_install($module_name, '', $module_settings);
}
/**
* Implements hook_uninstall().
*/
function mmoda_uninstall()
{
$module_name = basename(__FILE__, '.install');
_mmoda_common_uninstall($module_name);
// Delete all help page fields.
mmoda_del_custom_fields();
$bundles = array();
foreach (mmoda_node_info() as $key => $value) {
$bundles[] = $key;
}
// print "Content types to be deleted:\n" . print_r($bundles, true);
// Delete bundles.
foreach ($bundles as $bundle) {
node_type_delete($bundle);
}
node_types_rebuild();
menu_rebuild();
field_purge_batch(500);
$help_page_content_type = array_key_first(mmoda_node_info());
variable_del('pathauto_node_' . $help_page_content_type . '_pattern');
}