forked from OS2web/os2web-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
os2web.profile
404 lines (373 loc) · 12.6 KB
/
os2web.profile
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<?php
/**
* @file
* This file includes all hooks to proper set up profile during install
*/
/**
* Name of profile; visible in profile selection form.
*/
define('PROFILE_NAME', 'OS2Web');
/**
* Description of profile; visible in profile selection form.
*/
define('PROFILE_DESCRIPTION', 'Generisk Installation af OS2Web.');
/**
* Implements hook_install_tasks().
*/
function os2web_install_tasks() {
$task = array(
'os2web_import_database' => array(
'type' => 'normal',
'display_name' => st('Import default database'),
),
'os2web_profile_prepare' => array(
'type' => 'normal',
'display_name' => st('Prepare OS2web..'),
),
'os2web_settings_form' => array(
'display_name' => st('Setup OS2Web'),
'type' => 'form',
),
'os2web_import_default_feeds_form' => array(
'display_name' => st('Setup Imports'),
'type' => 'form',
),
'os2web_import_default_feeds' => array(
'display_name' => st('Import default content'),
'type' => 'batch',
),
);
return $task;
}
/**
* Implements hook_profile_prepare().
*/
function os2web_profile_prepare() {
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// Menu rebuild neccesary to load xpath_parser
menu_rebuild();
drupal_get_form('os2web_settings_form');
drupal_set_message('Database import complete, please reload this form to continue.','ok');
}
/**
* Implements hook_form().
*/
function os2web_settings_form($install_state) {
drupal_set_title(st('Webservice endpoint setup'));
$form['os2web_pws_config_group'] = array(
'#type' => 'fieldset',
'#title' => t('PWS Endpoint configuration'),
);
$form['os2web_pws_config_group']['os2web_pws_url'] = array(
'#type' => 'textfield',
'#title' => t('PWS URL for V4'),
'#default_value' => variable_get('os2web_pws_url'),
'#description' => t('URL to the PWS webservice endpoint.'),
);
$form['os2web_pws_config_group']['os2web_pws_url_v6'] = array(
'#type' => 'textfield',
'#title' => t('PWS URL for V6'),
'#default_value' => variable_get('os2web_pws_url_v6'),
'#description' => t('URL to the PWSv6 webservice endpoint.'),
);
$form['os2web_pws_config_group']['os2web_pws_url_search'] = array(
'#type' => 'textfield',
'#title' => t('PWS URL for Search service'),
'#default_value' => variable_get('os2web_pws_url_search'),
'#description' => t('URL to the webservice endpoint that runs the search service.'),
);
$form['os2web_pws_config_group']['os2web_pws_user'] = array(
'#type' => 'textfield',
'#title' => t('PWS login user'),
'#default_value' => variable_get('os2web_pws_user'),
'#description' => t('PWS HTTP authentification user.'),
);
$form['os2web_pws_config_group']['os2web_pws_password'] = array(
'#type' => 'textfield',
'#title' => t('PWS password'),
'#default_value' => variable_get('os2web_pws_password'),
'#description' => t('PWS HTTP authentification password.'),
);
$form['os2web_pws_adlib_group'] = array(
'#type' => 'fieldset',
'#title' => t('Adlib Endpoint configuration'),
);
$form['os2web_pws_adlib_group']['os2web_adlib_url'] = array(
'#type' => 'textfield',
'#title' => t('URL for Adlib service endpoint'),
'#default_value' => variable_get('os2web_adlib_url'),
'#description' => t('URL to the webservice endpoint that runs the Adlib service.'),
);
// Proxy setups.
$form['os2web_pws_proxy_group'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => !variable_get('os2web_pws_proxy'),
'#title' => t('Proxy configuration'),
'#weight' => 10,
);
$form['os2web_pws_proxy_group']['os2web_pws_proxy'] = array(
'#type' => 'checkbox',
'#default_value' => variable_get('os2web_pws_proxy'),
'#title' => t('Use proxy?'),
);
$form['os2web_pws_proxy_group']['os2web_pws_proxy_host'] = array(
'#type' => 'textfield',
'#default_value' => variable_get('os2web_pws_proxy_host'),
'#title' => t('Proxy hostname or IP'),
);
$form['os2web_pws_proxy_group']['os2web_pws_proxy_port'] = array(
'#type' => 'textfield',
'#default_value' => variable_get('os2web_pws_proxy_port'),
'#title' => t('Proxy port number.'),
);
return system_settings_form($form);
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Allows the profile to alter the site configuration form.
*/
function os2web_form_install_configure_form_alter(&$form, $form_state) {
// Pre-populate the site name with the server name.
$form['site_information']['site_name']['#default_value'] = 'OS2Web Test';
$form['update_notifications']['update_status_module']['#default_value'] = array(0, 0);
$form['server_settings']['site_default_country']['#default_value'] = 'DK';
$form['server_settings']['#access'] = FALSE;
$form['update_notifications']['#access'] = FALSE;
$form['admin_account']['account']['name']['#default_value'] = 'admin';
}
/**
* Implements hook_form().
*/
function os2web_import_default_feeds_form($install_state) {
if ($drush = function_exists('drush_log')) {
drush_log('Imports disabled during drush install. Rembmer to visit /import.', 'ok');
}
// drupal_load('module', 'feeds');
module_load_all();
$config = feeds_source('ofir_job_import')->getConfig();
$ofir_url = $config['FeedsHTTPFetcher']['source'];
$form = array(
// 'os2web_import_group' => array(
// '#type' => 'fieldset',
// '#title' => st('Taxonomy imports'),
// '#description' => st('Choose if you wish to import all vocabularies during install.'),
// 'os2web_import_kle_import' => array(
// '#type' => 'checkbox',
// '#title' => st('KLE'),
// '#default_value' => TRUE && !$drush,
// ),
// 'os2web_import_org_import' => array(
// '#type' => 'checkbox',
// '#title' => st('Organizations'),
// '#default_value' => TRUE && !$drush,
// ),
// 'os2web_import_pol_import' => array(
// '#type' => 'checkbox',
// '#title' => st('Politics'),
// '#default_value' => TRUE && !$drush,
// ),
// 'os2web_import_gis_import' => array(
// '#type' => 'checkbox',
// '#title' => st('GIS Names'),
// '#default_value' => TRUE && !$drush,
// ),
// ),
'os2web_import_group2' => array(
'#type' => 'fieldset',
'#title' => st('Ofir.dk job Import'),
'#description' => st('Setup for the Ofir.dk import.'),
'os2web_import_ofir_url' => array(
'#type' => 'textfield',
'#title' => st('Default URL for Ofir.dk job feed.'),
'#default_value' => $ofir_url,
),
'os2web_import_ofir_import' => array(
'#type' => 'checkbox',
'#title' => st('Import during install ?'),
'#default_value' => FALSE,
),
),
);
return system_settings_form($form);
}
/**
* Sets up default feeds for os2web.
*/
function os2web_import_default_feeds($install_state) {
// Set default KLE taxonomy feed url.
$source = feeds_source('taxonomy_kle');
$config = $source->getConfig();
$config['FeedsFileFetcher']['source'] = drupal_get_path('module', 'taxonomies_and_taxonomy_importers') . '/data/kle.xml';
$source->setConfig($config);
$source->save();
// Set default Organisation taxonomy feed url.
$source = feeds_source('taxonomy_organization');
$config = $source->getConfig();
$config['FeedsFileFetcher']['source'] = drupal_get_path('module', 'taxonomies_and_taxonomy_importers') . '/data/org.xml';
$source->setConfig($config);
$source->save();
// Set default Politik taxonomy feed url.
$source = feeds_source('taxonomy_politics');
$config = $source->getConfig();
$config['FeedsFileFetcher']['source'] = drupal_get_path('module', 'taxonomies_and_taxonomy_importers') . '/data/pol.xml';
$source->setConfig($config);
$source->save();
// Set default Egenavne/stednavne taxonomy feed url.
$source = feeds_source('taxonomy_gisnames');
$config = $source->getConfig();
$config['FeedsFileFetcher']['source'] = drupal_get_path('module', 'taxonomies_and_taxonomy_importers') . '/data/gis.xml';
$source->setConfig($config);
$source->save();
// Set default Ofir feed url.
$source = feeds_source('ofir_job_import');
$config = $source->getConfig();
$config['FeedsHTTPFetcher']['source'] = variable_get('os2web_import_ofir_url', '');
$source->setConfig($config);
$source->save();
$batch = array(
'title' => t('Importing feeds'),
'operations' => array(),
'progress_message' => t('Current: @current | Remaining:
@remaining | Total: @total | Percentage: @percentage'),
);
if (variable_get('os2web_import_kle_import', FALSE)) {
$batch['operations'][] = array('feeds_batch',
array('import', 'taxonomy_kle', 0));
}
if (variable_get('os2web_import_org_import', FALSE)) {
$batch['operations'][] = array('feeds_batch',
array('import', 'taxonomy_organization', 0));
}
if (variable_get('os2web_import_pol_import', FALSE)) {
$batch['operations'][] = array('feeds_batch',
array('import', 'taxonomy_politics', 0));
}
if (variable_get('os2web_import_gis_import', FALSE)) {
$batch['operations'][] = array('feeds_batch',
array('import', 'taxonomy_gisnames', 0));
}
if (variable_get('os2web_import_ofir_import', FALSE)) {
$batch['operations'][] = array('feeds_batch',
array('import', 'ofir_job_import', 0));
}
// $batch = array();
// Clean up temporary vars.
variable_del('os2web_import_ofir_url');
variable_del('os2web_import_kle_import');
variable_del('os2web_import_org_import');
variable_del('os2web_import_pol_import');
variable_del('os2web_import_gis_import');
variable_del('os2web_import_ofir_import');
return $batch;
}
/**
* Sets the default language to danish.
*/
function os2web_profile_details() {
return array(
'name' => PROFILE_NAME,
'description' => PROFILE_DESCRIPTION,
// 'language' => "da",
'language' => "en",
);
}
/* * ************** DB DUMP INSTALLER *************************** */
/**
* Custom form submit handler for configuration form.
*
* Drops all data from existing database, imports database dump, and restores
* values entered into configuration form.
*/
function os2web_import_database() {
// Store the set-up vars:
$vars = array(
'site_name',
'site_mail',
'date_default_timezone',
'clean_url',
'update_status_module',
'install_task',
'drupal_private_key',
);
$data = array();
foreach ($vars as $name) {
$data[$name] = variable_get($name);
}
// Import database dump file.
$os2web_file = dirname(__FILE__) . '/db.sql.gz';
$success = import_dump($os2web_file);
if (!$success) {
return;
}
// Now re-set the values they filled in during the previous step.
foreach ($data as $key => $value) {
variable_set($key, $value);
}
// Perform additional clean-up tasks.
variable_del('file_temporary_path');
variable_del('file_public_path');
// drupal_goto('<front>');
}
// The rest is copy/paste/modify code from demo module. //
/**
* Imports a database dump file.
*
* @see demo_reset()
*/
function import_dump($filename) {
// Open dump file.
// if (!file_exists($filename) || !($fp = fopen($filename, 'r'))) {
if (!file_exists($filename) || !($fp = gzopen($filename, 'r'))) {
drupal_set_message(t('Unable to open dump file %filename.', array('%filename' => $filename)), 'error');
return FALSE;
}
// Drop all existing tables.
foreach (list_tables() as $table) {
if ($table != 'sessions') {
db_query("DROP TABLE " . $table);
}
}
// Load data from dump file.
$success = TRUE;
$query = '';
while (!feof($fp)) {
$line = fgets($fp, 16384);
if ($line && $line != "\n" && strncmp($line, '--', 2) && strncmp($line, '#', 1)) {
$query .= $line;
if (substr($line, -2) == ";\n") {
$options = array(
'target' => 'default',
'return' => Database::RETURN_NULL,
// 'throw_exception' => FALSE,
);
$stmt = Database::getConnection($options['target'])->prepare($query);
if (!$stmt->execute(array(), $options)) {
if ($verbose) {
// Don't use t() here, as the locale_* tables might not (yet) exist.
drupal_set_message(strtr('Query failed: %query', array('%query' => $query)), 'error');
}
$success = FALSE;
}
$query = '';
}
}
}
fclose($fp);
if (!$success) {
drupal_set_message(t('Failed importing database from %filename.', array('%filename' => $filename)), 'error');
}
return $success;
}
/**
* Returns a list of tables in the active database.
*
* Only returns tables whose prefix matches the configured one (or ones, if
* there are multiple).
*
* @see demo_enum_tables()
*/
function list_tables() {
return db_query("SHOW TABLES")->fetchCol();
}