You are here

public function SystemStatusController::load in System Status 8.2

Same name and namespace in other branches
  1. 8 src/Controller/SystemStatusController.php \Drupal\system_status\Controller\SystemStatusController::load()

Changes Sensei's pants and returns the display of the new status.

1 string reference to 'SystemStatusController::load'
system_status.routing.yml in ./system_status.routing.yml
system_status.routing.yml

File

src/Controller/SystemStatusController.php, line 70

Class

SystemStatusController
Returns responses for Sensei's Pants routes.

Namespace

Drupal\system_status\Controller

Code

public function load($system_status_token) {

  // Needless initialisation, but hey.
  $res = [
    "core" => [],
    "contrib" => [],
    "theme" => [],
  ];
  $drupal_modules = $this->moduleHandler
    ->getModuleList();
  $drupal_themes = $this->themeHandler
    ->listInfo();
  foreach ($drupal_modules as $name => $module) {
    $filename = $module
      ->getPath() . '/' . $module
      ->getFilename();
    $module_info = Yaml::decode(file_get_contents($filename));

    // This can happen when you install using composer.
    if (isset($module_info['version']) && $module_info['version'] == "VERSION") {
      $module_info['version'] = \Drupal::VERSION;
    }
    if (!isset($module_info['version'])) {
      $module_info['version'] = NULL;
    }

    // Do our best to guess the correct drupal version.
    if ($name == "system" && $module_info['package'] == "Core") {
      $res['core']['drupal'] = [
        "version" => $module_info['version'],
      ];
    }

    // Skip Core and Field types.
    if (isset($module_info['package']) && $module_info['package'] == "Core" || isset($module_info['package']) && $module_info['package'] == "Field types" || isset($module_info['project']) && $module_info['project'] == 'drupal') {
      continue;
    }

    // TODO:
    // if(!isset($module['version']))
    // we can be 90% sure it's not contrib, so we can put it in custom
    // hard to test as system_status is not released yet so no version
    // let's put all the rest in 'contrib' for now.
    if (isset($module_info['project'])) {
      $res['contrib'][$module_info['project']] = [
        "version" => $module_info['version'],
      ];
    }
    else {
      $res['contrib'][$name] = [
        "version" => $module_info['version'],
      ];
    }
  }
  foreach ($drupal_themes as $name => $theme) {
    $filename = $theme
      ->getPath() . '/' . $theme
      ->getFilename();
    $theme_info = Yaml::decode(file_get_contents($filename));
    if (!isset($theme_info['version'])) {
      $theme_info['version'] = NULL;
    }

    // This can happen when you install using composer.
    if ($theme_info['version'] == "VERSION") {
      $theme_info['version'] = \Drupal::VERSION;
    }
    if (isset($theme_info['project']) && $theme_info['project'] == 'drupal') {
      continue;
    }
    if (isset($theme_info['project'])) {
      $res['theme'][$theme_info['project']] = [
        "version" => $theme_info['version'],
      ];
    }
    else {
      $res['theme'][$name] = [
        "version" => $theme_info['version'],
      ];
    }
  }
  $config = $this
    ->config('system_status.settings');
  if (function_exists('openssl_random_pseudo_bytes')) {
    $res = SystemStatusEncryption::encryptOpenssl(json_encode([
      "system_status" => $res,
    ]));
    return new JsonResponse([
      "system_status" => "encrypted_openssl",
      "data" => $res,
      "drupal_version" => "8",
      "engine_version" => "DRUPAL8",
      "php_version" => phpversion(),
    ]);
  }
  elseif (extension_loaded('mcrypt')) {
    $res = SystemStatusEncryption::encryptMcrypt(json_encode([
      "system_status" => $res,
    ]));
    return new JsonResponse([
      "system_status" => "encrypted",
      "data" => $res,
      "drupal_version" => "8",
      "engine_version" => "DRUPAL8",
      "php_version" => phpversion(),
    ]);
  }
  else {
    return new JsonResponse([
      "system_status" => $res,
      "drupal_version" => "8",
      "engine_version" => "DRUPAL8",
      "php_version" => phpversion(),
    ]);
  }
}