? uuid-dupes5.patch
? uuid.drush.inc
Index: uuid.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uuid/uuid.module,v
retrieving revision 1.1.2.17
diff -u -p -r1.1.2.17 uuid.module
--- uuid.module	16 Nov 2010 02:57:59 -0000	1.1.2.17
+++ uuid.module	31 Jan 2011 22:47:38 -0000
@@ -24,6 +24,17 @@ function uuid_menu() {
 
   return $items;
 }
+/**
+ * Load the uuid information for a node.
+ */
+function uuid_node_load($node) {
+  if ($arr = db_fetch_array(db_query('SELECT un.uuid AS uuid, unr.uuid AS revision_uuid FROM {uuid_node} un LEFT JOIN {uuid_node_revisions} unr ON unr.vid=%d WHERE un.nid=%d', $node->vid, $node->nid))) {
+    return $arr;
+  }
+  else {
+   return array('uuid' => FALSE, 'revision_uuid' => FALSE);
+  }
+}
 
 /**
  * Implementation of hook_nodeapi().
@@ -33,12 +44,7 @@ function uuid_nodeapi(&$node, $op, $teas
 
   switch ($op) {
     case 'load':
-      $revision_uuid = db_result(db_query('SELECT uuid FROM {uuid_node_revisions} WHERE vid = %d', $node->vid));
-      return array(
-        'uuid' => db_result(db_query('SELECT uuid FROM {uuid_node} WHERE nid = %d', $node->nid)),
-        'revision_uuid' => $revision_uuid,
-        'loaded_revision_uuid' => $revision_uuid,
-      );
+      return uuid_node_load($node);
     case 'insert':
       // Handle the case where automatic UUID generation is turned OFF but a
       // node is created, node_save(), intentionally with the $node->uuid
@@ -55,7 +61,7 @@ function uuid_nodeapi(&$node, $op, $teas
           db_query("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES (%d, '%s', %d)", $node->vid, $node->revision_uuid, $node->nid);
         }
       }
-      elseif (in_array($node->type, $automatic_types)) {
+      elseif (in_array($node->type, $automatic_types, TRUE)) {
         $node->uuid = uuid_uuid();
         $node->revision_uuid = uuid_uuid();
         db_query("INSERT INTO {uuid_node} (nid, uuid) VALUES (%d, '%s')", $node->nid, $node->uuid);
@@ -63,15 +69,27 @@ function uuid_nodeapi(&$node, $op, $teas
       }
       break;
     case 'update':
-      if (isset($node->revision)) {
-        if (isset($node->revision_uuid) && uuid_is_valid($node->revision_uuid) && $node->revision_uuid != $node->loaded_revision_uuid) {
-          db_query("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES (%d, '%s', %d)", $node->vid, $node->revision_uuid, $node->nid);
+      // Get existing UUID info from the DB
+      $uuid_information = uuid_node_load($node);
+
+      // Compare to values passed in - do we need to create or update the node's UUID value?
+      if (!empty($node->uuid)) {
+        if (empty($uuid_information['uuid'])) {
+          db_query("INSERT INTO {uuid_node} (nid, uuid) VALUES (%d, '%s')", $node->nid, $node->uuid);
         }
-        else {
-          $node->revision_uuid = uuid_uuid();
-          db_query("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES (%d, '%s', %d)", $node->vid, $node->revision_uuid, $node->nid);
+        elseif ($node->uuid != $uuid_information['uuid']) {
+          db_query("UPDATE {uuid_node} SET uuid='%s' WHERE nid=%d", $node->uuid, $node->nid);
         }
       }
+
+      // Create a new uuid for this revision if the node already has a uuid
+      // or if the content type is configured to have uuids
+      // automatically assigned.
+      if (!empty($node->revision) && (in_array($node->type, $automatic_types, TRUE) || !empty($node->uuid))) {
+        // Assign a new uuid to this revision.
+        $node->revision_uuid = uuid_uuid();
+        db_query("INSERT INTO {uuid_node_revisions} (vid, uuid, nid) VALUES (%d, '%s', %d)", $node->vid, $node->revision_uuid, $node->nid);
+      }
       break;
     case 'delete':
       db_query('DELETE FROM {uuid_node} WHERE nid = %d', $node->nid);
Index: uuid.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/uuid/Attic/uuid.test,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 uuid.test
--- uuid.test	16 Nov 2010 04:26:50 -0000	1.1.2.1
+++ uuid.test	31 Jan 2011 22:47:38 -0000
@@ -112,7 +112,7 @@ class UUIDUnitTestCase extends UUIDTestH
    * Mark testcase as incomplete.
    */
   function testMarkIncomplete() {
-    $this->markIncomplete(t("This test in incomplete."));
+    $this->markIncomplete(t("This test is incomplete."));
   }
 
 
@@ -154,14 +154,14 @@ class UUIDFunctionalityTestCase extends 
     $object = $this->drupalCreateNode($options);
 
     // Verify fields are not attached to the node.
