From 2c381622a5bd3ab5b22077348a088bb54ca202dc Mon Sep 17 00:00:00 2001 From: Angie Byron <webchick@24967.no-reply.drupal.org> Date: Sat, 31 Jan 2009 16:50:57 +0000 Subject: [PATCH] #88264 by Rob Loach and kscheirer: Make variable_get()'s defaultparameter default to NULL so that NULLs do not need to be specified. --- includes/bootstrap.inc | 4 ++-- includes/file.inc | 2 +- modules/color/color.module | 4 ++-- modules/locale/locale.install | 2 +- modules/simpletest/tests/bootstrap.test | 13 ++++++++++++- modules/system/system.api.php | 2 +- modules/system/system.install | 10 +++++----- modules/user/user.test | 2 +- 8 files changed, 25 insertions(+), 14 deletions(-) diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index ba27a5f7cd85..a84257341ca4 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -631,7 +631,7 @@ function variable_init($conf = array()) { * @return * The value of the variable. */ -function variable_get($name, $default) { +function variable_get($name, $default = NULL) { global $conf; return isset($conf[$name]) ? $conf[$name] : $default; @@ -1046,7 +1046,7 @@ function drupal_is_denied($ip) { // Because this function is called on every page request, we first check // for an array of IP addresses in settings.php before querying the // database. - $blocked_ips = variable_get('blocked_ips', NULL); + $blocked_ips = variable_get('blocked_ips'); if (isset($blocked_ips) && is_array($blocked_ips)) { return in_array($ip, $blocked_ips); } diff --git a/includes/file.inc b/includes/file.inc index 38c4999ff1b0..05318add6db1 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -1407,7 +1407,7 @@ function file_scan_directory($dir, $mask, $nomask = '/(\.\.?|CVS)$/', $callback * A string containing a temp directory. */ function file_directory_temp() { - $temporary_directory = variable_get('file_directory_temp', NULL); + $temporary_directory = variable_get('file_directory_temp'); if (is_null($temporary_directory)) { $directories = array(); diff --git a/modules/color/color.module b/modules/color/color.module index fa53f45f7768..d64a64b64cc2 100644 --- a/modules/color/color.module +++ b/modules/color/color.module @@ -72,7 +72,7 @@ function _color_theme_select_form_alter(&$form, &$form_state) { // Use the generated screenshot in the theme list. $themes = list_themes(); foreach (element_children($form) as $theme) { - if ($screenshot = variable_get('color_' . $theme . '_screenshot', NULL)) { + if ($screenshot = variable_get('color_' . $theme . '_screenshot')) { if (isset($form[$theme]['screenshot'])) { $form[$theme]['screenshot']['#markup'] = theme('image', $screenshot, '', '', array('class' => 'screenshot'), FALSE); } @@ -127,7 +127,7 @@ function _color_page_alter(&$vars) { } // Override logo. - $logo = variable_get('color_' . $theme_key . '_logo', NULL); + $logo = variable_get('color_' . $theme_key . '_logo'); if ($logo && $vars['logo'] && preg_match('!' . $theme_key . '/logo.png$!', $vars['logo'])) { $vars['logo'] = base_path() . $logo; } diff --git a/modules/locale/locale.install b/modules/locale/locale.install index de8f6fe98c69..044ab62d34ca 100644 --- a/modules/locale/locale.install +++ b/modules/locale/locale.install @@ -172,7 +172,7 @@ function locale_update_6004() { function locale_update_6005() { foreach (node_get_types() as $type => $content_type) { // Default to NULL, so we can skip dealing with non-existent settings. - $setting = variable_get('language_' . $type, NULL); + $setting = variable_get('language_' . $type); if ($type == 'default' && is_numeric($setting)) { // language_default was overwritten with the content type setting, // so reset the default language and save the content type setting. diff --git a/modules/simpletest/tests/bootstrap.test b/modules/simpletest/tests/bootstrap.test index 149c5ef49353..3cacf11751bf 100644 --- a/modules/simpletest/tests/bootstrap.test +++ b/modules/simpletest/tests/bootstrap.test @@ -151,7 +151,7 @@ class BootstrapVariableTestCase extends DrupalWebTestCase { // Setting and retrieving values. $variable = $this->randomName(); variable_set('simpletest_bootstrap_variable_test', $variable); - $this->assertIdentical($variable, variable_get('simpletest_bootstrap_variable_test', NULL), t('Setting and retrieving values')); + $this->assertIdentical($variable, variable_get('simpletest_bootstrap_variable_test'), t('Setting and retrieving values')); // Make sure the variable persists across multiple requests. $this->drupalGet('system-test/variable-get'); @@ -164,6 +164,17 @@ class BootstrapVariableTestCase extends DrupalWebTestCase { $this->assertIdentical($variable, $default_value, t('Deleting variables')); } + /** + * Makes sure that the default variable parameter is passed through okay. + */ + function testVariableDefaults() { + // Tests passing nothing through to the default. + $this->assertIdentical(NULL, variable_get('simpletest_bootstrap_variable_test'), t('Variables are correctly defaulting to NULL.')); + + // Tests passing 5 to the default parameter. + $this->assertIdentical(5, variable_get('simpletest_bootstrap_variable_test', 5), t('The default variable parameter is passed through correctly.')); + } + } /** diff --git a/modules/system/system.api.php b/modules/system/system.api.php index 9fc2457fb79d..7e5e2e7e7164 100644 --- a/modules/system/system.api.php +++ b/modules/system/system.api.php @@ -1322,7 +1322,7 @@ function hook_requirements($phase) { // Report cron status if ($phase == 'runtime') { - $cron_last = variable_get('cron_last', NULL); + $cron_last = variable_get('cron_last'); if (is_numeric($cron_last)) { $requirements['cron']['value'] = $t('Last run !time ago', array('!time' => format_interval(REQUEST_TIME - $cron_last))); diff --git a/modules/system/system.install b/modules/system/system.install index 1849f88adf08..7b8f1e144554 100644 --- a/modules/system/system.install +++ b/modules/system/system.install @@ -134,7 +134,7 @@ function system_requirements($phase) { $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')); // Determine when cron last ran. - $cron_last = variable_get('cron_last', NULL); + $cron_last = variable_get('cron_last'); if (!is_numeric($cron_last)) { $cron_last = variable_get('install_time', 0); } @@ -2491,7 +2491,7 @@ function system_update_6041() { */ function system_update_6042() { foreach (list_themes() as $theme) { - $stylesheet = variable_get('color_' . $theme->name . '_stylesheet', NULL); + $stylesheet = variable_get('color_' . $theme->name . '_stylesheet'); if (!empty($stylesheet)) { variable_set('color_' . $theme->name . '_stylesheets', array($stylesheet)); variable_del('color_' . $theme->name . '_stylesheet'); @@ -2853,12 +2853,12 @@ function system_update_7004(&$sandbox) { } } // Rename forum module's block variables. - $forum_block_num_0 = variable_get('forum_block_num_0', NULL); + $forum_block_num_0 = variable_get('forum_block_num_0'); if (isset($forum_block_num_0)) { variable_set('forum_block_num_active', $forum_block_num_0); variable_del('forum_block_num_0'); } - $forum_block_num_1 = variable_get('forum_block_num_1', NULL); + $forum_block_num_1 = variable_get('forum_block_num_1'); if (isset($forum_block_num_1)) { variable_set('forum_block_num_new', $forum_block_num_1); variable_del('forum_block_num_1'); @@ -3090,7 +3090,7 @@ function system_update_7013() { $timezones = system_time_zones(); // If the contributed Date module set a default time zone name, use this // setting as the default time zone. - if (($timezone_name = variable_get('date_default_timezone_name', NULL)) && isset($timezones[$timezone_name])) { + if (($timezone_name = variable_get('date_default_timezone_name')) && isset($timezones[$timezone_name])) { $timezone = $timezone_name; } // If the contributed Event module has set a default site time zone, look up diff --git a/modules/user/user.test b/modules/user/user.test index 22dea39b18cf..327068f5bf21 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -42,7 +42,7 @@ class UserRegistrationTestCase extends DrupalWebTestCase { $this->assertEqual($user->signature, '', t('Correct signature field.')); $this->assertTrue(($user->created > REQUEST_TIME - 20 ), t('Correct creation time.')); $this->assertEqual($user->status, variable_get('user_register', 1) == 1 ? 1 : 0, t('Correct status field.')); - $this->assertEqual($user->timezone, variable_get('date_default_timezone', NULL), t('Correct time zone field.')); + $this->assertEqual($user->timezone, variable_get('date_default_timezone'), t('Correct time zone field.')); $this->assertEqual($user->language, '', t('Correct language field.')); $this->assertEqual($user->picture, '', t('Correct picture field.')); $this->assertEqual($user->init, $mail, t('Correct init field.')); -- GitLab