You are here

function openatrium_profile_tasks in Open Atrium 6

Implementation of hook_profile_tasks().

File

./openatrium.profile, line 134

Code

function openatrium_profile_tasks(&$task, $url) {
  global $profile, $install_locale;

  // Just in case some of the future tasks adds some output
  $output = '';

  // Download and install translation if needed
  if ($task == 'profile') {

    // Rebuild the language list.
    // When running through the CLI, the static language list will be empty
    // unless we repopulate it from the ,newly available, database.
    language_list('name', TRUE);
    $task = 'intranet-modules';
  }

  // We are running a batch task for this profile so basically do nothing and return page
  if (in_array($task, array(
    'intranet-modules-batch',
    'l10n-install-batch',
    'intranet-configure-batch',
  ))) {
    include_once 'includes/batch.inc';
    $output = _batch_page();
  }

  // Install some more modules and maybe localization helpers too
  if ($task == 'intranet-modules') {
    $modules = _openatrium_atrium_modules();
    $files = module_rebuild_cache();

    // Create batch
    foreach ($modules as $module) {
      $batch['operations'][] = array(
        '_install_module_batch',
        array(
          $module,
          $files[$module]->info['name'],
        ),
      );
    }
    $batch['finished'] = '_openatrium_profile_batch_finished';
    $batch['title'] = st('Installing @drupal', array(
      '@drupal' => drupal_install_profile_name(),
    ));
    $batch['error_message'] = st('The installation has encountered an error.');

    // Start a batch, switch to 'intranet-modules-batch' task. We need to
    // set the variable here, because batch_process() redirects.
    variable_set('install_task', 'intranet-modules-batch');
    batch_set($batch);
    batch_process($url, $url);

    // Just for cli installs. We'll never reach here on interactive installs.
    return;
  }
  if ($task == 'l10n-install') {
    if (_openatrium_language_selected()) {
      $history = l10n_update_get_history();
      module_load_include('check.inc', 'l10n_update');
      $available = l10n_update_available_releases();
      $updates = l10n_update_build_updates($history, $available);
      module_load_include('batch.inc', 'l10n_update');
      $updates = _l10n_update_prepare_updates($updates, NULL, array());
      $batch = l10n_update_batch_multiple($updates, LOCALE_IMPORT_KEEP);

      // Overwrite batch finish callback, so we can modify install task too.
      $batch['finished'] = '_openatrium_translate_batch_finished';

      // Start a batch, switch to 'l10n-install-batch' task. We need to
      // set the variable here, because batch_process() redirects.
      variable_set('install_task', 'l10n-install-batch');
      batch_set($batch);
      batch_process($url, $url);

      // Just for cli installs. We'll never reach here on interactive installs.
      return;
    }
    $task = 'intranet-configure';
  }

  // Run additional configuration tasks
  // @todo Review all the cache/rebuild options at the end, some of them may not be needed
  // @todo Review for localization, the time zone cannot be set that way either
  if ($task == 'intranet-configure') {
    $batch['title'] = st('Configuring @drupal', array(
      '@drupal' => drupal_install_profile_name(),
    ));
    $batch['operations'][] = array(
      '_openatrium_intranet_configure',
      array(),
    );
    $batch['operations'][] = array(
      '_openatrium_intranet_configure_check',
      array(),
    );
    $batch['finished'] = '_openatrium_intranet_configure_finished';
    variable_set('install_task', 'intranet-configure-batch');
    batch_set($batch);
    batch_process($url, $url);

    // Jut for cli installs. We'll never reach here on interactive installs.
    return;
  }
  return $output;
}