1

Is there any easy way to remove duplicate nodes based on Node title?

2 Answers 2

4

You can achieve that by Remove Duplicates module

This module helps the administrator to easily remove duplicate nodes according to one of the node fields.

Features

The duplicate nodes found are permanently removed. It can be very useful with Drupal Feeds module (Feeds).

7
  • hw can i test this..
    – Nishant
    Commented Jun 23, 2014 at 11:20
  • actually i jst create some content i.e. Article with same name... all are shows...
    – Nishant
    Commented Jun 23, 2014 at 11:22
  • @niks88 I didn't try this module before let me check that for you Commented Jun 23, 2014 at 11:35
  • @niks88 It's working fine. Once Remove Duplicates module is installed and enabled, you can use it at admin/config/content/remove_duplicates. If you not sure, please try it on your local env. Commented Jun 23, 2014 at 11:44
  • after enable is there any setting is needed...???
    – Nishant
    Commented Jun 23, 2014 at 11:49
2

You can also achieve that by creating a custom module

<?php
/**
 * @file
 * Remove Duplicate Nodes.
 */
/**
 * Implementation of hook_menu().
 */
function dedupe_menu() {
    $items['admin/content/dedupe'] = array(
        'title' => 'Dedupe',
        'description' => 'Delete Duplicate Nodes',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('dedupe_content_command'),
        'access arguments' => array('administer site configuration'),
        'type' => MENU_NORMAL_ITEM,
    );
    return $items;
}
/**
 * Build Form
 */
function dedupe_content_command() {
    $options = node_get_types('names');
    $form['dedupe_node_types'] = array(
        '#type' => 'select',
        '#title' => t('You can select content type from which duplicates are removed.'),
        '#options' => $options,
        '#default_value' => variable_get('dedupe_node_types', array('page')),
        '#description' => t('Duplicate content from the selected content types will be deleted.'),
    );
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Dedupe'),
    );
    return $form;
}
/**
 * Call delete function and set message.
 */
function dedupe_content_command_submit($form, $form_state) {
    $type= $form_state['values']['dedupe_node_types'];
    $dedupe_m = 'Duplicates deleted from content type '. $type;
    dedupe_delete($type);
    drupal_set_message(check_plain(t($dedupe_m)));
}
/**
 * Delete duplicates from selected content type, based on title. By Robert Douglass.
 * @see http://robshouse.net/blog-post/remove-duplicate-nodes-dedupe-based-title
 */
function dedupe_delete($type) {
    $previous = array();
    $result = db_query("SELECT nid, title FROM {node}
    WHERE title IN
      (SELECT title FROM {node}
        WHERE type = '%s'
        GROUP BY title HAVING count(*) > 1)
    ORDER BY title, created DESC", $type);
    while ($row = db_fetch_array($result)) {
        if ($row['title'] == $previous['title']) {
            node_delete($previous['nid']);
        }
        $previous = $row;
    }
}
?>

Note: I didn't test this code.But seems it would work.Read more from Remove Duplicate Nodes based on title

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.