You are here

function upgrade_assist_disable_modules in Upgrade Status 6

Form constructor to disable non-core modules.

File

upgrade_assist/upgrade_assist.module, line 485
Assists in upgrading Drupal.

Code

function upgrade_assist_disable_modules() {
  drupal_set_title(t('Disable non-core modules'));
  $options = array();
  $default_value = array();
  $form['#modules'] = array();
  $form['#projects'] = array();
  $result = db_query("SELECT * FROM {system} WHERE type = 'module'");
  while ($module = db_fetch_object($result)) {
    $module->info = unserialize($module->info);

    // Skip required core modules and hidden modules.
    if (!empty($module->info['required']) || !empty($module->info['hidden'])) {
      continue;
    }

    // Ignore core modules by package. Although there might be bogus modules
    // that use a Drupal core package name, those are rarely seen and not
    // supported here.
    if (in_array($module->info['package'], array(
      'Core - required',
      'Core - optional',
    ))) {
      continue;
    }

    // Only enabled modules can be disabled.
    if ($module->status) {
      $form['#modules'][$module->name] = array(
        'name' => $module->info['name'],
        'project' => $module->info['project'],
      );

      // @todo Make use of Upgrade Status information, if available. We are only
      //   interested in projects that are actually available for the new
      //   version. Thus, add project title + recommended release info.
      if (isset($module->info['project'])) {
        $form['#projects'][$module->name] = array(
          'project' => $module->info['project'],
        );
      }

      // Skip Upgrade Assist and its dependencies. We need their module and
      // project info though.
      if (in_array($module->name, array(
        'upgrade_assist',
        'demo',
      ))) {
        continue;
      }
      $options[$module->name] = t('@project: @name', array(
        '@project' => isset($module->info['project']) ? $module->info['project'] : t('Unknown'),
        '@name' => $module->info['name'],
      ));
      $default_value[$module->name] = $module->name;
    }
  }
  if ($options) {

    // Sort options by label.
    asort($options);
    $form['disable'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Modules to disable'),
      '#options' => $options,
      '#default_value' => $default_value,
      '#description' => t('All disabled modules are tracked and may be re-enabled after upgrading Drupal core.'),
    );
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Disable'),
    );
  }
  else {
    drupal_set_message(t('All non-core modules have been disabled already.'), 'warning');
  }
  return $form;
}