Commit f193db25 authored by Dries's avatar Dries

- Patch #1493098 by sun, jcisio, pcambra, Pol, wamilton, Rok Žlender,...

- Patch #1493098 by sun, jcisio, pcambra, Pol, wamilton, Rok Žlender, beejeebus: convert cron settings to configuration system.
parent d074df4c
......@@ -357,10 +357,11 @@ function drupal_verify_profile($install_state) {
* functions can be made available while other modules are installed.
*/
function drupal_install_system() {
// Create tables.
drupal_install_schema('system');
$system_path = drupal_get_path('module', 'system');
require_once DRUPAL_ROOT . '/' . $system_path . '/system.install';
module_invoke('system', 'install');
$system_versions = drupal_get_schema_versions('system');
$system_version = $system_versions ? max($system_versions) : SCHEMA_INSTALLED;
db_insert('system')
......@@ -375,8 +376,19 @@ function drupal_install_system() {
'bootstrap' => 0,
))
->execute();
// Clear out module list and hook implementation statics before calling
// system_rebuild_theme_data().
drupal_static_reset('system_list');
module_list_reset();
module_implements_reset();
system_rebuild_module_data();
system_rebuild_theme_data();
config_install_default_config('system');
module_invoke('system', 'install');
}
/**
......
......@@ -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('cron_key');
$key = config('system.cron')->get('key');
$this->createSampleNodes();
$feed = $this->createFeed();
$this->cronRun();
......
......@@ -1408,7 +1408,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('cron_key'));
$this->drupalGet('cron/' . config('system.cron')->get('key'));
}
/**
......
cron_max_threshold: '10800'
cron_safe_threshold: '10800'
cron_threshold_warning: '172800'
cron_threshold_error: '1209600'
cron_key: drupal
key: ''
threshold:
autorun: '10800'
requirements_warning: '172800'
requirements_error: '1209600'
......@@ -38,7 +38,7 @@ function testCronRun() {
$this->assertResponse(403);
// Run cron anonymously with the valid cron key.
$key = config('system.cron')->get('cron_key');
$key = config('system.cron')->get('key');
$this->drupalGet('cron/' . $key);
$this->assertResponse(204);
}
......@@ -56,7 +56,7 @@ function testAutomaticCron() {
$cron_safe_threshold = 100;
variable_set('cron_last', $cron_last);
config('system.cron')
->set('cron_safe_threshold', $cron_safe_threshold)
->set('threshold.autorun', $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.'));
......
......@@ -1584,7 +1584,6 @@ function system_site_information_settings_submit($form, &$form_state) {
/**
* Form builder; Cron form.
*
* @see system_settings_form()
* @ingroup forms
*/
function system_cron_settings($form, &$form_state) {
......@@ -1596,40 +1595,34 @@ function system_cron_settings($form, &$form_state) {
'#value' => t('Run cron'),
'#submit' => array('system_run_cron_submit'),
);
$status = '<p>' . t('Last run: %cron-last ago.', array('%cron-last' => format_interval(REQUEST_TIME - variable_get('cron_last')),)) . '</p>';
$form['status'] = array(
'#markup' => $status,
);
$form['cron'] = array(
'#type' => 'fieldset',
);
$form['cron']['cron_safe_threshold'] = array(
'#type' => 'select',
'#title' => t('Run cron every'),
'#default_value' => config('system.cron')->get('cron_safe_threshold'),
'#default_value' => config('system.cron')->get('threshold.autorun'),
'#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',
);
$form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
return $form;
return system_config_form($form, $form_state);
}
/**
* 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'])
->set('threshold.autorun', $form_state['values']['cron_safe_threshold'])
->save();
drupal_set_message(t('The configuration options have been saved.'));
}
/**
......
......@@ -263,11 +263,11 @@ function system_requirements($phase) {
// Report cron status.
if ($phase == 'runtime') {
$config = config('system.cron');
$cron_config = config('system.cron');
// Cron warning threshold defaults to two days.
$threshold_warning = $config->get('cron_threshold_warning');
$threshold_warning = $cron_config->get('threshold.requirements_warning');
// Cron error threshold defaults to two weeks.
$threshold_error = $config->get('cron_threshold_error');
$threshold_error = $cron_config->get('threshold.requirements_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'));
......@@ -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/' . $config->get('cron_key'))));
$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'))));
$requirements['cron'] = array(
'title' => $t('Cron maintenance tasks'),
......@@ -506,21 +506,6 @@ function system_requirements($phase) {
* Implements hook_install().
*/
function system_install() {
// Create tables.
drupal_install_schema('system');
$versions = drupal_get_schema_versions('system');
$version = $versions ? max($versions) : SCHEMA_INSTALLED;
drupal_set_installed_schema_version('system', $version);
// Clear out module list and hook implementation statics before calling
// system_rebuild_theme_data().
drupal_static_reset('system_list');
module_list_reset();
module_implements_reset();
// Load system theme data appropriately.
system_rebuild_theme_data();
// Enable the default theme.
variable_set('theme_default', 'stark');
db_update('system')
......@@ -532,7 +517,7 @@ function system_install() {
// Populate the cron key variable.
$cron_key = drupal_hash_base64(drupal_random_bytes(55));
config('system.cron')
->set('cron_key', $cron_key)
->set('key', $cron_key)
->save();
}
......@@ -1918,11 +1903,10 @@ function system_update_8008() {
*/
function system_update_8009() {
update_variables_to_config('system.cron', array(
'cron_max_threshold' => 'cron_max_threshold',
'cron_safe_threshold' => 'cron_safe_threshold',
'cron_threshold_warning' => 'cron_threshold_warning',
'cron_threshold_error' => 'cron_threshold_error',
'cron_key' => 'cron_key',
'cron_key' => 'key',
'cron_safe_threshold' => 'threshold.autorun',
'cron_threshold_warning' => 'threshold.requirements_warning',
'cron_threshold_error' => 'threshold.requirements_error',
));
}
......
......@@ -1178,7 +1178,7 @@ function system_cron_page() {
* @see system_cron_page().
*/
function system_cron_access($key) {
if ($key != config('system.cron')->get('cron_key')) {
if ($key != config('system.cron')->get('key')) {
watchdog('cron', 'Cron could not run because an invalid key was used.', array(), WATCHDOG_NOTICE);
return FALSE;
}
......@@ -3790,7 +3790,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 = config('system.cron')->get('cron_safe_threshold')) > 0 && variable_get('install_task') == 'done') {
if (($threshold = config('system.cron')->get('threshold.autorun')) > 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();
......
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