Skip to content
Snippets Groups Projects
Commit 383f7e57 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #302412 by Berdir: converted more of taxonomy module to the new database abstraction layer.

parent bd93e727
No related branches found
No related tags found
No related merge requests found
...@@ -265,9 +265,29 @@ function taxonomy_overview_terms(&$form_state, $vocabulary) { ...@@ -265,9 +265,29 @@ function taxonomy_overview_terms(&$form_state, $vocabulary) {
if ($vocabulary->tags) { if ($vocabulary->tags) {
// We are not calling taxonomy_get_tree because that might fail with a big // We are not calling taxonomy_get_tree because that might fail with a big
// number of tags in the freetagging vocabulary. // number of tags in the freetagging vocabulary.
$results = pager_query(db_rewrite_sql('SELECT t.*, h.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'), $page_increment, 0, NULL, $vocabulary->vid); $query = db_select('taxonomy_term_data', 't')->extend('PagerDefault');
$total_entries = db_query(db_rewrite_sql('SELECT COUNT(*) FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} h ON t.tid = h.tid WHERE t.vid = :vid'), array(':vid' => $vocabulary->vid)); $query->join('taxonomy_term_hierarchy', 'h', 't.tid = h.tid');
while ($term = db_fetch_object($results)) { $query->addTag('term_access');
$query->condition('t.vid', $vocabulary->vid);
// Store count in total entries and use this as count query.
$count_query = db_select('taxonomy_term_data', 't');
$count_query->join('taxonomy_term_hierarchy', 'h', 't.tid = h.tid');
$count_query->addTag('term_access');
$count_query->condition('t.vid', $vocabulary->vid);
$count_query->addExpression('COUNT(t.tid)');
$total_entries = $count_query->execute();
$query->setCountQuery($count_query);
$result = $query
->fields('t')
->fields('h', array('parent'))
->orderBy('weight')
->orderBy('name')
->limit($page_increment)
->execute();
foreach ($result as $term) {
$key = 'tid:' . $term->tid . ':0'; $key = 'tid:' . $term->tid . ':0';
$current_page[$key] = $term; $current_page[$key] = $term;
$page_entries++; $page_entries++;
...@@ -903,7 +923,10 @@ function taxonomy_vocabulary_confirm_reset_alphabetical(&$form_state, $vid) { ...@@ -903,7 +923,10 @@ function taxonomy_vocabulary_confirm_reset_alphabetical(&$form_state, $vid) {
* @see taxonomy_vocabulary_confirm_reset_alphabetical() * @see taxonomy_vocabulary_confirm_reset_alphabetical()
*/ */
function taxonomy_vocabulary_confirm_reset_alphabetical_submit($form, &$form_state) { function taxonomy_vocabulary_confirm_reset_alphabetical_submit($form, &$form_state) {
db_query('UPDATE {taxonomy_term_data} SET weight = 0 WHERE vid = :vid', array(':vid' => $form_state['values']['vid'])); db_update('taxonomy_term_data')
->fields(array('weight' => 0))
->condition('vid', $form_state['values']['vid'])
->execute();
drupal_set_message(t('Reset vocabulary %name to alphabetical order.', array('%name' => $form_state['values']['name']))); drupal_set_message(t('Reset vocabulary %name to alphabetical order.', array('%name' => $form_state['values']['name'])));
watchdog('taxonomy', 'Reset vocabulary %name to alphabetical order.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE); watchdog('taxonomy', 'Reset vocabulary %name to alphabetical order.', array('%name' => $form_state['values']['name']), WATCHDOG_NOTICE);
$form_state['redirect'] = 'admin/content/taxonomy/' . $form_state['values']['vid']; $form_state['redirect'] = 'admin/content/taxonomy/' . $form_state['values']['vid'];
......
This diff is collapsed.
...@@ -16,13 +16,17 @@ function taxonomy_term_page($terms, $depth = 0, $op = 'page') { ...@@ -16,13 +16,17 @@ function taxonomy_term_page($terms, $depth = 0, $op = 'page') {
$str_tids = $terms['str_tids']; $str_tids = $terms['str_tids'];
if ($terms['tids']) { if ($terms['tids']) {
$result = db_query(db_rewrite_sql('SELECT t.tid, t.name FROM {taxonomy_term_data} t WHERE t.tid IN (' . db_placeholders($terms['tids']) . ')', 't', 'tid'), $terms['tids']); $query = db_select('taxonomy_term_data', 't');
$tids = array(); // we rebuild the $tids-array so it only contains terms the user has access to. $query->addTag('term_access');
$names = array();
while ($term = db_fetch_object($result)) { // Load array with all tid's the user has access to in the format tid => name.
$tids[] = $term->tid; $term_results = $query
$names[] = $term->name; ->fields('t', array('tid', 'name'))
} ->condition('tid', $terms['tids'], 'IN')
->execute()
->fetchAllKeyed();
$tids = array_keys($term_results);
$names = array_values($term_results);
if ($names) { if ($names) {
$title = check_plain(implode(', ', $names)); $title = check_plain(implode(', ', $names));
...@@ -124,20 +128,26 @@ function taxonomy_autocomplete($vid, $string = '') { ...@@ -124,20 +128,26 @@ function taxonomy_autocomplete($vid, $string = '') {
$last_string = trim(array_pop($array)); $last_string = trim(array_pop($array));
$matches = array(); $matches = array();
if ($last_string != '') { if ($last_string != '') {
$result = db_query_range(db_rewrite_sql("SELECT t.tid, t.name FROM {taxonomy_term_data} t WHERE t.vid = :vid AND LOWER(t.name) LIKE LOWER(:last_string)", 't', 'tid'), array( $query = db_select('taxonomy_term_data', 't');
':vid' => $vid, $query->addTag('term_access');
':last_string' => '%'. $last_string .'%',
), 0, 10); $tags = $query
->fields('t', array('tid', 'name'))
->condition('t.vid', $vid)
->where("LOWER(t.name) LIKE LOWER(:last_string)", array(':last_string' => '%'. $last_string .'%'))
->range(0, 10)
->execute()
->fetchAllKeyed();
$prefix = count($array) ? implode(', ', $array) . ', ' : ''; $prefix = count($array) ? implode(', ', $array) . ', ' : '';
while ($tag = db_fetch_object($result)) { foreach ($tags as $tid => $name) {
$n = $tag->name; $n = $name;
// Commas and quotes in terms are special cases, so encode 'em. // Commas and quotes in terms are special cases, so encode 'em.
if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) { if (strpos($name, ',') !== FALSE || strpos($name, '"') !== FALSE) {
$n = '"' . str_replace('"', '""', $tag->name) . '"'; $n = '"' . str_replace('"', '""', $name) . '"';
} }
$matches[$prefix . $n] = check_plain($tag->name); $matches[$prefix . $n] = check_plain($name);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment