We have a file that will be imported weekly. There will be MANY nodes that will be duplicated in this file. However, the titles of our nodes are not unique. There is a hidden CCK field that will be unique. We would like the same functionality as the unique title functionality (that says: Title must be unique for this node type.)

I attempted a number of variations, starting with updating node.inc to have another checkbox called unique_field and duplicating the functionality as unique_title. The checkbox was created fine, but it did not throw errors or prevent duplication. The code I thought would prevent duplication was:

if ($unique_field) {
    $count = db_fetch_object(db_query("SELECT count(*) cnt FROM {content_type_calls} WHERE field_transactionid_value = '%s' AND type = '%s'", $node->field_transactionid_value, $node->type));
    if ($count->cnt > 0) {
      $errors[] = t('The node field %field is not unique for this node type.', array('%field' => $node->field_transactionid_value));
    }
  }

I also tried copying this code into cck/content.inc into the same hook functions (content_node_import_prepare and content_node_import_global), but did not have success there, either. Am I way out in left field and hopeless or am I close and missing something that could be easily resolved?

Comments

jwalling’s picture

Status: Active » Closed (fixed)
BrianKlinger’s picture

Status: Closed (fixed) » Active

Hi - I just posted this request for some support yesterday, and it was closed with no explanation. I'm hoping it was just a mistake. At any rate, my question was not answered, so I'm returning the status to active.

BrianKlinger’s picture

I actually resolved this one on my own. Of course, content_type_calls doesn't have a column "type", so it was failing because of the check for $node->type. Removed that portion and duplicated the lines elsewhere in the code (if it had unique_title I created an alternate called unique_field) as stated previously, and all worked fine. I'd create a patch for contribution, but this is a hard-coded answer to something that of course SHOULD be dynamically created, as each person's content types and fields will be different. If anyone can give me a good way to create the same effect using a module or something without "hacking" the .inc file, I'd love to hear about it, otherwise I'm going to leave well enough alone and make sure I update that file every time I run an update.

BrianKlinger’s picture

Status: Active » Closed (fixed)