summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/bootstrap.inc95
-rw-r--r--includes/install.inc3
-rw-r--r--includes/locale.inc18
-rw-r--r--install.php6
-rw-r--r--modules/forum/forum.test6
-rw-r--r--modules/simpletest/tests/bootstrap.test16
-rw-r--r--modules/taxonomy/taxonomy.module106
-rw-r--r--modules/taxonomy/taxonomy.test33
-rw-r--r--modules/translation/translation.test4
9 files changed, 177 insertions, 110 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 3a18ec71b..2db38365a 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -360,7 +360,7 @@ function timer_stop($name) {
* The path of the matching directory.
*/
function conf_path($require_settings = TRUE, $reset = FALSE) {
- static $conf = '';
+ $conf = &drupal_static(__FUNCTION__, '');
if ($conf && !$reset) {
return $conf;
@@ -558,7 +558,7 @@ function conf_init() {
* The filename of the requested item.
*/
function drupal_get_filename($type, $name, $filename = NULL) {
- static $files = array();
+ $files = &drupal_static(__FUNCTION__, array());
if (!isset($files[$type])) {
$files[$type] = array();
@@ -727,7 +727,7 @@ function page_get_cache($retrieve) {
* TRUE if the item is loaded or has already been loaded.
*/
function drupal_load($type, $name) {
- static $files = array();
+ $files = &drupal_static(__FUNCTION__, array());
if (isset($files[$type][$name])) {
return TRUE;
@@ -1093,7 +1093,19 @@ function drupal_anonymous_user($session = '') {
* DRUPAL_BOOTSTRAP_FULL: Drupal is fully loaded, validate and fix input data.
*/
function drupal_bootstrap($phase = NULL) {
- static $phases = array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_VARIABLES, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_LANGUAGE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL), $completed_phase = -1;
+ $phases = &drupal_static(__FUNCTION__ . '_phases', array(
+ DRUPAL_BOOTSTRAP_CONFIGURATION,
+ DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE,
+ DRUPAL_BOOTSTRAP_DATABASE,
+ DRUPAL_BOOTSTRAP_ACCESS,
+ DRUPAL_BOOTSTRAP_SESSION,
+ DRUPAL_BOOTSTRAP_VARIABLES,
+ DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE,
+ DRUPAL_BOOTSTRAP_LANGUAGE,
+ DRUPAL_BOOTSTRAP_PATH,
+ DRUPAL_BOOTSTRAP_FULL,
+ ));
+ $completed_phase = &drupal_static(__FUNCTION__ . '_completed_phase', -1);
if (isset($phase)) {
while ($phases && $phase > $completed_phase) {
@@ -1251,7 +1263,9 @@ function drupal_maintenance_theme() {
*/
function get_t() {
static $t;
- if (is_null($t)) {
+ // This is not converted to drupal_static because there is no point in
+ // resetting this as it can not change in the course of a request.
+ if (!isset($t)) {
$t = function_exists('install_main') ? 'st' : 't';
}
return $t;
@@ -1278,16 +1292,9 @@ function drupal_init_language() {
* Get a list of languages set up indexed by the specified key
*
* @param $field The field to index the list with.
- * @param $reset Boolean to request a reset of the list.
*/
-function language_list($field = 'language', $reset = FALSE) {
- static $languages = NULL;
-
- // Reset language list
- if ($reset) {
- $languages = NULL;
- }
-
+function language_list($field = 'language') {
+ $languages = &drupal_static(__FUNCTION__);
// Init language list
if (!isset($languages)) {
if (variable_get('language_count', 1) > 1 || module_exists('locale')) {
@@ -1333,16 +1340,14 @@ function language_default($property = NULL) {
* the proxy server, and not the client's. If Drupal is run in a cluster
* we use the X-Cluster-Client-Ip header instead.
*
- * @param $reset
- * Reset the current IP address saved in static.
* @return
* IP address of client machine, adjusted for reverse proxy and/or cluster
* environments.
*/
-function ip_address($reset = FALSE) {
- static $ip_address = NULL;
+function ip_address() {
+ $ip_address = &drupal_static(__FUNCTION__);
- if (!isset($ip_address) || $reset) {
+ if (!isset($ip_address)) {
$ip_address = $_SERVER['REMOTE_ADDR'];
if (variable_get('reverse_proxy', 0)) {
@@ -1616,3 +1621,55 @@ function registry_rebuild() {
/**
* @} End of "ingroup registry".
*/
+
+/**
+ * Central static variable storage.
+ *
+ * @param $name
+ * Globally unique name for the variable. For a function with only one static,
+ * variable, the function name (e.g. via the PHP magic __FUNCTION__ constant)
+ * is recommended. For a function with multiple static variables add a
+ * distinguishing suffix to the function name for each one.
+ * @param $default_value
+ * Optional default value.
+ * @param $reset
+ * TRUE to reset a specific named variable, or all variables if $name is NULL.
+ * Resetting every variable should only be used, for example, for running
+ * unit tests with a clean environment. Should be used only though via
+ * function drupal_static_reset().
+ *
+ * @return
+ * Returns a variable by reference if $reset is FALSE.
+ */
+function &drupal_static($name, $default_value = NULL, $reset = FALSE) {
+ static $data = array();
+
+ // Reset a single value, or all values.
+ if ($reset) {
+ if (isset($name)) {
+ unset($data[$name]);
+ }
+ else {
+ $data = array();
+ }
+ // We must return a reference to a variable.
+ $dummy = NULL;
+ return $dummy;
+ }
+
+ if (!isset($data[$name])) {
+ $data[$name] = $default_value;
+ }
+
+ return $data[$name];
+}
+
+/**
+ * Reset one or all centrally stored static variable(s).
+ *
+ * @param $name
+ * Name of the static variable to reset. Omit to reset all variables.
+ */
+function drupal_static_reset($name = NULL) {
+ drupal_static($name, NULL, TRUE);
+}
diff --git a/includes/install.inc b/includes/install.inc
index 6eaf8db2c..7cd4c7038 100644
--- a/includes/install.inc
+++ b/includes/install.inc
@@ -335,7 +335,8 @@ abstract class DatabaseInstaller {
*/
function drupal_rewrite_settings($settings = array(), $prefix = '') {
$default_settings = 'sites/default/default.settings.php';
- $settings_file = conf_path(FALSE, TRUE) . '/' . $prefix . 'settings.php';
+ drupal_static_reset('conf_path');
+ $settings_file = conf_path(FALSE) . '/' . $prefix . 'settings.php';
// Build list of setting names and insert the values into the global namespace.
$keys = array();
diff --git a/includes/locale.inc b/includes/locale.inc
index 5f8fbac25..4d2ada42a 100644
--- a/includes/locale.inc
+++ b/includes/locale.inc
@@ -32,7 +32,8 @@ define('LOCALE_IMPORT_KEEP', 1);
* User interface for the language overview screen.
*/
function locale_languages_overview_form() {
- $languages = language_list('language', TRUE);
+ drupal_static_reset('language');
+ $languages = language_list('language');
$options = array();
$form['weight'] = array('#tree' => TRUE);
@@ -515,7 +516,8 @@ function locale_languages_configure_form_submit($form, &$form_state) {
* Overview screen for translations.
*/
function locale_translate_overview_screen() {
- $languages = language_list('language', TRUE);
+ drupal_static_reset('language_list');
+ $languages = language_list('language');
$groups = module_invoke_all('locale', 'groups');
// Build headers with all groups in order.
@@ -577,7 +579,8 @@ function locale_translation_filters() {
$filters = array();
// Get all languages, except English
- $languages = locale_language_list('name', TRUE);
+ drupal_static_reset('language_list');
+ $languages = locale_language_list('name');
unset($languages['en']);
$filters['string'] = array(
@@ -699,7 +702,8 @@ function locale_translation_filter_form_submit($form, &$form_state) {
*/
function locale_translate_import_form() {
// Get all languages, except English
- $names = locale_language_list('name', TRUE);
+ drupal_static_reset('language_list');
+ $names = locale_language_list('name');
unset($names['en']);
if (!count($names)) {
@@ -757,7 +761,8 @@ function locale_translate_import_form_submit($form, &$form_state) {
if ($file = file_save_upload('file')) {
// Add language, if not yet supported
- $languages = language_list('language', TRUE);
+ drupal_static_reset('language_list');
+ $languages = language_list('language');
$langcode = $form_state['values']['langcode'];
if (!isset($languages[$langcode])) {
include_once DRUPAL_ROOT . '/includes/iso.inc';
@@ -796,7 +801,8 @@ function locale_translate_import_form_submit($form, &$form_state) {
*/
function locale_translate_export_screen() {
// Get all languages, except English
- $names = locale_language_list('name', TRUE);
+ drupal_static_reset('language_list');
+ $names = locale_language_list('name');
unset($names['en']);
$output = '';
// Offer translation export if any language is set up.
diff --git a/install.php b/install.php
index 4065fb06f..f154de33a 100644
--- a/install.php
+++ b/install.php
@@ -185,7 +185,8 @@ function install_verify_settings() {
include_once DRUPAL_ROOT . '/includes/form.inc';
$database = $databases['default']['default'];
- $settings_file = './' . conf_path(FALSE, TRUE) . '/settings.php';
+ drupal_static_reset('conf_path');
+ $settings_file = './' . conf_path(FALSE) . '/settings.php';
$form_state = array();
_install_settings_form_validate($database, $settings_file, $form_state);
@@ -202,7 +203,8 @@ function install_verify_settings() {
function install_change_settings($profile = 'default', $install_locale = '') {
global $databases, $db_prefix;
- $conf_path = './' . conf_path(FALSE, TRUE);
+ drupal_static_reset('conf_path');
+ $conf_path = './' . conf_path(FALSE);
$settings_file = $conf_path . '/settings.php';
$database = isset($databases['default']['default']) ? $databases['default']['default'] : array();
diff --git a/modules/forum/forum.test b/modules/forum/forum.test
index 9dbfa3952..0ed99ad03 100644
--- a/modules/forum/forum.test
+++ b/modules/forum/forum.test
@@ -135,7 +135,8 @@ class ForumTestCase extends DrupalWebTestCase {
$this->assertRaw(t('Updated vocabulary %name.', array('%name' => $title)), t('Vocabulary was edited'));
// Grab the newly edited vocabulary.
- $current_settings = taxonomy_vocabulary_load($vid, TRUE);
+ drupal_static_reset('taxonomy_vocabulary_load_multiple');
+ $current_settings = taxonomy_vocabulary_load($vid);
// Make sure we actually edited the vocabulary properly.
$this->assertEqual($current_settings->name, $title, t('The name was updated'));
@@ -143,7 +144,8 @@ class ForumTestCase extends DrupalWebTestCase {
// Restore the original vocabulary.
taxonomy_vocabulary_save($original_settings);
- $current_settings = taxonomy_vocabulary_load($vid, TRUE);
+ drupal_static_reset('taxonomy_vocabulary_load');
+ $current_settings = taxonomy_vocabulary_load($vid);
$this->assertEqual($current_settings->name, $original_settings->name, 'The original vocabulary settings were restored');
}
diff --git a/modules/simpletest/tests/bootstrap.test b/modules/simpletest/tests/bootstrap.test
index befc5ea53..eedf1a914 100644
--- a/modules/simpletest/tests/bootstrap.test
+++ b/modules/simpletest/tests/bootstrap.test
@@ -20,6 +20,8 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase {
$this->cluster_ip = '127.0.0.4';
$this->untrusted_ip = '0.0.0.0';
+ drupal_static_reset('ip_address');
+
$_SERVER['REMOTE_ADDR'] = $this->remote_ip;
unset($_SERVER['HTTP_X_FORWARDED_FOR']);
unset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']);
@@ -29,6 +31,7 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase {
function tearDown() {
$_SERVER = $this->oldserver;
+ drupal_static_reset('ip_address');
parent::tearDown();
}
@@ -38,37 +41,40 @@ class BootstrapIPAddressTestCase extends DrupalWebTestCase {
function testIPAddressHost() {
// Test the normal IP address.
$this->assertTrue(
- ip_address(true) == $this->remote_ip,
+ ip_address() == $this->remote_ip,
t('Got remote IP address')
);
// Proxy forwarding on but no proxy addresses defined.
variable_set('reverse_proxy', 1);
$this->assertTrue(
- ip_address(true) == $this->remote_ip,
+ ip_address() == $this->remote_ip,
t('Proxy forwarding without trusted proxies got remote IP address')
);
// Proxy forwarding on and proxy address not trusted.
variable_set('reverse_proxy_addresses', array($this->proxy_ip));
+ drupal_static_reset('ip_address');
$_SERVER['REMOTE_ADDR'] = $this->untrusted_ip;
$this->assertTrue(
- ip_address(true) == $this->untrusted_ip,
+ ip_address() == $this->untrusted_ip,
t('Proxy forwarding with untrusted proxy got remote IP address')
);
// Proxy forwarding on and proxy address trusted.
$_SERVER['REMOTE_ADDR'] = $this->proxy_ip;
$_SERVER['HTTP_X_FORWARDED_FOR'] = $this->forwarded_ip;
+ drupal_static_reset('ip_address');
$this->assertTrue(
- ip_address(true) == $this->forwarded_ip,
+ ip_address() == $this->forwarded_ip,
t('Proxy forwarding with trusted proxy got forwarded IP address')
);
// Cluster environment.
$_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] = $this->cluster_ip;
+ drupal_static_reset('ip_address');
$this->assertTrue(
- ip_address(TRUE) == $this->cluster_ip,
+ ip_address() == $this->cluster_ip,
t('Cluster environment got cluster client IP')
);
$this->assertFalse(drupal_valid_http_host('security/.drupal.org:80'), t('HTTP_HOST with / is invalid'));
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index 96823daa9..5215c6cc4 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -227,6 +227,7 @@ function taxonomy_vocabulary_save($vocabulary) {
}
cache_clear_all();
+ drupal_static_reset('taxonomy_vocabulary_load_multiple');
return $status;
}
@@ -252,6 +253,7 @@ function taxonomy_vocabulary_delete($vid) {
module_invoke_all('taxonomy', 'delete', 'vocabulary', $vocabulary);
cache_clear_all();
+ drupal_static_reset('taxonomy_vocabulary_load_multiple');
return SAVED_DELETED;
}
@@ -361,6 +363,7 @@ function taxonomy_term_save($term) {
}
cache_clear_all();
+ taxonomy_terms_static_reset();
return $status;
}
@@ -404,11 +407,23 @@ function taxonomy_term_delete($tid) {
}
cache_clear_all();
-
+ taxonomy_terms_static_reset();
+
return SAVED_DELETED;
}
/**
+ * Clear all static cache variables for terms..
+ */
+function taxonomy_terms_static_reset() {
+ drupal_static_reset('taxonomy_term_count_nodes');
+ drupal_static_reset('taxonomy_get_tree');
+ drupal_static_reset('taxonomy_get_synonym_root');
+ drupal_static_reset('taxonomy_term_load_multiple');
+ drupal_static_reset('taxonomy_get_term_data');
+}
+
+/**
* Generate a form element for selecting terms from a vocabulary.
*/
function taxonomy_form($vid, $value = 0, $help = NULL, $name = 'taxonomy') {
@@ -452,9 +467,9 @@ function taxonomy_form_all($free_tags = 0) {
* @param $type
* If set, return only those vocabularies associated with this node type.
*/
-function taxonomy_get_vocabularies($type = NULL, $reset = FALSE) {
+function taxonomy_get_vocabularies($type = NULL) {
$conditions = !empty($type) ? array('type' => $type) : NULL;
- return taxonomy_vocabulary_load_multiple(array(), $conditions, $reset);
+ return taxonomy_vocabulary_load_multiple(array(), $conditions);
}
/**
@@ -616,7 +631,7 @@ function taxonomy_get_tids_from_nodes($nodes) {
* Find all terms associated with the given node, ordered by vocabulary and term weight.
*/
function taxonomy_node_get_terms($node, $key = 'tid') {
- static $terms;
+ $terms = &drupal_static(__FUNCTION__);
if (!isset($terms[$node->vid][$key])) {
$result = db_query(db_rewrite_sql('SELECT t.* FROM {taxonomy_term_node} r INNER JOIN {taxonomy_term_data} t ON r.tid = t.tid INNER JOIN {taxonomy_vocabulary} v ON t.vid = v.vid WHERE r.vid = %d ORDER BY v.weight, t.weight, t.name', 't', 'tid'), $node->vid);
@@ -701,6 +716,7 @@ function taxonomy_node_type($op, $info) {
elseif ($op == 'delete') {
db_query("DELETE FROM {taxonomy_vocabulary_node_type} WHERE type = '%s'", $info->type);
}
+ drupal_static_reset('taxonomy_term_count_nodes');
}
/**
@@ -780,9 +796,6 @@ function taxonomy_get_children($tid, $vid = 0, $key = 'tid') {
* for the entire vocabulary.
* @param $max_depth
* The number of levels of the tree to return. Leave NULL to return all levels.
- * @param $reset
- * Whether to reset the static cache, you should only use this if
- * updating and loading term hierarchies during a page request.
* @param $depth
* Internal use only.
*
@@ -791,12 +804,10 @@ function taxonomy_get_children($tid, $vid = 0, $key = 'tid') {
* to have "depth" and "parents" attributes in addition to its normal ones.
* Results are statically cached.
*/
-function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $reset = FALSE, $depth = -1) {
- static $children, $parents, $terms;
-
- if ($reset) {
- $children = $parents = $terms = array();
- }
+function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $depth = -1) {
+ $children = &drupal_static(__FUNCTION__, array());
+ $parents = &drupal_static(__FUNCTION__ . 'parents', array());
+ $terms = &drupal_static(__FUNCTION__ . 'terms', array());
$depth++;
@@ -804,6 +815,8 @@ function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $reset = FALSE,
// and its children, too.
if (!isset($children[$vid])) {
$children[$vid] = array();
+ $parents[$vid] = array();
+ $terms[$vid] = array();
$result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $vid);
while ($term = db_fetch_object($result)) {
@@ -826,7 +839,7 @@ function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $reset = FALSE,
$tree[] = $term;
if (!empty($children[$vid][$child])) {
- $tree = array_merge($tree, taxonomy_get_tree($vid, $child, $max_depth, $reset, $depth));
+ $tree = array_merge($tree, taxonomy_get_tree($vid, $child, $max_depth, $depth));
}
}
}
@@ -857,17 +870,11 @@ function taxonomy_get_synonyms($tid) {
*
* @param $synonym
* The string to compare against.
- * @param $reset
- * Whether to reset the internal cache for this synonym.
* @return
* A term object, or FALSE if no matching term is found.
*/
-function taxonomy_get_synonym_root($synonym, $reset = FALSE) {
- static $synonyms = array();
-
- if ($reset) {
- unset($synonyms[$synonym]);
- }
+function taxonomy_get_synonym_root($synonym) {
+ $synonyms = &drupal_static(__FUNCTION__, array());
if (!isset($synonyms[$synonym])) {
$synonyms[$synonym] = db_query("SELECT * FROM {taxonomy_term_synonym} s, {taxonomy_term_data} t WHERE t.tid = s.tid AND s.name = :name", array(':name' => $synonym))->fetch();
@@ -883,26 +890,24 @@ function taxonomy_get_synonym_root($synonym, $reset = FALSE) {
* @param $type
* (Optional) The $node->type. If given, taxonomy_term_count_nodes only counts
* nodes of $type that are classified with the term $tid.
- * @param $reset
- * (Optional) Boolean to indicated whether to reset the internal cache.
*
* @return
* An integer representing a number of nodes.
* Results are statically cached.
*/
-function taxonomy_term_count_nodes($tid, $type = NULL, $reset = FALSE) {
- static $count = array();
- if ($reset) {
- $count = array();
+function taxonomy_term_count_nodes($tid, $type = NULL) {
+ $count = &drupal_static(__FUNCTION__, array());
+ // Reset the taxonomy tree when first called (or if reset).
+ if (empty($count)) {
+ drupal_static_reset('taxonomy_get_tree');
}
-
// If $type is NULL, change it to 0 to allow it to be used as an array key
// for the static cache.
$type = empty($type) ? 0 : $type;
if (!isset($count[$type][$tid])) {
$term = taxonomy_term_load($tid);
- $tree = taxonomy_get_tree($term->vid, $tid, NULL, $reset);
+ $tree = taxonomy_get_tree($term->vid, $tid, NULL);
$tids = array($tid);
foreach ($tree as $descendent) {
$tids[] = $descendent->tid;
@@ -955,14 +960,12 @@ function taxonomy_get_term_by_name($name) {
* An array of taxonomy vocabulary IDs.
* @param $conditions
* An array of conditions to add to the query.
- * @param $reset
- * Whether to reset the internal cache.
*
* @return
* An array of vocabulary objects, indexed by vid.
*/
-function taxonomy_vocabulary_load_multiple($vids = array(), $conditions = array(), $reset = FALSE) {
- static $vocabulary_cache = array();
+function taxonomy_vocabulary_load_multiple($vids = array(), $conditions = array()) {
+ $vocabulary_cache = &drupal_static(__FUNCTION__, array());
// Node type associations are not stored in the vocabulary table, so remove
// this from conditions into it's own variable.
if (isset($conditions['type'])) {
@@ -970,10 +973,6 @@ function taxonomy_vocabulary_load_multiple($vids = array(), $conditions = array(
unset($conditions['type']);
}
- if ($reset) {
- $vocabulary_cache = array();
- }
-
$vocabularies = array();
// Create a new variable which is either a prepared version of the $vids
@@ -1087,15 +1086,12 @@ function taxonomy_vocabulary_load_multiple($vids = array(), $conditions = array(
* @param $vid
* The vocabulary's ID.
*
- * @param $reset
- * A boolean flag indicating whether to reset the internal cache.
- *
* @return
* The vocabulary object with all of its metadata, if exists, FALSE otherwise.
* Results are statically cached.
*/
-function taxonomy_vocabulary_load($vid, $reset = FALSE) {
- return reset(taxonomy_vocabulary_load_multiple(array($vid), array(), $reset));
+function taxonomy_vocabulary_load($vid) {
+ return reset(taxonomy_vocabulary_load_multiple(array($vid), array()));
}
/**
@@ -1120,18 +1116,12 @@ function taxonomy_terms_load($str_tids) {
* An array of taxonomy term IDs.
* @param $conditions
* An array of conditions to add to the query.
- * @param $reset
- * Whether to reset the internal cache.
*
* @return
* An array of term objects, indexed by tid.
*/
-function taxonomy_term_load_multiple($tids = array(), $conditions = array(), $reset = FALSE) {
- static $term_cache = array();
-
- if ($reset) {
- $term_cache = array();
- }
+function taxonomy_term_load_multiple($tids = array(), $conditions = array()) {
+ $term_cache = &drupal_static(__FUNCTION__, array());
$terms = array();
@@ -1216,17 +1206,15 @@ function taxonomy_term_load_multiple($tids = array(), $conditions = array(), $re
*
* @param $tid
* A term's ID
- * @param $reset
- * Whether to reset the static cache.
*
* @return
* A term object. Results are statically cached.
*/
-function taxonomy_term_load($tid, $reset = FALSE) {
+function taxonomy_term_load($tid) {
if (!is_numeric($tid)) {
return FALSE;
}
- $term = taxonomy_term_load_multiple(array($tid), array(), $reset);
+ $term = taxonomy_term_load_multiple(array($tid), array());
return $term ? $term[$tid] : FALSE;
}
@@ -1237,10 +1225,10 @@ function taxonomy_term_load($tid, $reset = FALSE) {
* @return Object
* A term object. Results are statically cached.
*/
-function taxonomy_get_term_data($tid, $reset = FALSE) {
- static $terms = array();
+function taxonomy_get_term_data($tid) {
+ $terms = &drupal_static(__FUNCTION__, array());
- if (!isset($terms[$tid]) || $reset) {
+ if (!isset($terms[$tid])) {
$terms[$tid] = db_query('SELECT * FROM {taxonomy_term_data} WHERE tid = :tid', array(':tid' => $tid))->fetchObject();
}
return $terms[$tid];
@@ -1398,6 +1386,7 @@ function taxonomy_node_update($node) {
*/
function taxonomy_node_delete($node) {
db_query('DELETE FROM {taxonomy_term_node} WHERE nid = %d', $node->nid);
+ drupal_static_reset('taxonomy_term_count_nodes');
}
/**
@@ -1407,6 +1396,7 @@ function taxonomy_node_delete($node) {
*/
function taxonomy_node_delete_revision($node) {
db_query('DELETE FROM {taxonomy_term_node} WHERE vid = %d', $node->vid);
+ drupal_static_reset('taxonomy_term_count_nodes');
}
/**
diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test
index 2679da3e7..fda432120 100644
--- a/modules/taxonomy/taxonomy.test
+++ b/modules/taxonomy/taxonomy.test
@@ -151,7 +151,8 @@ class TaxonomyVocabularyFunctionalTest extends TaxonomyWebTestCase {
// Check the created vocabulary.
$vocabularies = taxonomy_get_vocabularies();
$vid = $vocabularies[count($vocabularies)-1]->vid;
- $vocabulary = taxonomy_vocabulary_load($vid, TRUE);
+ drupal_static_reset('taxonomy_vocabulary_load_multiple');
+ $vocabulary = taxonomy_vocabulary_load($vid);
$this->assertTrue($vocabulary, t('Vocabulary found in database'));
// Delete the vocabulary.
@@ -163,7 +164,8 @@ class TaxonomyVocabularyFunctionalTest extends TaxonomyWebTestCase {
// Confirm deletion.
$this->drupalPost(NULL, NULL, t('Delete'));
$this->assertRaw(t('Deleted vocabulary %name.', array('%name' => $vocabulary->name)), t('Vocabulary deleted'));
- $this->assertFalse(taxonomy_vocabulary_load($vid, TRUE), t('Vocabulary is not found in the database'));
+ drupal_static_reset('taxonomy_vocabulary_load_multiple');
+ $this->assertFalse(taxonomy_vocabulary_load($vid), t('Vocabulary is not found in the database'));
}
}
@@ -213,7 +215,7 @@ public static function getInfo() {
* Ensure that the vocabulary static reset works correctly.
*/
function testTaxonomyVocabularyLoadStaticReset() {
- $original_vocabulary = taxonomy_vocabulary_load($this->vocabulary->vid, TRUE);
+ $original_vocabulary = taxonomy_vocabulary_load($this->vocabulary->vid);
$this->assertTrue(is_object($original_vocabulary), t('Vocabulary loaded successfully'));
$this->assertEqual($this->vocabulary->name, $original_vocabulary->name, t('Vocabulary loaded successfully'));
@@ -223,8 +225,8 @@ public static function getInfo() {
$vocabulary->description = $this->randomName();
taxonomy_vocabulary_save($vocabulary);
- // Load the vocabulary with $reset TRUE.
- $new_vocabulary = taxonomy_vocabulary_load($original_vocabulary->vid, TRUE);
+ // Load the vocabulary.
+ $new_vocabulary = taxonomy_vocabulary_load($original_vocabulary->vid);
$this->assertEqual($new_vocabulary->name, $vocabulary->name);
$this->assertEqual($new_vocabulary->name, $vocabulary->name);
@@ -316,7 +318,7 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase {
$this->assertEqual(taxonomy_term_count_nodes($term2->tid), 1, t('Term has one valid node association.'));
// Confirm that term3 is not associated with any nodes.
- //$this->assertEqual(taxonomy_term_count_nodes($term3->tid), NULL, t('Term is not associated with any nodes'));
+ $this->assertEqual(taxonomy_term_count_nodes($term3->tid), 0, t('Term is not associated with any nodes'));
// Set term3 as the parent of term1.
$term1->parent = array($term3->tid);
@@ -326,29 +328,27 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase {
$children = taxonomy_get_children($term3->tid);
$this->assertTrue(isset($children[$term1->tid]), t('Term 3 saved as parent of term 1'));
- // Reset the taxonomy_get_tree() static cache to avoid stale data, since
- // the hierarchy has been updated during this page request.
- $this->assertEqual(count(taxonomy_get_tree($term3->vid, $term3->tid, NULL, TRUE)), 1, t('Term 3 has one child term'));
+ $this->assertEqual(count(taxonomy_get_tree($term3->vid, $term3->tid)), 1, t('Term 3 has one child term'));
// Confirm that term3's parental relationship with term1 leads to a
// node assocation being counted.
- $this->assertEqual(taxonomy_term_count_nodes($term3->tid, NULL, TRUE), 1, t('Term has one valid node association due to child term.'));
+ $this->assertEqual(taxonomy_term_count_nodes($term3->tid, NULL), 1, t('Term has one valid node association due to child term.'));
// Set term3 as the parent of term2.
$term2->parent = array($term3->tid);
taxonomy_term_save($term2);
// term3 should now have two node associations counted.
- $this->assertEqual(taxonomy_term_count_nodes($term3->tid, NULL, TRUE), 2, t('Term has two valid node associations due to child terms.'));
+ $this->assertEqual(taxonomy_term_count_nodes($term3->tid, NULL), 2, t('Term has two valid node associations due to child terms.'));
// Save node1 with both child taxonomy terms, this should still result
// in term3 having two node associations.
$node1->taxonomy = array($term1->tid, $term2->tid);
node_save($node1);
- $this->assertEqual(taxonomy_term_count_nodes($term3->tid, NULL, TRUE), 2, t('Term has two valid node associations.'));
+ $this->assertEqual(taxonomy_term_count_nodes($term3->tid, NULL), 2, t('Term has two valid node associations.'));
// Confirm that the node type argument returns a single node association.
- $this->assertEqual(taxonomy_term_count_nodes($term3->tid, 'page', TRUE), 1, t("Term is associated with one node of type 'page'."));
+ $this->assertEqual(taxonomy_term_count_nodes($term3->tid, 'page'), 1, t("Term is associated with one node of type 'page'."));
}
}
@@ -608,11 +608,11 @@ class TaxonomyLoadMultipleUnitTest extends TaxonomyWebTestCase {
// Remove one term from the array, then delete it.
$deleted = array_shift($terms3);
taxonomy_term_delete($deleted->tid);
- $deleted_term = taxonomy_term_load($deleted->tid, TRUE);
+ $deleted_term = taxonomy_term_load($deleted->tid);
$this->assertFalse($deleted_term);
// Load terms from the vocabulary by vid.
- $terms4 = taxonomy_term_load_multiple(NULL, array('vid' => $vocabulary->vid), TRUE);
+ $terms4 = taxonomy_term_load_multiple(NULL, array('vid' => $vocabulary->vid));
$this->assertTrue(count($terms4 == 4), t('Correct number of terms were loaded.'));
$this->assertFalse(isset($terms4[$deleted->tid]));
@@ -669,7 +669,8 @@ class TaxonomyHooksTestCase extends DrupalWebTestCase {
'antonyms' => 'Short',
);
$this->drupalPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save'));
- $term = taxonomy_term_load($term->tid, TRUE);
+ taxonomy_terms_static_reset();
+ $term = taxonomy_term_load($term->tid);
$this->assertTrue(in_array($edit['antonyms'], $term->antonyms), t('Antonym was successfully edited'));
// Delete the term.
diff --git a/modules/translation/translation.test b/modules/translation/translation.test
index 22b08faf1..73afe8409 100644
--- a/modules/translation/translation.test
+++ b/modules/translation/translation.test
@@ -100,7 +100,9 @@ class TranslationTestCase extends DrupalWebTestCase {
$edit['langcode'] = $language_code;
$this->drupalPost('admin/international/language/add', $edit, t('Add language'));
- $languages = language_list('language', TRUE); // Make sure we're not using a stale list.
+ // Make sure we're not using a stale list.
+ drupal_static_reset('language_list');
+ $languages = language_list('language');
$this->assertTrue(array_key_exists($language_code, $languages), t('Language was installed successfully.'));
if (array_key_exists($language_code, $languages)) {