-
Notifications
You must be signed in to change notification settings - Fork 2
/
cu_core.install
562 lines (476 loc) · 19.8 KB
/
cu_core.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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
<?php
/**
* @file
* Install hooks for cu_core module.
*/
/**
* Implements hook_install().
*/
function cu_core_install() {
// Set the weight high to run last hooks after other modules.
db_update('system')
->fields(array('weight' => 999))
->condition('name', 'cu_core', '=')
->execute();
$hosting = express_check_known_hosts();
if ($hosting === 'travis') {
module_enable(array('travis_hosting', 'cu_users'));
}
elseif ($hosting == 'ucb_on_prem_hosting') {
module_enable(array('ucb_on_prem_hosting'));
}
elseif ($hosting === 'pantheon') {
module_enable(array('pantheon_hosting'));
}
elseif ($hosting === 'lando' || $hosting === 'valet') {
module_enable(array('local_hosting'));
}
else {
module_enable(array('ng_hosting'));
}
theme_enable(array(
'cuhighlight',
'cuivory',
'culayers',
'cuminimal',
'cumodern',
'curise',
'cushadow',
'cusimple',
'cuspirit',
'cuswatch',
'cutradition',
));
// Add blocks shortcut to shortcuts set.
$shortcut_set = shortcut_set_load(SHORTCUT_DEFAULT_SET_NAME);
$shortcut_set->links[] =
array(
'link_path' => 'admin/content/blocks',
'link_title' => st('Blocks'),
'weight' => -18,
);
shortcut_set_save($shortcut_set);
// Set default variables for user_external_invite.
_set_external_invite_variables();
// Change for #FIT-583 for https://www.drupal.org/node/2172293.
// Must be set before cu_forms_bundle is enabled.
variable_set('webform_install_add_body_field', TRUE);
variable_set('site_name', 'University of Colorado Boulder');
variable_set('site_name_1', 'University of Colorado Boulder');
variable_set('site_slogan', 'University of Colorado Boulder');
variable_set('express_help_base_url', 'http://www.colorado.edu/webcentral');
// Set message for when enabling of bundles is turned off.
variable_set('profile_module_manager_disable_enabling_atlas_bundles', 0);
variable_set('profile_module_manager_disable_enabling_text', 'Bundles are not available at this time. Contact websupport@colorado.edu for questions regarding this.');
variable_set('rave_alerts_rss_url', 'http://www.getrave.com/rss/cuboulder/channel1');
variable_set('rave_alerts_check_enable', 1);
variable_set('rave_alerts_network_fail_message', 'Network Failure: Please go directly to http://alerts.colorado.edu for more information.');
variable_set('rave_alerts_deafult_read_more_url', 'http://alerts.colorado.edu');
// Set the syslog_identity variable to the SID.
$cu_sid = variable_get('cu_sid', '');
if ($cu_sid) {
// Current value
$syslog_identity = 'drupal-' . $cu_sid;
}
else {
$syslog_identity = 'drupal-no_sid';
}
variable_set('syslog_identity', $syslog_identity);
// Key for 'LOG_LOCAL0' in the form.
variable_set('syslog_facility', '128');
variable_set('syslog_format', '!base_url|!timestamp|!type|!ip|!request_uri|!referer|!uid|!link|!message');
// Set variable for disabling certain messages from users.
variable_set('disable_messages_ignore_regex', array(
'/^Metatag support has been enabled for the .*?$/i',
'/^You can now .+configure the CAPTCHA module.+ for your site.$/i',
'/^Note that the CAPTCHA module disables .+page caching.+ of pages that include a CAPTCHA challenge.$/i',
'/^The block System help was assigned to the invalid region help and has been disabled.$/i',
));
variable_set('disable_messages_ignore_patterns', 'Metatag support has been enabled for the .+
You can now .+configure the CAPTCHA module.+ for your site.
Note that the CAPTCHA module disables .+page caching.+ of pages that include a CAPTCHA challenge.
The block System help was assigned to the invalid region help and has been disabled.');
variable_set('express_layout_node_type_ignore', array('file'));
db_update('responsive_preview')
->fields(array('status' => 0,))
->execute();
db_update('responsive_preview')
->fields(array('status' => 1,))
->condition(db_or()
->condition('name', 'medium')
->condition('name', 'small')
)
->execute();
// Disable user 1 & set random name.
$random_name = 'admin-' . user_password(10);
// Generate hashed password.
$unhashed_pass = user_password(50);
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$hashed_pass = user_hash_password(trim($unhashed_pass));
variable_set('user_mail_status_activated_notify ', 0);
// Set admin user email to something not admin@example.com.
$admin_user = user_load(1);
$admin_user->mail = 'websupport@colorado.edu';
$admin_user->name = $random_name;
$admin_user->pass = $hashed_pass;
$admin_user->status = 0;
user_save($admin_user);
watchdog('express', 'attempted to disable uid 1');
variable_set('express_permissions_owner_cap', 4);
// Google Tag Manager.
variable_set('google_tag_container_id', 'GTM-M3DX2QP');
}
/**
* Set default variables for user_external_invite.
*/
function _set_external_invite_variables() {
// Set core invite roles.
$core_roles = express_permissions_role_settings(array('core'));
$core_role_ids = array();
foreach ($core_roles['rid'] as $rid => $role) {
$core_role_ids[] = $rid;
}
variable_set('user_external_invite_core_roles', $core_role_ids);
// Set Content Editor as the default role to invite.
variable_set('user_external_invite_default_role', $core_roles['names']['site_editor']['rid']);
// Set addon invite roles.
$addon_roles = express_permissions_role_settings(array('core_addon'));
$addon_roles_array = array();
foreach ($addon_roles['rid'] as $rid => $role) {
$addon_roles_array[] = $rid;
}
variable_set('user_external_invite_addon_roles', $addon_roles_array);
variable_set('user_external_invite_days_valid_for', 5);
variable_set('user_external_invite_invite_template', '[user_external_invite:invite_custom]
You have been invited to join the [site:name] Web Express website as a user with "[user_external_invite:invite_core_role][user_external_invite:invite_addon_roles]" access privileges.
To accept this invitation:
1) Go to [user_external_invite:invite_link]
2) Login with your IdentiKey name and password.
Upon completion, you will receive an email confirming your access.
--
The Web Express Team
http://www.colorado.edu/webcentral
websupport@colorado.edu');
variable_set('user_external_invite_confirmation_template', 'We have received your request to grant "[user_external_invite:invite_core_role][user_external_invite:invite_addon_roles]" access to the following users:
[user_external_invite:invited_emails]
An email invitation has been sent requesting the user to login to [site:url] and accept the invitation. Upon completion, a confirmation email will be sent.
If you did not submit this request or need to modify it, please contact us at websupport@colorado.edu.
--
The Web Express Team
http://www.colorado.edu/webcentral
websupport@colorado.edu');
variable_set('user_external_invite_accepted_template', 'We are confirming [user_external_invite:invited_email] now has "[user_external_invite:invite_core_role][user_external_invite:invite_addon_roles]" access to the [site:name], [site:url], website.
Web Central:
You can use the Web Central website as your main resource for step-by-step tutorials, information on training sessions, and requesting help. http://www.colorado.edu/webcentral
--
The Web Express Team
http://www.colorado.edu/webcentral
websupport@colorado.edu');
variable_set('user_external_invite_accepted_confirmation_template', 'You have successfully joined the [site:name] Web Express website as a user with "[user_external_invite:invite_core_role][user_external_invite:invite_addon_roles]" access privileges.
To access and edit this site:
1) Go to [user_external_invite:invite_login_link]
2) Login with your IdentiKey name and password.
Web Central:
You can use the Web Central website as your main resource for step-by-step tutorials, information on training sessions, and requesting help. http://www.colorado.edu/webcentral
--
The Web Express Team
http://www.colorado.edu/webcentral
websupport@colorado.edu');
}
/**
* Variable sets for Express transition.
*/
function cu_core_update_7001() {
variable_set('express_help_base_url', 'https://www.colorado.edu/webcentral');
variable_set('profile_module_manager_ignore', 'secure_permissions, express_permissions, cu_users, cu_core, cu_help, cu_inventory, cu_inventory_stats, express_final');
// Set SEO bundle to be hidden in bundle list form.
variable_set('profile_module_manager_bundle_ignore', array('cu_seo_bundle' => 'cu_seo_bundle'));
// Set message for when enabling of bundles is turned off.
variable_set('profile_module_manager_disable_enabling_text', 'Due to unexpectedly high load on the servers, the option to enable bundles has temporarily been disabled. Please check back tomorrow.');
// Set variable for disabling certain messages from users.
variable_set('disable_messages_ignore_regex', array(
'/^Metatag support has been enabled for the .*?$/i',
'/^You can now .+configure the CAPTCHA module.+ for your site.$/i',
'/^Note that the CAPTCHA module disables .+page caching.+ of pages that include a CAPTCHA challenge.$/i',
));
variable_set('disable_messages_ignore_patterns', 'Metatag support has been enabled for the .+
You can now .+configure the CAPTCHA module.+ for your site.
Note that the CAPTCHA module disables .+page caching.+ of pages that include a CAPTCHA challenge.');
}
/**
* Revert features by passing features in an array.
*/
function cu_core_revert_features($features = NULL) {
// If an array of specific features isn't passed, populate with all overridden features.
if ($features == NULL) {
module_load_include('inc', 'features', 'features.export');
$features = features_get_features();
foreach ($features as $feature) {
if (features_get_storage($feature->name) == 0) {
unset($features[$feature->name]);
}
}
}
// Check against features that currently can't be reverted.
$express_protected_features = array_merge(array(
'cu_home_page',
'cu_sitewide',
), explode(',', variable_get('express_protected_features', '')));
foreach ($features as $key => $feature) {
if (!in_array($key, $express_protected_features)) {
$f = features_get_features($key);
$components = array_keys($f->info['features']);
features_revert(array($f->name => $components));
watchdog('cu_core', 'Attempting to revert %feature', array('%feature' => $feature->name), WATCHDOG_NOTICE);
}
}
}
/**
* Run every time a db update.
*
* This calls the inventory update function and admin password change.
*/
function cu_core_express_update($version) {
cu_core_atlas_update($version);
// Change admin user/pass.
cu_core_scramble_admin();
}
/**
* Updates inventory with profile version.
*/
function cu_core_inventory_update($version) {
// Nulling this function out so that older update hooks will still work.
return;
}
/**
* Updates Atlas with profile version.
*/
function cu_core_atlas_update($version) {
if (module_exists('atlas')) {
atlas_process_core_schema_version($version);
}
}
/**
* Obscures uid 1 password and username for added security.
*/
function cu_core_scramble_admin() {
// Generate hashed password.
$unhashed_pass = user_password(50);
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$hashed_pass = user_hash_password(trim($unhashed_pass));
// Abort if the hashing failed and returned FALSE.
if (!$hashed_pass) {
return FALSE;
}
else {
// Save admin user with new user/password.
$user = user_load(1);
$user->name = 'admin-' . user_password(10);
$user->pass = $hashed_pass;
user_save($user);
}
}
/**
* Implements hook_requirements().
* cu_core is designed to be extended by 1 hosting module
*/
function cu_core_requirements($phase) {
$requirements = array();
if ($phase === 'runtime') {
$t = get_t();
$overriddenFeatures = array();
// The features.export.inc is where features_get_storage() is defined.
module_load_include('inc', 'features', 'features.export');
// This loops over each feature, checking if its state is overridden and if it is expected to be overridden.
// If the feature's .info file contains `settings[can_be_overridden] = 1`, it can be overridden and will not show up as an error on the /admin/reports/status page.
foreach (features_get_features(NULL, TRUE) as $feature) {
if (features_get_storage($feature->name) == FEATURES_OVERRIDDEN && $feature->info['settings']['can_be_overridden'] !== "1") {
$overriddenFeatures[] = $feature->info['name'];
}
}
if (count($overriddenFeatures) > 0) {
$requirements['overridden_features'] = [
'title' => $t('Overridden Features'),
'value' => t(implode(', ', $overriddenFeatures)),
'severity' => REQUIREMENT_ERROR,
];
}
// Get enabled modules with hosting in the name.
$enabled_hosting_modules = (array) db_query("SELECT name FROM {system} WHERE type = 'module' AND status = 1 AND name LIKE '%_hosting' ORDER BY weight ASC, name ASC")->fetchCol('name');
$hosting_modules_count = count($enabled_hosting_modules);
if ($hosting_modules_count != 1) {
$hosting_modules = !empty(implode(', ', $enabled_hosting_modules)) ? implode(', ', $enabled_hosting_modules) : 'None.';
$requirements['cu_profile_module_manager'] = array(
'title' => $t('Hosting Module Status'),
'value' => 'Hosting modules enabled: '. $hosting_modules,
'severity' => REQUIREMENT_ERROR,
);
}
}
// Check value LDAP Mixed Mode variable; warn if site is in Mixed Mode.
$ldapAuthArray = variable_get('ldap_authentication_conf', FALSE);
$authMode = $ldapAuthArray['authenticationMode'];
if ($authMode == 1) {
$requirements['authMode'] = array(
'title' => $t('Authentication Mode'),
'value' => $t('Site is in Mixed Mode'),
'severity' => REQUIREMENT_WARNING,
);
}
// Warn if Secure Permissions are not being loaded from code.
$securePerm = variable_get('secure_permissions_active', FALSE);
if ($securePerm == 0) {
$requirements['securePerm'] = array(
'title' => $t('Secure Permissions'),
'value' => $t('Secure Permissions are not being loaded from code'),
'severity' => REQUIREMENT_WARNING,
);
}
return $requirements;
}
/**
* Express 3.0.0 Update - Revert Features
*/
function cu_core_update_7059() {
cu_core_revert_features();
}
/**
* Express 3.0.2 Update - Rebuild permssions to force discovery of new roles
*/
function cu_core_update_7060() {
secure_permissions_rebuild();
// Set new Content Editor as the default role to invite.
$site_editor_role = user_role_load_by_name('site_editor');
variable_set('user_external_invite_default_role', $site_editor_role->rid);
}
/**
* Express 3.0.2 Update - Add Form Manager to "invitable" roles if Form Bundle is enabled
*/
function cu_core_update_7061() {
if (module_exists('cu_forms_bundle')) {
$form_manager_role = user_role_load_by_name('form_manager');
$invite_roles = variable_get('user_external_invite_addon_roles', array());
$invite_roles[] = $form_manager_role->rid;
variable_set('user_external_invite_addon_roles', $invite_roles);
}
}
/**
* Fixing array formatting of string overrides, Setting gtm variable.
*/
function cu_core_update_7062() {
module_enable(array('google_tag'));
variable_set('google_tag_container_id', 'GTM-M3DX2QP');
$locale_custom_strings_en = array();
$locale_custom_strings_en[''] = array(
'Each menu has a corresponding block that is managed on the <a href="@blocks">Blocks administration page</a>.' => 'Each menu has a corresponding block which can be placed in a content region.',
'You can enable the newly-created block for this menu on the <a href="@blocks">Blocks administration page</a>.' => 'Each menu has a corresponding block which can be placed in a content region.',
'Set and configure the default theme for your website. Alternative <a href="@themes">themes</a> are available.' => 'Set and configure the default theme for your website.',
'The menu module allows on-the-fly creation of menu links in the content authoring forms. To configure these settings for a particular content type, visit the <a href="@content-types">Content types</a> page, click the <em>edit</em> link for the content type, and go to the <em>Menu settings</em> section.' => 'The menu module allows on-the-fly creation of menu links.',
);
variable_set('locale_custom_strings_en', $locale_custom_strings_en);
}
/**
* Disabling Express Help module.
*/
function cu_core_update_7063() {
module_disable(array('express_help'));
drupal_uninstall_modules(array('express_help'));
}
/**
* Enabling Add Another module.
*/
function cu_core_update_7064() {
module_enable(array('addanother'));
}
/**
* Rebuild permissions.
*/
function cu_core_update_7065() {
secure_permissions_rebuild();
}
/**
* Reset affiliation value to match keys from ATLAS.
*/
function cu_core_update_7066() {
// This array contains keys of the original config with values of the new config.
$values = array(
'college_of_arts_sciences' => 'arts_sciences',
'leeds_school_business' => 'business',
'college_media_communication_information' => 'cmci',
'school_education' => 'education',
'college_engineering_applied_science' => 'engineering',
'institutional_equity' => 'institutional_equity_compliance',
'school_law' => 'law',
'college_music' => 'music',
'diversity_equity_engagement' => 'odece',
'research_innovation' => 'research_innovation_office',
'strategic_relations_communication' => 'strategic_relations_comm',
);
// Check to see if the affiliation has been set already.
if ($affiliation = variable_get('cu_site_affiliation_options', NULL)) {
// Check to see if the saved affiliation matches one of the changing values.
if (!empty($values[$affiliation])) {
variable_set('cu_site_affiliation_options', $values[$affiliation]);
}
}
}
/**
* Set affiliation and enable affiliation.
*/
function cu_core_update_7067() {
$current_affiliation = variable_get('cu_site_affiliation_options', NULL);
if (is_null($current_affiliation)) {
if ($atlas_id = variable_get('atlas_id', NULL)) {
$site_array = atlas_api_request('sites', $atlas_id);
if (!empty($site_array['major_unit'])) {
$atlas_major_unit = $site_array['major_unit'];
// Check to see if major_unit value returns affiliation settings.
$affiliation = cu_core_site_affiliation_options($atlas_major_unit);
if (!empty($affiliation)) {
variable_set('cu_site_affiliation_options', $atlas_major_unit);
}
}
variable_set('cu_affiliation_enable', 1);
}
}
}
/**
* Disable old tracking pixel modules.
*/
function cu_core_update_7068() {
$modules = array(
'cu_seo_admin_bundle',
'cu_tracking_pixel',
'cu_tracking_pixel_overview',
);
module_disable($modules);
drupal_uninstall_modules($modules);
}
/**
* Ensure responsive setting is set as expected now that the option for users to alter this setting has been removed.
*/
function cu_core_update_7069() {
$themes = list_themes();
$hidden_themes = variable_get('express_theme_picker_theme_ignore', array());
foreach ($themes as $theme) {
if (empty($hidden_themes[$theme->name])) {
$theme_settings = variable_get('theme_' . $theme->name . '_settings', array());
// Alpha responsive is set as a string in the theme's .info file. Set it as a string here, too.
$theme_settings['alpha-responsive'] = '1';
variable_set('theme_' . $theme->name . '_settings', $theme_settings);
}
}
}
/**
* Reverting cu_wysiwyg to add wowza video filter.
*/
function cu_core_update_7070() {
$features = array('cu_wysiwyg');
cu_core_revert_features($features);
}
/**
* Enable express_site_metrics module for Prometheus' gathering of metrics data.
*/
function cu_core_update_7071() {
module_enable(['express_site_metrics'], TRUE);
}