diff --git a/core/modules/system/lib/Drupal/system/Controller/SystemInfoController.php b/core/modules/system/lib/Drupal/system/Controller/SystemInfoController.php new file mode 100644 index 0000000..0f7cba1 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Controller/SystemInfoController.php @@ -0,0 +1,72 @@ +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); + } + +} diff --git a/core/modules/system/lib/Drupal/system/SystemManager.php b/core/modules/system/lib/Drupal/system/SystemManager.php new file mode 100644 index 0000000..00714b2 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/SystemManager.php @@ -0,0 +1,125 @@ +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) == 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; + } + + /** + * 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 = REQUIREMENT_OK; + foreach ($requirements as $requirement) { + if (isset($requirement['severity'])) { + $severity = max($severity, $requirement['severity']); + } + } + return $severity; + } + +} diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index a44060e..066c27b 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -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 status report for more information.', array('@status' => url('admin/reports/status'))), 'error'); } $blocks = array(); @@ -1279,35 +1280,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: run cron manually. */ function system_run_cron() { @@ -1323,14 +1295,6 @@ function system_run_cron() { } /** - * Menu callback: return information about PHP. - */ -function system_php() { - phpinfo(); - drupal_exit(); -} - -/** * Default page callback for batches. */ function system_batch_page() { diff --git a/core/modules/system/system.module b/core/modules/system/system.module index b6d37f0..c645bd5 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -978,10 +978,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', + 'route_name' => 'system_status', ); $items['admin/reports/status/run-cron'] = array( 'title' => 'Run cron', @@ -990,13 +987,6 @@ function system_menu() { 'type' => MENU_CALLBACK, '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', - ); // Default page for batch operations. $items['batch'] = array( @@ -3287,19 +3277,6 @@ function system_config_form_submit($form, &$form_state) { } /** - * 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. * * This function returns a complete form array for confirming an action. The diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml index 1b4c9a9..eac92a2 100644 --- a/core/modules/system/system.routing.yml +++ b/core/modules/system/system.routing.yml @@ -101,3 +101,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' + diff --git a/core/modules/system/system.services.yml b/core/modules/system/system.services.yml index c049b0a..8f0d232 100644 --- a/core/modules/system/system.services.yml +++ b/core/modules/system/system.services.yml @@ -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']