diff --git a/core/modules/system/lib/Drupal/system/CronController.php b/core/modules/system/lib/Drupal/system/CronController.php new file mode 100644 index 0000000..292d242 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/CronController.php @@ -0,0 +1,55 @@ +access($key)) { + throw new AccessDeniedHttpException(); + } + + // @todo Make this an injected object. + drupal_cron_run(); + + // HTTP 204 is "No content", meaning "I did what you asked and we're done." + return new Response('', 204); + } + + /** + * Determines if the user has access to run cron. + * + * @todo Eliminate this method in favor of a new-style access checker once + * http://drupal.org/node/1793520 gets in. + */ + function access($key) { + if ($key != state()->get('system.cron_key')) { + watchdog('cron', 'Cron could not run because an invalid key was used.', array(), WATCHDOG_NOTICE); + return FALSE; + } + elseif (config('system.maintenance')->get('enabled')) { + watchdog('cron', 'Cron could not run because the site is in maintenance mode.', array(), WATCHDOG_NOTICE); + return FALSE; + } + + return TRUE; + } + +} diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 6401361..5258008 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -564,13 +564,6 @@ function system_element_info() { * Implements hook_menu(). */ function system_menu() { - $items['cron/%'] = array( - 'title' => 'Run cron', - 'page callback' => 'system_cron_page', - 'access callback' => 'system_cron_access', - 'access arguments' => array(1), - 'type' => MENU_CALLBACK, - ); $items['system/files'] = array( 'title' => 'File download', 'page callback' => 'file_download', @@ -1077,41 +1070,6 @@ function system_menu() { } /** - * Page callback; Execute cron tasks. - * - * @see system_cron_access(). - */ - -function system_cron_page() { - drupal_page_is_cacheable(FALSE); - drupal_cron_run(); - - // HTTP 204 is "No content", meaning "I did what you asked and we're done." - return new Response('', 204); -} - -/** - * Access callback for system_cron(). - * - * @param string $key - * A hash to validate the page request origin. - * - * @see system_cron_page(). - */ -function system_cron_access($key) { - if ($key != state()->get('system.cron_key')) { - watchdog('cron', 'Cron could not run because an invalid key was used.', array(), WATCHDOG_NOTICE); - return FALSE; - } - elseif (config('system.maintenance')->get('enabled')) { - watchdog('cron', 'Cron could not run because the site is in maintenance mode.', array(), WATCHDOG_NOTICE); - return FALSE; - } - - return TRUE; -} - -/** * Theme callback for the default batch page. */ function _system_batch_theme() { diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml new file mode 100644 index 0000000..85e0517 --- /dev/null +++ b/core/modules/system/system.routing.yml @@ -0,0 +1,4 @@ +cron: + pattern: '/cron/{key}' + defaults: + _controller: '\Drupal\system\CronController::run'