- Patch #343788 by catch: taxonomy module doesn't use its own APIs.
parent
19a6c84f7c
commit
6fc4eb9f94
|
@ -504,7 +504,6 @@ function taxonomy_terms_static_reset() {
|
||||||
drupal_static_reset('taxonomy_get_tree');
|
drupal_static_reset('taxonomy_get_tree');
|
||||||
drupal_static_reset('taxonomy_get_synonym_root');
|
drupal_static_reset('taxonomy_get_synonym_root');
|
||||||
drupal_static_reset('taxonomy_term_load_multiple');
|
drupal_static_reset('taxonomy_term_load_multiple');
|
||||||
drupal_static_reset('taxonomy_get_term_data');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1119,13 +1118,7 @@ function taxonomy_term_count_nodes($tid, $type = NULL) {
|
||||||
* An array of matching term objects.
|
* An array of matching term objects.
|
||||||
*/
|
*/
|
||||||
function taxonomy_get_term_by_name($name) {
|
function taxonomy_get_term_by_name($name) {
|
||||||
$query = db_select('taxonomy_term_data', 't');
|
return taxonomy_term_load_multiple(array(), array('name' => trim($name)));
|
||||||
$query->addTag('term_access');
|
|
||||||
|
|
||||||
return $query
|
|
||||||
->fields('t')
|
|
||||||
->where("LOWER(t.name) = LOWER(:name)", array(':name' => trim($name)))
|
|
||||||
->execute()->fetchAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1328,9 +1321,14 @@ function taxonomy_term_load_multiple($tids = array(), $conditions = array()) {
|
||||||
|
|
||||||
// Remove any loaded terms from the array if they don't match $conditions.
|
// Remove any loaded terms from the array if they don't match $conditions.
|
||||||
if ($conditions) {
|
if ($conditions) {
|
||||||
|
// Name matching is case insensitive, note that with some collations
|
||||||
|
// LOWER() and drupal_strtolower() may return different results.
|
||||||
foreach ($terms as $term) {
|
foreach ($terms as $term) {
|
||||||
$term_values = (array) $term;
|
$term_values = (array) $term;
|
||||||
if (array_diff_assoc($conditions, $term_values)) {
|
if (isset($conditions['name']) && drupal_strtolower($conditions['name'] != drupal_strtolower($term_values['name']))) {
|
||||||
|
unset($terms[$term->tid]);
|
||||||
|
}
|
||||||
|
elseif (array_diff_assoc($conditions, $term_values)) {
|
||||||
unset($terms[$term->tid]);
|
unset($terms[$term->tid]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1350,6 +1348,11 @@ function taxonomy_term_load_multiple($tids = array(), $conditions = array()) {
|
||||||
|
|
||||||
// If the conditions array is populated, add those to the query.
|
// If the conditions array is populated, add those to the query.
|
||||||
if ($conditions) {
|
if ($conditions) {
|
||||||
|
// When name is passed as a condition use LIKE.
|
||||||
|
if (isset($conditions['name'])) {
|
||||||
|
$query->condition('t.name', $conditions['name'], 'LIKE');
|
||||||
|
unset($conditions['name']);
|
||||||
|
}
|
||||||
foreach ($conditions as $field => $value) {
|
foreach ($conditions as $field => $value) {
|
||||||
$query->condition('t.' . $field, $value);
|
$query->condition('t.' . $field, $value);
|
||||||
}
|
}
|
||||||
|
@ -1398,22 +1401,6 @@ function taxonomy_term_load($tid) {
|
||||||
return $term ? $term[$tid] : FALSE;
|
return $term ? $term[$tid] : FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a term object from the taxonomy_term_data table.
|
|
||||||
* @param $tid
|
|
||||||
* A term's ID
|
|
||||||
* @return Object
|
|
||||||
* A term object. Results are statically cached.
|
|
||||||
*/
|
|
||||||
function taxonomy_get_term_data($tid) {
|
|
||||||
$terms = &drupal_static(__FUNCTION__, array());
|
|
||||||
|
|
||||||
if (!isset($terms[$tid])) {
|
|
||||||
$terms[$tid] = db_query('SELECT * FROM {taxonomy_term_data} WHERE tid = :tid', array(':tid' => $tid))->fetch();
|
|
||||||
}
|
|
||||||
return $terms[$tid];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a select form element for a given taxonomy vocabulary.
|
* Create a select form element for a given taxonomy vocabulary.
|
||||||
*
|
*
|
||||||
|
@ -1511,10 +1498,10 @@ function taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0, $p
|
||||||
if ($depth === 'all') {
|
if ($depth === 'all') {
|
||||||
$depth = NULL;
|
$depth = NULL;
|
||||||
}
|
}
|
||||||
foreach ($tids as $index => $tid) {
|
$terms = taxonomy_term_load_multiple($tids);
|
||||||
$term = taxonomy_get_term_data($tid);
|
foreach ($terms as $term) {
|
||||||
$tree = taxonomy_get_tree($term->vid, $tid, $depth);
|
$tree = taxonomy_get_tree($term->vid, $term->tid, $depth);
|
||||||
$descendant_tids[] = array_merge(array($tid), array_map('_taxonomy_get_tid_from_term', $tree));
|
$descendant_tids[] = array_merge(array($term->tid), array_map('_taxonomy_get_tid_from_term', $tree));
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = db_select('node', 'n');
|
$query = db_select('node', 'n');
|
||||||
|
|
|
@ -525,7 +525,7 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
|
||||||
// Create the term to edit.
|
// Create the term to edit.
|
||||||
$this->drupalPost('admin/content/taxonomy/' . $this->vocabulary->vid . '/add', $edit, t('Save'));
|
$this->drupalPost('admin/content/taxonomy/' . $this->vocabulary->vid . '/add', $edit, t('Save'));
|
||||||
|
|
||||||
$term = taxonomy_get_term_by_name($edit['name']);
|
$term = reset(taxonomy_get_term_by_name($edit['name']));
|
||||||
$this->assertNotNull($term, t('Term found in database'));
|
$this->assertNotNull($term, t('Term found in database'));
|
||||||
|
|
||||||
// Submitting a term takes us to the add page; we need the List page.
|
// Submitting a term takes us to the add page; we need the List page.
|
||||||
|
@ -546,21 +546,52 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Edit the term.
|
// Edit the term.
|
||||||
$this->drupalPost('taxonomy/term/' . $term[0]->tid . '/edit', $edit, t('Save'));
|
$this->drupalPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save'));
|
||||||
|
|
||||||
// View the term and check that it is correct.
|
// View the term and check that it is correct.
|
||||||
$this->drupalGet('taxonomy/term/' . $term[0]->tid);
|
$this->drupalGet('taxonomy/term/' . $term->tid);
|
||||||
$this->assertText($edit['name'], t('The randomly generated term name is present.'));
|
$this->assertText($edit['name'], t('The randomly generated term name is present.'));
|
||||||
$this->assertText($edit['description'], t('The randomly generated term description is present.'));
|
$this->assertText($edit['description'], t('The randomly generated term description is present.'));
|
||||||
|
|
||||||
// Delete the term.
|
// Delete the term.
|
||||||
$this->drupalPost('taxonomy/term/' . $term[0]->tid . '/edit', array(), t('Delete'));
|
$this->drupalPost('taxonomy/term/' . $term->tid . '/edit', array(), t('Delete'));
|
||||||
$this->drupalPost(NULL, NULL, t('Delete'));
|
$this->drupalPost(NULL, NULL, t('Delete'));
|
||||||
|
|
||||||
// Assert that the term no longer exists.
|
// Assert that the term no longer exists.
|
||||||
$this->drupalGet('taxonomy/term/' . $term[0]->tid);
|
$this->drupalGet('taxonomy/term/' . $term->tid);
|
||||||
$this->assertResponse(404, t('The taxonomy term page was not found'));
|
$this->assertResponse(404, t('The taxonomy term page was not found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test taxonomy_get_term_by_name().
|
||||||
|
*/
|
||||||
|
function testTaxonomyGetTermByName() {
|
||||||
|
$term = $this->createTerm($this->vocabulary->vid);
|
||||||
|
|
||||||
|
// Load the term with the exact name.
|
||||||
|
$terms = taxonomy_get_term_by_name($term->name);
|
||||||
|
$this->assertTrue(isset($terms[$term->tid]), t('Term loaded using exact name.'));
|
||||||
|
|
||||||
|
// Load the term with space concatenated.
|
||||||
|
$terms = taxonomy_get_term_by_name(' ' . $term->name . ' ');
|
||||||
|
$this->assertTrue(isset($terms[$term->tid]), t('Term loaded with extra whitespace.'));
|
||||||
|
|
||||||
|
// Load the term with name uppercased.
|
||||||
|
$terms = taxonomy_get_term_by_name(strtoupper($term->name));
|
||||||
|
$this->assertTrue(isset($terms[$term->tid]), t('Term loaded with uppercased name.'));
|
||||||
|
|
||||||
|
// Load the term with name lowercased.
|
||||||
|
$terms = taxonomy_get_term_by_name(strtolower($term->name));
|
||||||
|
$this->assertTrue(isset($terms[$term->tid]), t('Term loaded with lowercased name.'));
|
||||||
|
|
||||||
|
// Try to load an invalid term name.
|
||||||
|
$terms = taxonomy_get_term_by_name('Banana');
|
||||||
|
$this->assertFalse($terms);
|
||||||
|
|
||||||
|
// Try to load the term using a substring of the name.
|
||||||
|
$terms = taxonomy_get_term_by_name(drupal_substr($term->name, 2));
|
||||||
|
$this->assertFalse($terms);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -664,8 +695,7 @@ class TaxonomyHooksTestCase extends DrupalWebTestCase {
|
||||||
'antonyms' => 'Long',
|
'antonyms' => 'Long',
|
||||||
);
|
);
|
||||||
$this->drupalPost('admin/content/taxonomy/1/add', $edit, t('Save'));
|
$this->drupalPost('admin/content/taxonomy/1/add', $edit, t('Save'));
|
||||||
$terms = taxonomy_get_term_by_name($edit['name']);
|
$term = reset(taxonomy_get_term_by_name($edit['name']));
|
||||||
$term = taxonomy_term_load($terms[0]->tid);
|
|
||||||
$this->assertEqual($term->antonyms[0], $edit['antonyms'], t('Antonyms were loaded into the term object'));
|
$this->assertEqual($term->antonyms[0], $edit['antonyms'], t('Antonyms were loaded into the term object'));
|
||||||
|
|
||||||
// Update the term with a different antonym.
|
// Update the term with a different antonym.
|
||||||
|
|
Loading…
Reference in New Issue