You are here

varbase.install in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 7.3

File

varbase.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the News install profile.
 */
require_once __DIR__ . '/varbase_install.inc';

/**
 * Implements hook_install_tasks().
 *
 */
function varbase_install_tasks() {

  // Increase maximum function nesting level to prevent install errors if you have xdebug installed.
  $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);
  }
}

/**
 * Implements hook_install_tasks_alter().
 *
 */
function varbase_install_tasks_alter(&$tasks, $install_state) {
  $needs_translations = count($install_state['locales']) > 1 && !empty($install_state['parameters']['locale']) && $install_state['parameters']['locale'] != 'en';

  // Add Extra dependency
  if ($install_state['parameters']['profile'] == 'varbase') {
    $varbase_install_load_profile_extra = array(
      'varbase_install_load_profile_extra' => array(
        'run' => INSTALL_TASK_RUN_IF_REACHED,
      ),
    );
    _array_splice_assoc($tasks, 3, 0, $varbase_install_load_profile_extra);
  }

  // Add Extra verification requirements and dependencies
  $tasks['install_verify_requirements']['function'] = 'varbase_install_verify_requirements';
  $tasks['install_finished']['function'] = 'varbase_install_finished';
  $tasks['install_finished']['type'] = 'batch';
  $tasks['install_finished']['display'] = TRUE;
}
function varbase_install_load_profile_extra(&$install_state) {

  // Add varbase_default_settings feature as a dependancey only if the installation profile is varbase
  $install_state['profile_info']['dependencies'][] = 'varbase_default_settings';
}

/**
 * Verifies the requirements for installing Drupal & Varbase.
 * for more information check install_verify_requirements().
 *
 * @todo we need to find another way to alter install requirements without
 * overriding the whole Drupal core function.
 *
 * @param $install_state
 *   An array of information about the current installation state.
 *
 * @return
 *   A themed status report, or an exception if there are requirement errors.
 *   If there are only requirement warnings, a themed status report is shown
 *   initially, but the user is allowed to bypass it by providing 'continue=1'
 *   in the URL. Otherwise, no output is returned, so that the next task can be
 *   run in the same page request.
 */
function varbase_install_verify_requirements(&$install_state) {

  // Check the installation requirements for Drupal and this profile.
  $requirements = install_check_requirements($install_state);

  // Varbase extra install requirments.
  $requirements += varbase_verify_requirments($install_state);

  // Verify existence of all required modules.
  $requirements += drupal_verify_profile($install_state);

  // Check the severity of the requirements reported.
  $severity = drupal_requirements_severity($requirements);

  // If there are errors, always display them. If there are only warnings, skip
  // them if the user has provided a URL parameter acknowledging the warnings
  // and indicating a desire to continue anyway. See drupal_requirements_url().
  if ($severity == REQUIREMENT_ERROR || $severity == REQUIREMENT_WARNING && empty($install_state['parameters']['continue'])) {
    if ($install_state['interactive']) {
      drupal_set_title(st('Requirements problem'));
      $status_report = theme('status_report', array(
        'requirements' => $requirements,
      ));
      $status_report .= st('Check the error messages and <a href="!url">proceed with the installation</a>.', array(
        '!url' => check_url(drupal_requirements_url($severity)),
      ));
      return $status_report;
    }
    else {

      // Throw an exception showing any unmet requirements.
      $failures = array();
      foreach ($requirements as $requirement) {

        // Skip warnings altogether for non-interactive installations; these
        // proceed in a single request so there is no good opportunity (and no
        // good method) to warn the user anyway.
        if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) {
          $failures[] = $requirement['title'] . ': ' . $requirement['value'] . "\n\n" . $requirement['description'];
        }
      }
      if (!empty($failures)) {
        throw new Exception(implode("\n\n", $failures));
      }
    }
  }
}

/**
 * Finishes importing files at end of installation.
 *
 * @param $install_state
 *   An array of information about the current installation state.
 *
 * @return
 *   A message informing the user that the installation is complete.
 */
function varbase_install_finished(&$install_state) {
  drupal_static_reset();
  drupal_get_schema(NULL, TRUE);

  // Remember the profile which was used.
  variable_set('install_profile', drupal_get_profile());

  // Installation profiles are always loaded last
  db_update('system')
    ->fields(array(
    'weight' => 1000,
  ))
    ->condition('type', 'module')
    ->condition('name', drupal_get_profile())
    ->execute();
  $batch = _varbase_install_batch_finished();
  return $batch;
}
function _varbase_install_batch_finished() {
  $operations = array();

  // Define finishing step
  $operations[] = array(
    '_varbase_install_rebuild_features_keys',
    array(),
  );
  $operations[] = array(
    '_varbase_install_rebuild_features_defaultconfig_rebuild',
    array(),
  );
  $operations[] = array(
    '_varbase_install_rebuild_features_all',
    array(),
  );
  $operations[] = array(
    '_varbase_install_drupal_cc_all',
    array(),
  );
  $batch = array(
    'operations' => $operations,
    'finished' => '_varbase_install_finished_batch_finished',
    'title' => t('Finishing install'),
    'init_message' => t('please wait for until we finalize your installation.'),
    'progress_message' => t('Finalizing installation.'),
    'error_message' => t('Installtion have encountered error please contact the site admin as your database maybe corrupted.'),
    'file' => drupal_get_path('profile', 'varbase') . '/varbase_batch.inc',
  );
  return $batch;
}

/**
 * Implements hook_install().
 *
 * Perform actions to set up the site for this profile.
 *
 * @see system_install()
 */
function varbase_install() {

  //themes to enable and disable
  theme_enable(array(
    'vartheme_admin',
    'vartheme',
    'adminimal',
  ));
  theme_disable(array(
    'bartik',
  ));
  variable_set('theme_default', 'vartheme');
  variable_set('admin_theme', 'vartheme_admin');
}

/**
 * Replace array element and keeping the order and the inserted key
 *
 */
function _array_splice_assoc(&$input, $offset, $length, $replacement) {
  $replacement = (array) $replacement;
  $key_indices = array_flip(array_keys($input));
  if (isset($input[$offset]) && is_string($offset)) {
    $offset = $key_indices[$offset];
  }
  if (isset($input[$length]) && is_string($length)) {
    $length = $key_indices[$length] - $offset;
  }
  $input = array_slice($input, 0, $offset, TRUE) + $replacement + array_slice($input, $offset + $length, NULL, TRUE);
}

/**
 * Implements hook_update_N().
 */
function varbase_update_7200() {

  // Disable & uninstall Remember Me module.
  if (module_exists('remember_me')) {
    module_disable(array(
      'remember_me',
    ));
    drupal_uninstall_modules(array(
      'remember_me',
    ));
  }

  // Enable Persistent Login module.
  if (module_exists('persistent_login')) {
    module_enable(array(
      'persistent_login',
    ));
  }
}

Functions

Namesort descending Description
varbase_install Implements hook_install().
varbase_install_finished Finishes importing files at end of installation.
varbase_install_load_profile_extra
varbase_install_tasks Implements hook_install_tasks().
varbase_install_tasks_alter Implements hook_install_tasks_alter().
varbase_install_verify_requirements Verifies the requirements for installing Drupal & Varbase. for more information check install_verify_requirements().
varbase_update_7200 Implements hook_update_N().
_array_splice_assoc Replace array element and keeping the order and the inserted key
_varbase_install_batch_finished