From f193db251f94e8d54b28712d9dc07a89cfa582df Mon Sep 17 00:00:00 2001 From: Dries <dries@buytaert.net> Date: Sat, 21 Jul 2012 15:16:31 -0400 Subject: [PATCH] =?UTF-8?q?-=20Patch=20#1493098=20by=20sun,=20jcisio,=20pc?= =?UTF-8?q?ambra,=20Pol,=20wamilton,=20Rok=20=C5=BDlender,=20beejeebus:=20?= =?UTF-8?q?convert=20cron=20settings=20to=20configuration=20system.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/includes/install.inc | 16 +++++++-- .../aggregator/Tests/AggregatorCronTest.php | 2 +- .../lib/Drupal/simpletest/WebTestBase.php | 2 +- core/modules/system/config/system.cron.yml | 10 +++--- .../system/Tests/System/CronRunTest.php | 4 +-- core/modules/system/system.admin.inc | 17 +++------- core/modules/system/system.install | 34 +++++-------------- core/modules/system/system.module | 4 +-- 8 files changed, 39 insertions(+), 50 deletions(-) diff --git a/core/includes/install.inc b/core/includes/install.inc index 3f89516a8f1f..1150fce103d4 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -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'); } /** diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorCronTest.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorCronTest.php index a6c29687b305..096693727b92 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorCronTest.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorCronTest.php @@ -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(); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 6b271ba2aa84..b006cdd2022e 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -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')); } /** diff --git a/core/modules/system/config/system.cron.yml b/core/modules/system/config/system.cron.yml index 570b70baa868..4d96e3047f9a 100644 --- a/core/modules/system/config/system.cron.yml +++ b/core/modules/system/config/system.cron.yml @@ -1,5 +1,5 @@ -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' diff --git a/core/modules/system/lib/Drupal/system/Tests/System/CronRunTest.php b/core/modules/system/lib/Drupal/system/Tests/System/CronRunTest.php index 601c5a83eb19..3ac2772d444d 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/CronRunTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/CronRunTest.php @@ -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.')); diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index 45ad10ef4462..7dbd85a96872 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -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.')); } /** diff --git a/core/modules/system/system.install b/core/modules/system/system.install index 656b5b2cac7a..4f9b0172f8e2 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -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', )); } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index a76e3ae35d3c..48a25ec2eb19 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -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(); -- GitLab