I auto generate my node titles on import and I also need the node titles to be unique, but the check for a unique node title seems to be done before the title has been generated by Auto Nodetitle. This can result in duplicate nodes.

I have had a quick look, but I can't see where to fix this.

Any pointers appreciated!

Using D5.10, Automatic Nodetitles 5.x-1.1, Token 5.x-1.x-dev

CommentFileSizeAuthor
#2 auto_nodetitle.patch1.92 KBlinl

Comments

PatFrat’s picture

subscribing

linl’s picture

Status: Active » Needs review
StatusFileSize
new1.92 KB

Attached is a patch for this that I've used for a one off import into my site with auto nodetitles. Not ideal as it adds another checkbox rather than using the existing setting, but I did it this way to keep it self contained rather than messing with node_import.module and node.inc.

I've tested it with D5.10, Node Import 5.x-1.6, Automatic Nodetitles 5.x-1.1, Token 5.x-1.x-dev

Robrecht Jacques’s picture

Category: support » bug
Status: Needs review » Fixed

I've modified the code a bit so we use the same setting as node.inc. In order to avoid the test in supported/node.inc I assign a random title in supported/auto_nodetitle.inc and redo the test in there. The new code:


/**
 * @file
 * Support for the auto_nodetitle module.
 */

/**
 * Implementation of hook_node_import_prepare().
 */
function auto_nodetitle_node_import_prepare(&$node, $preview) {
  $errors = array();

  $setting = auto_nodetitle_get_setting($node->type);
  if (($setting == AUTO_NODETITLE_ENABLED) || ($setting == AUTO_NODETITLE_OPTIONAL && $node->title == $node->auto_nodetitle)) {
    // Flush the tokens and create a new title.
    token_get_values('node', $node, TRUE);
    auto_nodetitle_set_title($node);
    unset($node->auto_nodetitle);
  }

  // Since we provided a static random title value the test in
  // supported/node.inc for unique titles does no longer work.
  if ($setting == AUTO_NODETITLE_ENABLED || $setting == AUTO_NODETITLE_OPTIONAL) {
    if ($node->node_import_node['unique_title']) {
      $count = db_fetch_object(db_query("SELECT count(*) cnt FROM {node} WHERE title = '%s' AND type = '%s'", $node->title, $node->type));
      if ($count->cnt > 0) {
        $errors[] = t('The node title %title is not unique for this node type.', array('%title' => $node->title));
      }
    }
  }

  return $errors;
}

/**
 * Implementation of hook_node_import_static().
 */
function auto_nodetitle_node_import_static($type) {
  $setting = auto_nodetitle_get_setting($type);
  if (($setting == AUTO_NODETITLE_ENABLED) || ($setting == AUTO_NODETITLE_OPTIONAL)) {
    $title = md5(rand());
    return array(
      'title' => $title,
      'auto_nodetitle' => $title,
    );
  }
}

Note that in 5.x-1.6 there was a problem with the unique title feature so there is a little patch for supported/node.inc as well.

Fixed. Will be included in next release of node_import (5.x-1.8). Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.