Commit 520f1c51 authored by alexpott's avatar alexpott

Issue #1987824 by nick_schuch, vijaycs85, ParisLiakos: Convert system_php() to...

Issue #1987824 by nick_schuch, vijaycs85, ParisLiakos: Convert system_php() to a new style controller.
parent 5ccb4329
<?php
/**
* @file
* Contains \Drupal\system\Controller\SystemInfoController.
*/
namespace Drupal\system\Controller;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
use Drupal\Core\ControllerInterface;
use Drupal\Core\Database\Connection;
use Drupal\system\SystemManager;
/**
* Returns responses for System Info routes.
*/
class SystemInfoController implements ControllerInterface {
/**
* System Manager Service.
*
* @var \Drupal\system\SystemManager
*/
protected $systemManager;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('system.manager')
);
}
/**
* Constructs a SystemInfoController object.
*
* @param \Drupal\system\SystemManager $systemManager
* System manager service.
*/
public function __construct(SystemManager $systemManager) {
$this->systemManager = $systemManager;
}
/**
* Displays the site status report.
*
* @return string
* The current status of the Drupal installation.
*/
public function status() {
$requirements = $this->systemManager->listRequirements();
$this->systemManager->fixAnonymousUid();
return theme('status_report', array('requirements' => $requirements));
}
/**
* Returns the contents of phpinfo().
*
* @return \Symfony\Component\HttpFoundation\Response
* A response object to be sent to the client.
*/
public function php() {
ob_start();
phpinfo();
$output = ob_get_clean();
return new Response($output);
}
}
<?php
/**
* @file
* Contains \Drupal\system\SystemManager.
*/
namespace Drupal\system;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Extension\ModuleHandlerInterface;
/**
* System Manager Service.
*/
class SystemManager {
/**
* Module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Database Service Object.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* Requirement severity -- Requirement successfully met.
*/
const REQUIREMENT_OK = 0;
/**
* Requirement severity -- Warning condition; proceed but flag warning.
*/
const REQUIREMENT_WARNING = 1;
/**
* Requirement severity -- Error condition; abort installation.
*/
const REQUIREMENT_ERROR = 2;
/**
* Constructs a SystemManager object.
*/
public function __construct(ModuleHandlerInterface $module_handler, Connection $database) {
$this->moduleHandler = $module_handler;
$this->database = $database;
}
/**
* Checks for requirement severity.
*
* @return boolean
* Returns the status of the system.
*/
public function checkRequirements() {
$requirements = $this->listRequirements();
return $this->getMaxSeverity($requirements) == static::REQUIREMENT_ERROR;
}
/**
* Displays the site status report. Can also be used as a pure check.
*
* @return array
* An array of system requirements.
*/
public function listRequirements() {
// Load .install files
include_once DRUPAL_ROOT . '/core/includes/install.inc';
drupal_load_updates();
// Check run-time requirements and status information.
$requirements = $this->moduleHandler->invokeAll('requirements', array('runtime'));
usort($requirements, function($a, $b) {
if (!isset($a['weight'])) {
if (!isset($b['weight'])) {
return strcmp($a['title'], $b['title']);
}
return -$b['weight'];
}
return isset($b['weight']) ? $a['weight'] - $b['weight'] : $a['weight'];
});
return $requirements;
}
/**
* Fixes anonymous user on MySQL.
*
* MySQL import might have set the uid of the anonymous user to autoincrement
* value. Let's try fixing it. See http://drupal.org/node/204411
*/
public function fixAnonymousUid() {
$this->database->update('users')
->expression('uid', 'uid - uid')
->condition('name', '')
->condition('pass', '')
->condition('status', 0)
->execute();
}
/**
* Extracts the highest severity from the requirements array.
*
* @param $requirements
* An array of requirements, in the same format as is returned by
* hook_requirements().
*
* @return
* The highest severity in the array.
*/
public function getMaxSeverity(&$requirements) {
$severity = static::REQUIREMENT_OK;
foreach ($requirements as $requirement) {
if (isset($requirement['severity'])) {
$severity = max($severity, $requirement['severity']);
}
}
return $severity;
}
}
......@@ -19,7 +19,8 @@
*/
function system_admin_config_page() {
// Check for status report errors.
if (system_status(TRUE) && user_access('administer site configuration')) {
// @todo Use depedancy injection in http://drupal.org/node/1987810.
if (Drupal::service('system.manager')->checkRequirements() && user_access('administer site configuration')) {
drupal_set_message(t('One or more problems were detected with your Drupal installation. Check the <a href="@status">status report</a> for more information.', array('@status' => url('admin/reports/status'))), 'error');
}
$blocks = array();
......@@ -1278,43 +1279,6 @@ function system_modules_uninstall_submit($form, &$form_state) {
}
}
/**
* Menu callback: displays the site status report. Can also be used as a pure check.
*
* @param $check
* If true, only returns a boolean whether there are system status errors.
*/
function system_status($check = FALSE) {
// Load .install files
include_once DRUPAL_ROOT . '/core/includes/install.inc';
drupal_load_updates();
// Check run-time requirements and status information.
$requirements = module_invoke_all('requirements', 'runtime');
usort($requirements, '_system_sort_requirements');
if ($check) {
return drupal_requirements_severity($requirements) == REQUIREMENT_ERROR;
}
// MySQL import might have set the uid of the anonymous user to autoincrement
// value. Let's try fixing it. See http://drupal.org/node/204411
db_update('users')
->expression('uid', 'uid - uid')
->condition('name', '')
->condition('pass', '')
->condition('status', 0)
->execute();
return theme('status_report', array('requirements' => $requirements));
}
/**
* Menu callback: return information about PHP.
*/
function system_php() {
phpinfo();
drupal_exit();
}
/**
* Default page callback for batches.
*/
......
......@@ -974,17 +974,7 @@ function system_menu() {
$items['admin/reports/status'] = array(
'title' => 'Status report',
'description' => "Get a status report about your site's operation and any detected problems.",
'page callback' => 'system_status',
'weight' => -60,
'access arguments' => array('administer site configuration'),
'file' => 'system.admin.inc',
);
$items['admin/reports/status/php'] = array(
'title' => 'PHP',
'page callback' => 'system_php',
'access arguments' => array('administer site configuration'),
'type' => MENU_CALLBACK,
'file' => 'system.admin.inc',
'route_name' => 'system_status',
);
// Default page for batch operations.
......@@ -3246,19 +3236,6 @@ function system_config_form_submit($form, &$form_state) {
drupal_set_message(t('The configuration options have been saved.'));
}
/**
* Helper function to sort requirements.
*/
function _system_sort_requirements($a, $b) {
if (!isset($a['weight'])) {
if (!isset($b['weight'])) {
return strcmp($a['title'], $b['title']);
}
return -$b['weight'];
}
return isset($b['weight']) ? $a['weight'] - $b['weight'] : $a['weight'];
}
/**
* Generates a form array for a confirmation form.
*
......
......@@ -122,3 +122,18 @@ system_theme_enable:
_controller: 'Drupal\system\Controller\ThemeController::enable'
requirements:
_permission: 'administer themes'
system_status:
pattern: '/admin/reports/status'
defaults:
_controller: 'Drupal\system\Controller\SystemInfoController::status'
requirements:
_permission: 'administer site configuration'
system_php:
pattern: '/admin/reports/status/php'
defaults:
_controller: 'Drupal\system\Controller\SystemInfoController::php'
requirements:
_permission: 'administer site configuration'
......@@ -6,3 +6,6 @@ services:
plugin.manager.system.plugin_ui:
class: Drupal\system\Plugin\Type\PluginUIManager
arguments: ['@container.namespaces']
system.manager:
class: Drupal\system\SystemManager
arguments: ['@module_handler', '@database']
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment