function _wikitools_duplicate_nodes_query in Wikitools 6
Same name and namespace in other branches
- 5 wikitools.module \_wikitools_duplicate_nodes_query()
- 6.2 wikitools.admin.inc \_wikitools_duplicate_nodes_query()
- 7 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
$node_types_placeholders = db_placeholders($node_types, 'varchar');
$from_part = 'FROM {node} n1, {node} n2 WHERE LOWER(' . $n1_title . ') = LOWER(' . $n2_title . ') AND n1.nid != n2.nid AND n1.type IN(' . $node_types_placeholders . ') AND n2.type IN(' . $node_types_placeholders . ')';
$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_merge($node_types, $node_types),
);
}
return array(
NULL,
NULL,
NULL,
);
}