DOIs are supposed to be permanent and unique. This patch takes a step forward for both. Restricting access to the DOI could be a configuration toggle on/off, retaining it safely seems like it would be one of the primary objectives of the module. The DOI lookup after the patch also cross-references the table to ensure that it is not looking at an old version (vid) of the node. I suppose the two adjustments could be considered separately.

Comments

stackpr’s picture

This is similar to #932566: retaining DOI number in node, but that appears to relate to a bug in the node-add UI, whereas this focuses on the edit form.

rjerome’s picture

This doesn't work when creating a new node, since there is no $form['#node']->nid value yet...

      // Look for DOI conflicts on save.
      if (!empty($form_state['values']['biblio_doi'])) {
        $doi = $form_state['values']['biblio_doi'];
        $conflict = (int) db_result(db_query("SELECT nid FROM {biblio} INNER JOIN {node} USING (nid, vid) WHERE biblio_doi = '%s' AND nid != %d", $doi, (int) $form['#node']->nid));
        if ($conflict) {
          form_set_error('biblio_doi', l(t("Another node already has this DOI."), "node/$conflict"));
        }
      }
stackpr’s picture

It might not be glorious, but it works. The empty nid would be cast to 0. Since there is never a nid=0 in the node table, the query would still work.

It could achieve the same thing if it were to run a different query when the nid is not set, simply without the nid condition.

rjerome’s picture

The reason I brought this up is that it didn't work at all when I tested it creating a new node. I always got a "conflict" error pointing to a node that didn't have any DOI attached to it. I didn't chase it down very much, so I can't tell you why at this point.

Ron.

stackpr’s picture

Corrected patch attached. It was not accounting for empty dois. I have quite a few other customizations at this point, but I think that I extracted the relevant patch info.

stackpr’s picture

Corrected patch (typo when manually adjusting).

liam morland’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

This version is no longer maintained. If this issue is still relevant to the Drupal 7 version, please re-open and provide details.