You are here

openatrium.install in Open Atrium 7.2

Perform actions to set up the site for this profile.

File

openatrium.install
View source
<?php

/**
 * @file
 * Perform actions to set up the site for this profile.
 */

/**
 * Implements hook_install_tasks()
 */
function openatrium_install_tasks(&$install_state) {
  $tasks = array();

  // Add our custom CSS file for the installation process.
  drupal_add_css(drupal_get_path('profile', 'openatrium') . '/openatrium.css');
  require_once drupal_get_path('module', 'apps') . '/apps.profile.inc';
  $server = array(
    'machine name' => 'openatrium',
    'default apps' => array(
      // built-in apps.
      'oa_discussion',
      'oa_events',
      'oa_wiki',
      'oa_worktracker',
      // Core addon apps.
      'oa_admin',
      'oa_appearance',
      'oa_archive',
      'oa_brand',
      'oa_clone',
      'oa_comment',
      'oa_contextual_tabs',
      'oa_events_import',
      'oa_export',
      'oa_favorites',
      'oa_files',
      'oa_home',
      'oa_htmlmail',
      'oa_media',
      'oa_messages_digest',
      'oa_notifications',
      // Currently having problems with oa_project enabling during install
      // So leave this off for now
      //  'oa_project',.
      'oa_related',
      'oa_sandbox',
      'oa_search',
      'oa_sitemap',
      'oa_site_layout',
      'oa_site_layout_defaults',
      'oa_styles',
      'oa_subspaces',
      'oa_toolbar',
      'oa_tour',
      'oa_tour_defaults',
      'oa_wizard',
    ),
  );
  $tasks = apps_profile_install_tasks($install_state, $server);
  $tasks['openatrium_features_revert_all'] = array(
    'type' => 'normal',
  );

  // Set default permissions.
  $tasks['openatrium_set_permissions'] = array(
    'type' => 'normal',
  );

  // Need to rebuild search index tables since oa_search changes panopoly_search.
  $tasks['openatrium_rebuild_search'] = array(
    'type' => 'normal',
  );

  // Rebuild node access..
  $tasks['openatrium_node_access_rebuild'] = array(
    'type' => 'normal',
  );

  // Skip tasks if using quickstart.
  if (!empty($install_state['parameters']['quickstart']) && $install_state['parameters']['quickstart'] == 'quick') {
    foreach ($tasks as $task_name => $task) {
      $tasks[$task_name]['run'] = INSTALL_TASK_SKIP;
    }
  }

  /*** TASKS BELOW RUN EVEN WITH QUICKSTART ***/

  // Revert bootstrap tour defaults.
  $tasks['openatrium_revert_tours'] = array(
    'type' => 'normal',
  );
  return $tasks;
}

/**
 * Revert all features.
 */
function openatrium_features_revert_all() {
  global $install_state;
  drupal_set_time_limit(0);
  features_revert(array(
    'oa_core' => array(
      'field_base',
    ),
    'oa_sections' => array(
      'field_base',
      'field_instance',
    ),
    'oa_users' => array(
      'field_instance',
    ),
  ));
  features_revert();
}

/**
 * Revert oa_tour_default feature.
 */
function openatrium_revert_tours() {
  features_revert(array(
    'oa_tour_defaults' => array(
      'bootstrap_tour',
    ),
  ));
}

/**
 * Update permissions.
 */
function openatrium_set_permissions() {

  // Update admin and member permissions.
  oa_adminrole_update_roles();
}

/**
 * Rebuild search index.
 */
function openatrium_rebuild_search() {
  global $install_state;
  require_once drupal_get_path('module', 'oa_search') . '/oa_search.install';
  features_revert(array(
    'oa_search' => array(
      'search_api_index',
    ),
  ));
  oa_search_rebuild_index();
}

/**
 * Wrapper around node access rebuild, as didn't work till I wrapped it.
 */
function openatrium_node_access_rebuild() {
  node_access_rebuild();
  openatrium_remove_message('Content permissions have been rebuilt');
}

/**
 * Implements hook_install_tasks_alter()
 */
function openatrium_install_tasks_alter(&$tasks, $install_state) {
  require_once drupal_get_path('module', 'oa_core') . '/oa_core.profile.inc';
  $tasks['install_load_profile']['function'] = 'oa_core_install_load_profile';

  // Add option for importing from db.
  install_from_db_install_tasks_alter($tasks, $install_state);
}

/**
 * Implements hook_form_FORM_ID_alter() for apps_profile_apps_select.
 */
function openatrium_form_apps_profile_apps_select_form_alter(&$form, $form_state) {

  // Disabling showing of these for now.
  $form['apps_message']['#access'] = FALSE;
  unset($form['apps_fieldset']['apps']['#title']);

  // Remove the demo content selection option since this is handled through the Panopoly demo module.
  $form['default_content_fieldset']['#access'] = FALSE;
}

