You are here

function _wikitools_duplicate_nodes_query in Wikitools 7

Same name and namespace in other branches
  1. 5 wikitools.module \_wikitools_duplicate_nodes_query()
  2. 6.2 wikitools.admin.inc \_wikitools_duplicate_nodes_query()
  3. 6 wikitools.admin.inc \_wikitools_duplicate_nodes_query()

Create queries to find nodes with duplicate titles.

1 call to _wikitools_duplicate_nodes_query()
wikitools_page_duplicates in ./wikitools.admin.inc
Menu callback for duplicate pages list.

File

./wikitools.admin.inc, line 142
Wikitools administration UI.

Code

function _wikitools_duplicate_nodes_query() {
  $node_types = array_values(wikitools_node_types());
  if (count($node_types)) {

    // Make sure we deal with various title equalities
    $n1_title = 'n1.title';
    $n2_title = 'n2.title';
    if (wikitools_treat_underscore_as_space()) {
      $n1_title = "REPLACE({$n1_title}, '_', ' ')";
      $n2_title = "REPLACE({$n2_title}, '_', ' ')";
    }
    if (wikitools_treat_dash_as_space()) {
      $n1_title = "REPLACE({$n1_title}, '-', ' ')";
      $n2_title = "REPLACE({$n2_title}, '-', ' ')";
    }

    // Grab all nodes that have the same title
    $from_part = 'FROM {node} n1, {node} n2 WHERE LOWER(' . $n1_title . ') = LOWER(' . $n2_title . ') AND n1.nid != n2.nid AND n1.type IN(:type) AND n2.type IN(:type)';
    $select_query = 'SELECT DISTINCT(n1.nid), n1.title ' . $from_part . ' ORDER BY n1.title ASC';
    $count_query = 'SELECT COUNT(DISTINCT(n1.nid)) ' . $from_part;
    return array(
      $select_query,
      $count_query,
      array(
        ':type' => $node_types,
      ),
    );
  }
  return array(
    NULL,
    NULL,
    NULL,
  );
}