Commit 0e9bf2e0 authored by catch's avatar catch

Issue #1821530 by LinL, alexpott: Move cron key from configuration to state system.

parent 9c79f870
......@@ -22,7 +22,7 @@ public static function getInfo() {
public function testCron() {
// Create feed and test basic updating on cron.
global $base_url;
$key = config('system.cron')->get('key');
$key = state()->get('system.cron_key');
$this->createSampleNodes();
$feed = $this->createFeed();
$this->cronRun();
......
......@@ -1436,7 +1436,7 @@ protected function drupalPostAJAX($path, $edit, $triggering_element, $ajax_path
* Runs cron in the Drupal installed by Simpletest.
*/
protected function cronRun() {
$this->drupalGet('cron/' . config('system.cron')->get('key'));
$this->drupalGet('cron/' . state()->get('system.cron_key'));
}
/**
......
key: ''
threshold:
autorun: '10800'
requirements_warning: '172800'
......
......@@ -42,7 +42,7 @@ function testCronRun() {
$this->assertResponse(403);
// Run cron anonymously with the valid cron key.
$key = config('system.cron')->get('key');
$key = state()->get('system.cron_key');
$this->drupalGet('cron/' . $key);
$this->assertResponse(204);
}
......
......@@ -47,6 +47,10 @@ public function testSystemVariableUpgrade() {
'value' => 1304208002,
'variable_name' => 'cron_last',
);
$expected_state['system.cron_key'] = array(
'value' => 'kdm95qppDDlyZrcUOx453YwQqDA4DNmxi4VQcxzFU9M',
'variable_name' => 'cron_key',
);
$expected_state['update.last_check'] = array(
'value' => 1304208000,
'variable_name' => 'update_last_check',
......
......@@ -35,7 +35,6 @@ public function testVariableUpgrade() {
// Verify that variables were properly upgraded.
$expected_config['system.cron'] = array(
'key' => 'kdm95qppDDlyZrcUOx453YwQqDA4DNmxi4VQcxzFU9M',
'threshold.autorun' => '86400',
'threshold.requirements_warning' => '86400',
'threshold.requirements_error' => '172800',
......
......@@ -294,7 +294,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/' . $cron_config->get('key'))));
$description .= '<br />' . $t('To run cron from outside the site, go to <a href="!cron">!cron</a>', array('!cron' => url('cron/' . state()->get('system.cron_key'))));
$requirements['cron'] = array(
'title' => $t('Cron maintenance tasks'),
......@@ -512,11 +512,9 @@ function system_install() {
variable_set('theme_default', 'stark');
config_install_default_config('theme', 'stark');
// Populate the cron key variable.
// Populate the cron key state variable.
$cron_key = drupal_hash_base64(drupal_random_bytes(55));
config('system.cron')
->set('key', $cron_key)
->save();
state()->set('system.cron_key', $cron_key);
}
/**
......@@ -1756,7 +1754,6 @@ function system_update_8008() {
*/
function system_update_8009() {
update_variables_to_config('system.cron', array(
'cron_key' => 'key',
'cron_safe_threshold' => 'threshold.autorun',
'cron_threshold_warning' => 'threshold.requirements_warning',
'cron_threshold_error' => 'threshold.requirements_error',
......@@ -2200,12 +2197,15 @@ function system_update_8033() {
}
/**
* Moves cron last run time from variable to state.
* Moves cron last run time and cron key from variable to state.
*
* @ingroup config_upgrade
*/
function system_update_8034() {
update_variables_to_state(array('cron_last' => 'system.cron_last'));
update_variables_to_state(array(
'cron_last' => 'system.cron_last',
'cron_key' => 'system.cron_key',
));
}
/**
......
......@@ -1101,7 +1101,7 @@ function system_cron_page() {
* @see system_cron_page().
*/
function system_cron_access($key) {
if ($key != config('system.cron')->get('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;
}
......
......@@ -31,3 +31,7 @@
->key(array('name' => 'cron_last'))
->fields(array('value' => serialize(1304208002)))
->execute();
db_merge('variable')
->key(array('name' => 'cron_key'))
->fields(array('value' => serialize('kdm95qppDDlyZrcUOx453YwQqDA4DNmxi4VQcxzFU9M')))
->execute();
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