/**
 * Implements hook_install().
 */
function openatrium_install() {

  // Set the default theme.
  _openatrium_set_up_theme();

  // Put modules into contrib.
  variable_set('apps_install_path', 'sites/all/modules/contrib');
}

/**
 * Set the default theme.
 */
function _openatrium_set_up_theme() {
  $theme = 'oa_theme';
  theme_enable(array(
    $theme,
  ));
  variable_set('theme_default', $theme);
  theme_disable(array(
    'responsive_bartik',
    'bartik',
    'oa_radix',
  ));
}

/**
 * Implements hook_requirements().
 */
function openatrium_requirements($phase) {

  // Cannot test during install time because menu is how test and can't use that.
  $requirements = array();

  // Ensure translations don't break during installation.
  $t = get_t();

  // Report Drupal version.
  if ($phase == 'runtime') {
    $available = FALSE;
    if (strpos(request_uri(), '?q=') === FALSE && strpos(request_uri(), '&q=') === FALSE) {
      $available = TRUE;
    }
    else {
      $request = drupal_http_request($GLOBALS['base_url'] . '/admin/config/search/clean-urls/check');

      // If the request returns HTTP 200, clean URLs are available.
      if (isset($request->code) && $request->code == 200 && ($data = drupal_json_decode($request->data)) && !empty($data['status'])) {
        $available = TRUE;
      }
    }
    if (!$available) {
      $requirements['clean_urls_available'] = array(
        'title' => $t('Clean Urls Available'),
        'value' => $t('Clean Urls is not available, but OpenAtrium requires it to function properly.'),
        'severity' => REQUIREMENT_ERROR,
      );
    }
    if ($phase == 'runtime' && !variable_get('clean_url', 0)) {
      $requirements['clean_urls_enabled'] = array(
        'title' => $t('Clean Urls Enabled'),
        'value' => $t('Clean Urls are not enabled, but OpenAtrium requires it to function properly.'),
        'severity' => REQUIREMENT_ERROR,
      );
    }
  }
  return $requirements;
}

/**
 * Enable oa_variables module.
 */
function openatrium_update_7002() {
  if (!module_exists('oa_variables') && !module_enable(array(
    'oa_variables',
  ))) {
    trigger_error('Unable to enable oa_variables module. Please check for any missing dependencies.');
  }

  // This may be missing from older installs.
  $missing = array(
    'backports',
    'date_popup_authored',
    'simplified_menu_admin',
  );
  module_enable($missing);

  // Ensure the install profile is enabled.
  module_enable(array(
    'openatrium',
  ));
}

/**
 * Enable oa_buttons.
 */
function openatrium_update_7003() {
  $enable = array(
    'oa_buttons',
  );
  module_enable($enable);
}

/**
 * Enable trash_flag.
 */
function openatrium_update_7004() {
  $enable = array(
    'trash_flag',
  );
  module_enable($enable);
}

/**
 * Enable command_buttons.
 */
function openatrium_update_7005() {
  $enable = array(
    'command_buttons',
  );
  module_enable($enable);
}

/**
 * Enable date_all_day.
 */
function openatrium_update_7006() {
  $enable = array(
    'date_all_day',
  );
  module_enable($enable);
}

/**
 * Enable panels_customerror.
 */
function openatrium_update_7007() {
  $enable = array(
    'panels_customerror',
  );
  module_enable($enable);
}

/**
 * Enable oa_contextual_tabs.
 */
function openatrium_update_7008() {
  $enable = array(
    'oa_contextual_tabs',
  );
  module_enable($enable);
}

/**
 * Enable oa_export.
 */
function openatrium_update_7009() {
  $enable = array(
    'oa_export',
  );
  module_enable($enable);
}

Functions

Namesort descending Description
openatrium_features_revert_all Revert all features.
openatrium_form_apps_profile_apps_select_form_alter Implements hook_form_FORM_ID_alter() for apps_profile_apps_select.
openatrium_install Implements hook_install().
openatrium_install_tasks Implements hook_install_tasks()
openatrium_install_tasks_alter Implements hook_install_tasks_alter()
openatrium_node_access_rebuild Wrapper around node access rebuild, as didn't work till I wrapped it.
openatrium_rebuild_search Rebuild search index.
openatrium_requirements Implements hook_requirements().
openatrium_revert_tours Revert oa_tour_default feature.
openatrium_set_permissions Update permissions.
openatrium_update_7002 Enable oa_variables module.
openatrium_update_7003 Enable oa_buttons.
openatrium_update_7004 Enable trash_flag.
openatrium_update_7005 Enable command_buttons.
openatrium_update_7006 Enable date_all_day.
openatrium_update_7007 Enable panels_customerror.
openatrium_update_7008 Enable oa_contextual_tabs.
openatrium_update_7009 Enable oa_export.
_openatrium_set_up_theme Set the default theme.