You are here

private function EvaluationImplementation::systemList in Drupal 8 upgrade evaluation 6

Backport of the DBTNG system_list() from Drupal 7.

2 calls to EvaluationImplementation::systemList()
EvaluationImplementation::upgradeCheckModulesData in includes/EvaluationImplementation.php
Fetch data of all enabled modules.
EvaluationImplementation::upgradeCheckThemesData in includes/EvaluationImplementation.php
Fetch data of all enabled themes.

File

includes/EvaluationImplementation.php, line 956

Class

EvaluationImplementation

Namespace

Upgrade_check

Code

private function systemList($type) {
  $lists =& $this
    ->drupalStatic(__FUNCTION__);

  // For bootstrap modules, attempt to fetch the list from cache if possible.
  // if not fetch only the required information to fire bootstrap hooks
  // in case we are going to serve the page from cache.
  if ($type == 'bootstrap') {
    if (isset($lists['bootstrap'])) {
      return $lists['bootstrap'];
    }
    $query = db_query("SELECT name, filename FROM {system} WHERE status = 1 AND bootstrap = 1 AND type = 'module' ORDER BY weight ASC, name ASC");
    $bootstrap_list = $this
      ->dbFetchAllAssoc($query, 'name');

    // To avoid a separate database lookup for the filepath, prime the
    // drupal_get_filename() static cache for bootstrap modules only.
    // The rest is stored separately to keep the bootstrap module cache small.
    foreach ($bootstrap_list as $module) {
      drupal_get_filename('module', $module->name, $module->filename);
    }

    // We only return the module names here since module_list() doesn't need
    // the filename itself.
    $lists['bootstrap'] = array_keys($bootstrap_list);
  }
  elseif (!isset($lists['module_enabled'])) {
    $lists = array(
      'module_enabled' => array(),
      'theme' => array(),
      'filepaths' => array(),
    );

    // The module name (rather than the filename) is used as the fallback
    // weighting in order to guarantee consistent behavior across different
    // Drupal installations, which might have modules installed in different
    // locations in the file system. The ordering here must also be
    // consistent with the one used in module_implements().
    $query = db_query("SELECT * FROM {system} WHERE type = 'theme' OR (type = 'module' AND status = 1) ORDER BY weight ASC, name ASC");
    while ($record = db_fetch_object($query)) {
      if (!empty($record)) {
        $record->info = unserialize($record->info);

        // Build a list of all enabled modules.
        if ($record->type == 'module') {
          $lists['module_enabled'][$record->name] = $record;
        }

        // Build a list of themes.
        if ($record->type == 'theme') {
          $lists['theme'][$record->name] = $record;
        }

        // Build a list of filenames so drupal_get_filename can use it.
        if ($record->status) {
          $lists['filepaths'][] = array(
            'type' => $record->type,
            'name' => $record->name,
            'filepath' => $record->filename,
          );
        }
      }
    }
    foreach ($lists['theme'] as $key => $theme) {
      if (!empty($theme->info['base theme'])) {

        // Make a list of the theme's base themes.
        $lists['theme'][$key]->base_themes = $this
          ->drupalFindBaseThemes($lists['theme'], $key);

        // Don't proceed if there was a problem with the root base theme.
        if (!current($lists['theme'][$key]->base_themes)) {
          continue;
        }

        // Determine the root base theme.
        $base_key = key($lists['theme'][$key]->base_themes);

        // Add to the list of sub-themes for each of the theme's base themes.
        foreach (array_keys($lists['theme'][$key]->base_themes) as $base_theme) {
          $lists['theme'][$base_theme]->sub_themes[$key] = $lists['theme'][$key]->info['name'];
        }

        // Add the base theme's theme engine info.
        $lists['theme'][$key]->info['engine'] = isset($lists['theme'][$base_key]->info['engine']) ? $lists['theme'][$base_key]->info['engine'] : 'theme';
      }
      else {

        // A plain theme is its own engine.
        $base_key = $key;
        if (!isset($lists['theme'][$key]->info['engine'])) {
          $lists['theme'][$key]->info['engine'] = 'theme';
        }
      }

      // Set the theme engine prefix.
      $lists['theme'][$key]->prefix = $lists['theme'][$key]->info['engine'] == 'theme' ? $base_key : $lists['theme'][$key]->info['engine'];
    }

    // To avoid a separate database lookup for the filepath, prime the
    // drupal_get_filename() static cache with all enabled modules and themes.
    foreach ($lists['filepaths'] as $item) {
      drupal_get_filename($item['type'], $item['name'], $item['filepath']);
    }
  }
  return $lists[$type];
}