uw_sites_all.install 4.64 KB
Newer Older
Liam Morland's avatar
Liam Morland committed
1 2 3 4 5 6 7
<?php

/**
 * @file
 * Install, update and uninstall for UW Sites all.
 */

8 9
use Drupal\user\Entity\Role;

Liam Morland's avatar
Liam Morland committed
10 11 12 13 14 15
/**
 * Implements hook_install().
 */
function uw_sites_all_install() {
  // Add web resources news feed.
  $title = 'Web-resources news';
16 17
  $database = \Drupal::database();
  $fid = $database->query('SELECT fid FROM {aggregator_feed} WHERE title = :title', [':title' => $title])->fetchCol();
Liam Morland's avatar
Liam Morland committed
18 19 20 21 22 23 24 25 26 27

  if (empty($fid)) {
    $feed = \Drupal::entityTypeManager()->getStorage('aggregator_feed')->create([
      'uuid' => \Drupal::service('uuid')->generate(),
      'title' => $title,
      'url' => 'https://uwaterloo.ca/web-resources/news/news.xml',
      'created' => time(),
    ]);
    $feed->save();
  }
28

Liam Morland's avatar
Liam Morland committed
29
  // Make sure the theme is installed.
30 31 32
  $theme_handler = \Drupal::service('theme_handler');
  $theme_handler->install(['uw_theme_admin']);

Liam Morland's avatar
Liam Morland committed
33
  // Set it as the admin theme.
34 35
  $config = \Drupal::service('config.factory')->getEditable('system.theme');
  $config->set('admin', 'uw_theme_admin')->save();
36 37 38

  // Remove default "contact" form.
  \Drupal::entityTypeManager()->getStorage('webform')->load('contact')->delete();
Liam Morland's avatar
Liam Morland committed
39 40 41 42 43 44
}

/**
 * Implements hook_uninstall().
 */
function uw_sites_all_uninstall() {
Liam Morland's avatar
Liam Morland committed
45
  // phpcs:disable DrupalPractice.CodeAnalysis.VariableAnalysis.UnusedVariable
Liam Morland's avatar
Liam Morland committed
46 47 48
  $transaction = \Drupal::database()->startTransaction();

  $title = "Web-resources news";
49 50
  $database = \Drupal::database();
  $fid = $database->query('SELECT fid FROM {aggregator_feed} WHERE title = :title', [':title' => $title])->fetchCol();
Liam Morland's avatar
Liam Morland committed
51
  if (!empty($fid)) {
52 53 54 55 56 57 58 59

    $query = $database->delete('aggregator_feed');
    $query->condition('fid', $fid);
    $query->execute();

    $query = $database->delete('aggregator_item');
    $query->condition('fid', $fid);
    $query->execute();
Liam Morland's avatar
Liam Morland committed
60 61
  }
}
62

Liam Morland's avatar
Liam Morland committed
63 64 65 66
/**
 * Implements hook_update_N().
 */

67 68 69 70 71 72
/**
 * Enables OFIS module.
 */
function uw_sites_all_update_8101(&$sandbox) {
  \Drupal::service('module_installer')->install(['uw_ws_ofis']);
}
73 74 75 76 77 78 79

/**
 * Enables UW CKEditor Plugins module.
 */
function uw_sites_all_update_8102(&$sandbox) {
  \Drupal::service('module_installer')->install(['uw_ckeditor_plugins']);
}
80 81 82 83 84 85 86 87

/**
 * Protect all Webforms with Honeypot.
 */
function uw_sites_all_update_8103() {
  $config = \Drupal::service('config.factory')->getEditable('webform.settings');
  $config->set('third_party_settings.honeypot.honeypot', TRUE)->save();
}
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

/**
 * Enable Override Node Options module and assigns permissions to roles.
 */
function uw_sites_all_update_8104() {
  \Drupal::service('module_installer')->install(['override_node_options']);

  // List of permissions needed to be applied to roles.
  $permissions = [
    'enter uw_ct_blog revision log entry',
    'enter uw_ct_catalog_item revision log entry',
    'enter uw_ct_contact revision log entry',
    'enter uw_ct_event revision log entry',
    'enter uw_ct_news_item revision log entry',
    'enter uw_ct_profile revision log entry',
    'enter uw_ct_web_page revision log entry',
    'override uw_ct_blog promote to front page option',
    'override uw_ct_blog published option',
    'override uw_ct_blog revision option',
    'override uw_ct_blog sticky option',
    'override uw_ct_catalog_item published option',
    'override uw_ct_catalog_item revision option',
    'override uw_ct_contact published option',
    'override uw_ct_contact revision option',
    'override uw_ct_event promote to front page option',
    'override uw_ct_event published option',
    'override uw_ct_event revision option',
    'override uw_ct_event sticky option',
    'override uw_ct_news_item promote to front page option',
    'override uw_ct_news_item published option',
    'override uw_ct_news_item revision option',
    'override uw_ct_news_item sticky option',
    'override uw_ct_profile published option',
    'override uw_ct_profile revision option',
    'override uw_ct_web_page published option',
    'override uw_ct_web_page revision option',
  ];

  // Roles that require updated permissions.
  $role_ids = [
    'uw_role_site_manager',
    'uw_role_content_editor',
    'uw_role_content_author',
  ];

  $roles = Role::loadMultiple($role_ids);

  // Grant all all roles.
  foreach ($permissions as $permission) {
    $roles['uw_role_site_manager']->grantPermission($permission);
    $roles['uw_role_content_editor']->grantPermission($permission);
    $roles['uw_role_content_author']->grantPermission($permission);
  }

  // Save role with new permissions.
  $roles['uw_role_site_manager']->save();
  $roles['uw_role_content_editor']->save();
  $roles['uw_role_content_author']->save();
}
147 148 149 150 151 152 153

/**
 * Enables Quick Node Clone module.
 */
function uw_sites_all_update_8105(&$sandbox) {
  \Drupal::service('module_installer')->install(['quick_node_clone']);
}