Commit daf490d3 authored by Dries's avatar Dries

Issue #1843844 by Crell: Convert cron to new routing system.

parent 62f6333a
<?php
/**
* @file
* Definition of Drupal\system\CronController.
*/
namespace Drupal\system;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/**
* Controllers for Cron handling.
*/
class CronController {
/**
* Run Cron once.
*
* @return Symfony\Component\HttpFoundation\Response
* A Symfony response object.
*/
public function run($key) {
if (!$this->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;
}
}
......@@ -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',
......@@ -1076,41 +1069,6 @@ function system_menu() {
return $items;
}
/**
* 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.
*/
......
cron:
pattern: '/cron/{key}'
defaults:
_controller: '\Drupal\system\CronController::run'
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