Issue #1493098 by jcisio, pcambra, Pol, wamilton, Rok Žlender, beejeebus: Convert cron settings to configuration system.
parent
74c409f134
commit
747e01ca53
|
@ -800,7 +800,7 @@ class AggregatorCronTestCase extends AggregatorTestCase {
|
|||
public function testCron() {
|
||||
// Create feed and test basic updating on cron.
|
||||
global $base_url;
|
||||
$key = variable_get('cron_key', 'drupal');
|
||||
$key = config('system.cron')->get('cron_key');
|
||||
$this->createSampleNodes();
|
||||
$feed = $this->createFeed();
|
||||
$this->cronRun();
|
||||
|
|
|
@ -1503,7 +1503,7 @@ abstract class WebTestBase extends TestBase {
|
|||
* Runs cron in the Drupal installed by Simpletest.
|
||||
*/
|
||||
protected function cronRun() {
|
||||
$this->drupalGet('cron/' . variable_get('cron_key', 'drupal'));
|
||||
$this->drupalGet('cron/' . config('system.cron')->get('cron_key'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0"?>
|
||||
<config>
|
||||
<cron_max_threshold>10800</cron_max_threshold>
|
||||
<cron_safe_threshold>10800</cron_safe_threshold>
|
||||
<cron_threshold_warning>172800</cron_threshold_warning>
|
||||
<cron_threshold_error>1209600</cron_threshold_error>
|
||||
<cron_key>drupal</cron_key>
|
||||
</config>
|
|
@ -1570,7 +1570,7 @@ function system_site_information_settings_validate($form, &$form_state) {
|
|||
* @see system_settings_form()
|
||||
* @ingroup forms
|
||||
*/
|
||||
function system_cron_settings() {
|
||||
function system_cron_settings($form, &$form_state) {
|
||||
$form['description'] = array(
|
||||
'#markup' => '<p>' . t('Cron takes care of running periodic tasks like checking for updates and indexing content for search.') . '</p>',
|
||||
);
|
||||
|
@ -1589,11 +1589,30 @@ function system_cron_settings() {
|
|||
$form['cron']['cron_safe_threshold'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Run cron every'),
|
||||
'#default_value' => variable_get('cron_safe_threshold', DRUPAL_CRON_DEFAULT_THRESHOLD),
|
||||
'#default_value' => config('system.cron')->get('cron_safe_threshold'),
|
||||
'#options' => array(0 => t('Never')) + drupal_map_assoc(array(3600, 10800, 21600, 43200, 86400, 604800), 'format_interval'),
|
||||
);
|
||||
// @todo This needs to be reviewed when #1324618 gets in.
|
||||
$form_state['config']['cron_safe_threshold'] = array(
|
||||
'name' => 'system.cron',
|
||||
'path' => 'cron_safe_threshold',
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
$form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form builder submit handler; Handle submission for cron settings.
|
||||
*
|
||||
* @ingroup forms
|
||||
* @see system_settings_form()
|
||||
*/
|
||||
function system_cron_settings_submit($form, &$form_state) {
|
||||
config('system.cron')
|
||||
->set('cron_safe_threshold', $form_state['values']['cron_safe_threshold'])
|
||||
->save();
|
||||
drupal_set_message(t('The configuration options have been saved.'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -253,10 +253,11 @@ function system_requirements($phase) {
|
|||
|
||||
// Report cron status.
|
||||
if ($phase == 'runtime') {
|
||||
$config = config('system.cron');
|
||||
// Cron warning threshold defaults to two days.
|
||||
$threshold_warning = variable_get('cron_threshold_warning', 172800);
|
||||
$threshold_warning = $config->get('cron_threshold_warning');
|
||||
// Cron error threshold defaults to two weeks.
|
||||
$threshold_error = variable_get('cron_threshold_error', 1209600);
|
||||
$threshold_error = $config->get('cron_threshold_error');
|
||||
// Cron configuration help text.
|
||||
$help = $t('For more information, see the online handbook entry for <a href="@cron-handbook">configuring cron jobs</a>.', array('@cron-handbook' => 'http://drupal.org/cron'));
|
||||
|
||||
|
@ -283,7 +284,7 @@ function system_requirements($phase) {
|
|||
}
|
||||
|
||||
$description .= ' ' . $t('You can <a href="@cron">run cron manually</a>.', array('@cron' => url('admin/reports/status/run-cron')));
|
||||
$description .= '<br />' . $t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url('cron/' . variable_get('cron_key', 'drupal'))));
|
||||
$description .= '<br />' . $t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url('cron/' . $config->get('cron_key'))));
|
||||
|
||||
$requirements['cron'] = array(
|
||||
'title' => $t('Cron maintenance tasks'),
|
||||
|
@ -515,7 +516,9 @@ function system_install() {
|
|||
|
||||
// Populate the cron key variable.
|
||||
$cron_key = drupal_hash_base64(drupal_random_bytes(55));
|
||||
variable_set('cron_key', $cron_key);
|
||||
config('system.cron')
|
||||
->set('cron_key', $cron_key)
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1855,6 +1858,13 @@ function system_update_8008() {
|
|||
variable_del('clean_url');
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves cron system settings from variable to config.
|
||||
*/
|
||||
function system_update_8009() {
|
||||
update_variables_to_config('system.cron');
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "defgroup updates-7.x-to-8.x"
|
||||
* The next series of updates should start at 9000.
|
||||
|
|
|
@ -10,11 +10,6 @@
|
|||
*/
|
||||
const DRUPAL_MAXIMUM_TEMP_FILE_AGE = 21600;
|
||||
|
||||
/**
|
||||
* Default interval for automatic cron executions in seconds.
|
||||
*/
|
||||
const DRUPAL_CRON_DEFAULT_THRESHOLD = 10800;
|
||||
|
||||
/**
|
||||
* New users will be set to the default time zone at registration.
|
||||
*/
|
||||
|
@ -1135,7 +1130,7 @@ function system_cron_page() {
|
|||
* @see system_cron_page().
|
||||
*/
|
||||
function system_cron_access($key) {
|
||||
if ($key != variable_get('cron_key', 'drupal')) {
|
||||
if ($key != config('system.cron')->get('cron_key')) {
|
||||
watchdog('cron', 'Cron could not run because an invalid key was used.', array(), WATCHDOG_NOTICE);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -3559,7 +3554,7 @@ function system_run_automated_cron() {
|
|||
// If the site is not fully installed, suppress the automated cron run.
|
||||
// Otherwise it could be triggered prematurely by Ajax requests during
|
||||
// installation.
|
||||
if (($threshold = variable_get('cron_safe_threshold', DRUPAL_CRON_DEFAULT_THRESHOLD)) > 0 && variable_get('install_task') == 'done') {
|
||||
if (($threshold = config('system.cron')->get('cron_safe_threshold')) > 0 && variable_get('install_task') == 'done') {
|
||||
$cron_last = variable_get('cron_last', NULL);
|
||||
if (!isset($cron_last) || (REQUEST_TIME - $cron_last > $threshold)) {
|
||||
drupal_cron_run();
|
||||
|
|
|
@ -819,7 +819,7 @@ class CronRunTestCase extends WebTestBase {
|
|||
$this->assertResponse(403);
|
||||
|
||||
// Run cron anonymously with the valid cron key.
|
||||
$key = variable_get('cron_key', 'drupal');
|
||||
$key = config('system.cron')->get('cron_key');
|
||||
$this->drupalGet('cron/' . $key);
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
@ -836,7 +836,9 @@ class CronRunTestCase extends WebTestBase {
|
|||
$cron_last = time();
|
||||
$cron_safe_threshold = 100;
|
||||
variable_set('cron_last', $cron_last);
|
||||
variable_set('cron_safe_threshold', $cron_safe_threshold);
|
||||
config('system.cron')
|
||||
->set('cron_safe_threshold', $cron_safe_threshold)
|
||||
->save();
|
||||
$this->drupalGet('');
|
||||
$this->assertTrue($cron_last == variable_get('cron_last', NULL), t('Cron does not run when the cron threshold is not passed.'));
|
||||
|
||||
|
|
Loading…
Reference in New Issue