-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathads.install
492 lines (419 loc) · 14.7 KB
/
ads.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
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
<?php
/**
* @file
* Install, update, and uninstall functions for the ADS profile.
*
*/
/**
* Implements hook_module_enabled().
*/
function ads_modules_enabled($modules) {
if (in_array('update', $modules)) {
if (empty($GLOBALS['install_state'])) {
return;
}
$install_state = $GLOBALS['install_state'];
if (drupal_is_cli()) {
echo "Setting Drupal variables:\n";
}
// Installation takes place.
if (isset($install_state['forms']['variables'])) {
foreach ($install_state['forms']['variables'] as $name => $value) {
if (drupal_is_cli()) {
echo ' - "' . $name . '" = "' . $value . "\"\n";
}
variable_set($name, $value);
}
if (array_key_exists('file_public_path', $install_state['forms']['variables'])) {
if (drupal_is_cli()) {
echo 'Preparing Drupal public files directory "' . $install_state['forms']['variables']['file_public_path'] . "\"\n";
}
file_prepare_directory($install_state['forms']['variables']['file_public_path'], FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}
if (array_key_exists('file_private_path', $install_state['forms']['variables'])) {
if (drupal_is_cli()) {
echo 'Preparing Drupal private files directory "' . $install_state['forms']['variables']['file_private_path'] . "\"\n";
}
file_prepare_directory($install_state['forms']['variables']['file_private_path'], FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}
if (array_key_exists('file_temporary_path', $install_state['forms']['variables'])) {
if (drupal_is_cli()) {
echo 'Preparing Drupal temporary files directory "' . $install_state['forms']['variables']['file_temporary_path'] . "\"\n";
}
file_prepare_directory($install_state['forms']['variables']['file_temporary_path'], FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}
}
// Rebuilding list of stream wrappers.
drush_log('Rebuilding list of stream wrappers');
drupal_static_reset('file_get_stream_wrappers');
// We don't want Smart IP to update MaxMind database so early.
variable_set('smart_ip_maxmind_bin_db_auto_update', '0');
variable_set('smart_ip_auto_update', '0');
}
}
/**
* Implements hook_install_tasks().
*/
function ads_install_tasks($install_state) {
// XDebug fix: Increase maximum function nesting level to prevent install errors.
$max_nesting_level = ini_get('xdebug.max_nesting_level');
if ($max_nesting_level > 0 && $max_nesting_level <= '200') {
ini_set('xdebug.max_nesting_level', 200);
}
// Remove any status messages that might have been set. They are unneeded.
// drupal_get_messages('status', TRUE);
$tasks = array(
'ads_install_additional_modules' => array(
'display_name' => st('Install additional modules'),
'type' => 'batch',
),
'ads_generate_example_users' => array(
'display_name' => st('Generate example users'),
'type' => 'normal',
),
'ads_cleanup' => array(
'display_name' => st('Post-install cleanup'),
'type' => 'batch',
),
);
return $tasks;
}
/**
* Task callback: Generates example users.
*/
function ads_generate_example_users() {
if (module_exists('devel')) {
module_load_include('inc', 'devel', 'devel_generate/devel_generate');
devel_create_users(5, FALSE, 0, array(), 'password');
}
}
/**
* Implements hook_install_tasks_alter().
*/
function ads_install_tasks_alter(&$tasks, $install_state) {
// Skip the profile selection, and use the 'exclusive' property to directly
// install the ads distribution. Requires core patch: #1727430.
$tasks['install_select_profile']['display'] = FALSE;
// Exchange the logo that is used in the installer.
/*
$theme_settings = array(
'toggle_logo' => 1,
'default_logo' => 0,
'logo_path' => 'profiles/ads/themes/cloudy/images/ads-logo.png',
'logo_upload' => '',
);
$GLOBALS['conf']['theme_ads_base_settings'] = $theme_settings;
*/
$GLOBALS['install_state'] = $install_state;
}
/**
* Task callback: uses Batch API to install additional modules that should
* be enabled by default but shouldn't be considered profile dependencies.
*
* Also installs demo content if selected.
*/
function ads_install_additional_modules() {
$modules = array(
// Install default core modules.
'contextual',
'dashboard',
'dblog',
'shortcut',
'field_ui',
// Install default contrib modules.
'taxonomy_manager',
'colorbox',
'context_ui',
'pathauto',
'facetapi_pretty_paths',
'context_ui',
'rules_admin',
// Install requirements for the ads cloudy base theme.
'omega_tools',
'block_class',
);
if (variable_get('ads_install_demo_content', FALSE)) {
$modules[] = 'ads_demo';
}
// Resolve the dependencies now, so that module_enable() doesn't need
// to do it later for each individual module (which kills performance).
$files = system_rebuild_module_data();
$modules_sorted = array();
foreach ($modules as $module) {
if (array_key_exists($module, $files) && $files[$module]->requires) {
// Create a list of dependencies that haven't been installed yet.
$dependencies = array_keys($files[$module]->requires);
$dependencies = array_filter($dependencies, '_ads_filter_dependencies');
// Add them to the module list.
$modules = array_merge($modules, $dependencies);
}
}
$modules = array_unique($modules);
foreach ($modules as $module) {
if (array_key_exists($module, $files)) {
$modules_sorted[$module] = $files[$module]->sort;
}
}
arsort($modules_sorted);
$operations = array();
// Enable the selected modules.
foreach ($modules_sorted as $module => $weight) {
$operations[] = array('_ads_enable_module', array($module, $files[$module]->info['name']));
}
$batch = array(
'title' => t('Installing additional modules'),
'operations' => $operations,
'file' => drupal_get_path('profile', 'ads') . '/includes/ads.install_callbacks.inc',
);
return $batch;
}
/**
* array_filter() callback used to filter out already installed dependencies.
*/
function _ads_filter_dependencies($dependency) {
return !module_exists($dependency);
}
/**
* Task callback: performs final post-installation cleanup.
*/
function ads_cleanup() {
/*
$operations = array();
// Revert all features.
$operations[] = array('_ads_revert_all_features', array(t('Revert all features.')));
// Flush caches before we do anything.
$operations[] = array('_ads_flush_caches', array(t('Flushed caches.')));
// Rename FacetAPI block titles.
// For now let's only bother renaming the blocks we show by default.
$facet_blocks = array(
// Resume facet blocks.
'20lwlBykNTHsiVDNAjG1STlcNs5ZOkAd' => 'Career status',
'0E13X9GxANL1YrsKm6GzqUBvUn9dwwKX' => 'Field of study',
'Npc9qPmJF0Z7K11E3oY7p0Z1dHoH0Rpr' => 'Desired region',
'Z1OEEIJTmFLiH0khl0e9VwNxTjr1km0o' => 'Desired occupation',
'MCIaDpM84mEXHKio1Bs8HcYiueQECFo8' => 'IT Skills',
'xETXZbrE5MuFZJhqCQ361R0xPQQIUoDH' => 'General Skills',
'PvSkNRl00z4DVBGE2G0g0wziYXD2YPFO' => 'Language',
// Job facet blocks.
'PE57RfU6JaWBJC3FFCu7iidegBzDJCMx' => 'Field of study',
'v3NKwi4cgrJI5BhGVl3K6y1dktYkhuo8' => 'Occupational field',
'IzmJzjOerbieKFXpXetvXQNCqhkAH8GM' => 'Employment type',
'fknTj1lNko0YBn9qkfWwlhCx0XCi0niU' => 'Required IT skills',
'plRdR3L5yjuALKnX3l09E70IsBWbyyiY' => 'Required general skills',
'GPKIRB6X2D0QOMoO6ldpQS739bPh6Zru' => 'Required languages',
'SZ9qoxuugBBvUZ39HNC99AUUIkZtp592' => 'Location',
);
foreach ($facet_blocks as $delta => $title) {
$operations[] = array('_ads_facet_block_titles', array($delta, $title, t('Setting FacetAPI block titles.')));
}
*/
// Flush caches again for good measure.
$operations[] = array('_ads_flush_caches', array(t('Flushed caches one last time.')));
$batch = array(
'title' => t('Performing post-install cleanup'),
'operations' => $operations,
'finished' => 'ads_cleanup_finished',
'file' => drupal_get_path('profile', 'ads') . '/includes/ads.install_callbacks.inc',
);
return $batch;
}
/**
* Implements hook_install().
*
* Perform actions to set up the site for this profile.
*/
function ads_install() {
// Note: Text formats defined in ads_site_settings.
// Insert default pre-defined node types into the database. For a complete
// list of available node type attributes, refer to the node type API
// documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info.
$types = array(
array(
'type' => 'page',
'name' => st('Basic page'),
'base' => 'node_content',
'description' => st("Use <em>basic pages</em> for your static content, such as an 'About us' page."),
'custom' => 1,
'modified' => 1,
'locked' => 0,
),
array(
'type' => 'article',
'name' => st('Article'),
'base' => 'node_content',
'description' => st('Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.'),
'custom' => 1,
'modified' => 1,
'locked' => 0,
),
);
foreach ($types as $type) {
$type = node_type_set_defaults($type);
node_type_save($type);
node_add_body_field($type);
}
// Default "Basic page" to not be promoted.
variable_set('node_options_page', array('status'));
// Don't display date and author information for "Basic page" nodes by default.
variable_set('node_submitted_page', FALSE);
// By default, enable user picture support.
variable_set('user_pictures', TRUE);
// Allow visitor account creation with administrative approval.
variable_set('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL);
// Create a default vocabulary named "Tags", enabled for the 'article' content type.
$description = st('Use tags to group articles on similar topics into categories.');
$help = st('Enter a comma-separated list of words to describe your content.');
$vocabulary = (object) array(
'name' => 'Tags',
'description' => $description,
'machine_name' => 'tags',
'help' => $help,
);
taxonomy_vocabulary_save($vocabulary);
$field = array(
'field_name' => 'field_' . $vocabulary->machine_name,
'type' => 'taxonomy_term_reference',
// Set cardinality to unlimited for tagging.
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary->machine_name,
'parent' => 0,
),
),
),
);
field_create_field($field);
$instance = array(
'field_name' => 'field_' . $vocabulary->machine_name,
'entity_type' => 'node',
'label' => $vocabulary->name,
'bundle' => 'article',
'description' => $vocabulary->help,
'widget' => array(
'type' => 'taxonomy_autocomplete',
'weight' => -4,
),
'display' => array(
'default' => array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
),
'teaser' => array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
),
),
);
field_create_instance($instance);
// Create an image field named "Image", enabled for the 'article' content type.
// Many of the following values will be defaulted, they're included here as an illustrative examples.
// See http://api.drupal.org/api/function/field_create_field/7
$field = array(
'field_name' => 'field_image',
'type' => 'image',
'cardinality' => 1,
'translatable' => TRUE,
'locked' => FALSE,
'indexes' => array('fid' => array('fid')),
'settings' => array(
'uri_scheme' => 'public',
'default_image' => FALSE,
),
'storage' => array(
'type' => 'field_sql_storage',
'settings' => array(),
),
);
field_create_field($field);
// Many of the following values will be defaulted, they're included here as an illustrative examples.
// See http://api.drupal.org/api/function/field_create_instance/7
$instance = array(
'field_name' => 'field_image',
'entity_type' => 'node',
'label' => 'Image',
'bundle' => 'article',
'description' => st('Upload an image to go with this article.'),
'required' => FALSE,
'settings' => array(
'file_directory' => 'field/image',
'file_extensions' => 'png gif jpg jpeg',
'max_filesize' => '',
'max_resolution' => '',
'min_resolution' => '',
'alt_field' => TRUE,
'title_field' => '',
),
'widget' => array(
'type' => 'image_image',
'settings' => array(
'progress_indicator' => 'throbber',
'preview_image_style' => 'thumbnail',
),
'weight' => -1,
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array('image_style' => 'large', 'image_link' => ''),
'weight' => -1,
),
'teaser' => array(
'label' => 'hidden',
'type' => 'image',
'settings' => array('image_style' => 'medium', 'image_link' => 'content'),
'weight' => -1,
),
),
);
field_create_instance($instance);
// Create a default role for site administrators (if it does not yet exist),
// and assign all available permissions.
if (!$admin_role = user_role_load_by_name('administrator')) {
$admin_role = new stdClass();
$admin_role->name = 'administrator';
$admin_role->weight = 2;
user_role_save($admin_role);
}
user_role_grant_permissions($admin_role->rid, array_keys(module_invoke_all('permission')));
// Set this as the administrator role.
variable_set('user_admin_role', $admin_role->rid);
// Assign user 1 the "administrator" role.
db_insert('users_roles')
->fields(array('uid' => 1, 'rid' => $admin_role->rid))
->execute();
// Create a Home link in the main menu.
$item = array(
'link_title' => 'Home',
'link_path' => '<front>',
'menu_name' => 'main-menu',
);
menu_link_save($item);
// Update the menu router information.
menu_rebuild();
// Enable default themes.
db_update('system')
->fields(array('status' => 1))
->condition('type', 'theme')
->condition(db_or()
->condition('name', 'ads_base')
)
->execute();
variable_set('theme_default', 'ads_base');
// Enable default admin theme.
db_update('system')
->fields(array('status' => 1))
->condition('type', 'theme')
->condition(db_or()
->condition('name', 'tao')
->condition('name', 'rubik')
)
->execute();
variable_set('admin_theme', 'rubik');
variable_set('node_admin_theme', '1');
$theme_settings = variable_get('theme_ads_settings', array());
variable_set('theme_ads_settings', $theme_settings);
$theme_settings['toggle_slogan'] = TRUE;
}