-    $this->assertFalse(
-      isset($object->uuid),
-      t("Node has not uuid field attached with default settings."),
+    $this->assertTrue(
+      empty($object->uuid),
+      t("Node has no uuid field attached with default settings."),
       t("Node UUID")
     );
-    $this->assertFalse(
-      isset($object->revision_uuid),
-      t("Node has not revision_uuid field attached with default settings."),
+    $this->assertTrue(
+      empty($object->revision_uuid),
+      t("Node has no revision_uuid field attached with default settings."),
       t("Node revision UUID")
     );
 
@@ -170,14 +170,14 @@ class UUIDFunctionalityTestCase extends 
     node_save($object);
 
     // Verify fields are not attached to the node.
-    $this->assertFalse(
-      isset($object->uuid),
-      t("Node has not uuid field attached with default settings."),
+    $this->assertTrue(
+      empty($object->uuid),
+      t("Node has no uuid field attached with default settings."),
       t("Node UUID")
     );
-    $this->assertFalse(
-      isset($object->revision_uuid),
-      t("Node has not revision_uuid field attached with default settings."),
+    $this->assertTrue(
+      empty($object->revision_uuid),
+      t("Node has no revision_uuid field attached with default settings."),
       t("Node revision UUID")
     );
 
@@ -193,9 +193,9 @@ class UUIDFunctionalityTestCase extends 
     $object = $this->drupalCreateUser();
 
     // Verify fields are not attached to the node.
-    $this->assertFalse(
-      isset($object->uuid),
-      t("User has not uuid field attached with default settings."),
+    $this->assertTrue(
+      empty($object->uuid),
+      t("User has no uuid field attached with default settings."),
       t("User UUID")
     );
   }
@@ -240,14 +240,14 @@ class UUIDFunctionalityTestCase extends 
     $object = $this->drupalCreateNode($options);
 
     // Verify fields are not attached to the node.
-    $this->assertFalse(
-      isset($object->uuid),
-      t("Node has not uuid field attached with disabled settings."),
+    $this->assertTrue(
+      empty($object->uuid),
+      t("Node has no uuid field attached with disabled settings."),
       t("Node UUID")
     );
-    $this->assertFalse(
-      isset($object->revision_uuid),
-      t("Node has not revision_uuid field attached with disabled settings."),
+    $this->assertTrue(
+      empty($object->revision_uuid),
+      t("Node has no revision_uuid field attached with disabled settings."),
       t("Node revision UUID")
     );
 
@@ -256,14 +256,14 @@ class UUIDFunctionalityTestCase extends 
     node_save($object);
 
     // Verify fields are not attached to the node.
-    $this->assertFalse(
-      isset($object->uuid),
-      t("Node has not uuid field attached with default settings."),
+    $this->assertTrue(
+      empty($object->uuid),
+      t("Node has no uuid field attached with default settings."),
       t("Node UUID")
     );
-    $this->assertFalse(
-      isset($object->revision_uuid),
-      t("Node has not revision_uuid field attached with default settings."),
+    $this->assertTrue(
+      empty($object->revision_uuid),
+      t("Node has no revision_uuid field attached with default settings."),
       t("Node revision UUID")
     );
 
@@ -283,9 +283,9 @@ class UUIDFunctionalityTestCase extends 
     $object = $this->drupalCreateUser();
 
     // Verify fields are not attached to the node.
-    $this->assertFalse(
-      isset($object->uuid),
-      t("User has not uuid field attached with disabled settings."),
+    $this->assertTrue(
+      empty($object->uuid),
+      t("User has no uuid field attached with disabled settings."),
       t("User UUID")
     );
   }
@@ -306,7 +306,11 @@ class UUIDFunctionalityTestCase extends 
 
   /**
    * Verify uuid behavior with enabled settings. All settings are forced to
-   * enabled, so new 'entities' should get an uuid assigned.
+   * enabled, so new 'entities' should get a uuid assigned.
+   *
+   * Note that there have been issues with the uuid values the node object
+   * after saving not necessarily reflecting what's in the database, so check
+   * with a node_load().
    */
 
   /**
@@ -350,6 +354,7 @@ class UUIDFunctionalityTestCase extends 
     // Create a new revision for this node.
     $object->revision = 1;
     node_save($object);
+    $loaded_node = node_load($object->nid, NULL, TRUE);
 
     // Verify fields are attached to the node.
     $this->assertIsUUID(
@@ -371,12 +376,44 @@ class UUIDFunctionalityTestCase extends 
       t("Node UUID")
     );
     $this->assertNotEqual(
-      $object->uuid,
-      $node->uuid,
+      $object->revision_uuid,
+      $node->revision_uuid,
       t("Node revision uuid is being updated successfully."),
       t("Node revision UUID")
     );
 
+    // Verify altered object reflects what's really in the database
+    $this->assertEqual(
+      $object->uuid,
+      $loaded_node->uuid,
+      t("Node uuid is being returned correctly"),
+      t("Node UUID")
+    );
+    $this->assertEqual(
+      $object->revision_uuid,
+      $loaded_node->revision_uuid,
+      t("Node revision uuid is being returned correctly"),
+      t("Node revision UUID")
+    );
+
+    // Replace the UUID
+    $new_uuid = uuid_uuid();
+    $object->uuid = $new_uuid;
+    node_save($object);
+    $loaded_node = node_load($object->nid, NULL, TRUE);
+    $this->assertEqual(
+      $object->uuid,
+      $new_uuid,
+      t("Node uuid is being changed correctly"),
+      t("Node UUID")
+    );
+    $this->assertEqual(
+      $object->uuid,
+      $loaded_node->uuid,
+      t("Node uuid is being returned correctly"),
+      t("Node UUID")
+    );
+
     // Show current node only in verbose mode.
     $this->verbose(print_r($node, 1));
   }
