Here you can find a patch that offers an administration interface to assign users and/or specific content types and/or choosen vocabularies.

Other modules that may need to implements UUID for their own contents can use:

uuid_create_uuid($oid, $object, $module = 'uuid')
Store a new UUID in the database
uuid_get_uuid($oid, $object, $module = 'uuid')
Retrieve an existing UUID from the database

The function used for creating UUID was taken from the patch suggested by anachivist (http://drupal.org/node/502622#comment-1858190)

The administration panel can be reached here: admin/settings/uuid.

When using the patch, you can delete uuid_node.inc and uuid_user.inc and you have to add the file uuid.admin.inc (@see the ZIP archive).

The ZIP archive contains the entire module.

Comments

b-prod’s picture

I forgot: the module implements some hooks of the token module (http://drupal.org/project/token).

The token is [uuid-raw] for all objects (node type, user and taxonomy).

recidive’s picture

Status: Patch (to be ported) » Needs work

Hi, thanks for your patch.

Unfortunately, I think your patch was taken against old HEAD code. I've just synced HEAD with DRUPAL-6 branch.

Some of your changes already exist in DRUPAL-6 (and now in HEAD too) like the ability to set which node types should have UUID auto-generated.

The uuid_node.inc and uuid_user.inc don't exist since long time ago.

Can you elaborate on your one-table table approach to store UUIDs for all entities? What it buy us?

I'd appreciate if you cold split your patch by functionality, since there are other issues for some of what you are proposing here, see #502622: UUID() is a non-deterministic function and breaks with replication and #324712: Support Token module. You can concentrate this issue maybe in the database stuff. This is not critical though, since I can as well commit your entire patch. But things like UUID generation need more thought IMO, see discussion in that issue.

Please make another patch so I can review better.

Thanks again.

b-prod’s picture

StatusFileSize
new3.67 KB
new26.65 KB

Hi!

Sorry, I never used CVS before.

I have created a new patch. In it, UUIDs are generated with UUID() for MySQL and PgSQL >= 8.4. For PgSQL < 8.4 (UUID() is not implemented), I use the function suggested by anarchist (#502622: UUID() is a non-deterministic function and breaks with replication)

The main differences are:

  • There is only one table in database
  • UUID are automatically synchronized when any type of Drupal object is enabled, or when the module itself is enabled
  • UUID supports taxonomy

I didn't add token and views support to current patch. I will send these patches when you will have reviewed and adapted the code.

There is also the fr.po translation file.

recidive’s picture

-  $types = node_get_types('names');
-  $form['content']['uuid_automatic_for_nodes'] = array(
-    '#type' => 'checkboxes',
-    '#title' => t('Content Types With Automatic UUIDs'),
-    '#default_value' => variable_get('uuid_automatic_for_nodes', array()),
-    '#options' => $types,
-    '#description' => t('Selected content types to have UUIDs automatically generated.'),
-    '#required' => FALSE,
-  );
+  
+  if ($options = node_get_types('names')) {
+    $form['node']['uuid_automatic_for_nodes'] = array(
+      '#type' => 'checkboxes',
+      '#title' => t('Content types with automatic UUIDs'),
+      '#default_value' => variable_get('uuid_automatic_for_nodes', array()),
+      '#options' => $options,
+      '#description' => t('Selected content types to have UUIDs automatically generated.'),
+      '#required' => FALSE,
+    );
+  } else {
+    $form['node']['uuid_automatic_for_nodes'] = array(
+      '#type' => 'item',
+      '#value' => t('There is currently no content type defined.'),
+    );
+  }

Your changes above does essentially the same as the current code, you can strip that out.

-    '#title' => t('Automatic UUIDs For Users?'),
+    '#title' => t('Automatic UUIDs for users?'),

Please avoid that kind of changes as they do nothing besides making it hard to read the patch.

+  $form['taxonomy'] = array(
     '#type' => 'fieldset',
-    '#title' => t('General Settings'),
-  );
-  $form['settings']['sync'] = array(
-    '#type' => 'submit',
-    '#value' => t('Create Missing UUIDs'),
-    '#submit' => array('uuid_sync'),
-    '#weight' => 10,
-  );
-  $form['settings']['rebuild_help'] = array(
-    '#value' => '<div class="description">' . t("If UUID settings have changed recently some content or users may be missing their UUIDs.") . '</div>',
-    '#weight' => 11,
+    '#title' => t('Taxonomy UUID Settings'),
   );

You are removing important code here, that's probably not what you want.

The uuid_sync() is too much hardcoded for nodes, users and taxonomy, maybe it's time to make this a pluggable system by adding some hooks for other modules to extend functionality.

 /**
  * Implementation of hook_uninstall().
  */
 function uuid_uninstall() {
-  variable_del('uuid_automatic_for_nodes');
-  variable_del('uuid_automatic_for_users');
-
-  // Remove tables.
   drupal_uninstall_schema('uuid');
 }

You are removing code that delete module setting on unistallation instead of adding code to remove your new settings.

Can you explain why your 1-table-only approach for storing UUIDs is better than a table for each entity? This can have performance impact e.g. when you have 1M users and 1M nodes, the query will need to search 2M items instead of 1M.

Also, it would help if you can remove the UUID generation stuff from your patch as this is being developed in the other issue.

Tip, taking a patch is not just a matter of replacing module files with your files and taking the patch, what you need to do instead is to take a patch against the code you used as base for doing your changes, and selectively, manually apply to the newer code, then take a patch from it. Also a patch that touches every part of the code is less likely to get commited, since one can agree with part of your code only, and the other part will hold this back. Try to split your patches by functionality. I know this can be tedious, but it's a good way to learn how to make good patches.

Thanks for you contributions!

b-prod’s picture

Status: Needs work » Needs review
StatusFileSize
new2.05 KB

Add support of taxonomy (vocabulary + term).

recidive’s picture

Status: Needs review » Needs work

Hello, patch looks ok.

I'm just a bit concerned about using %s placeholder in table and column names in those two queries:

+  if (array_key_exists($type, $types) && in_array($array['vid'], variable_get('uuid_automatic_for_taxonomy', array()))) {
+    switch ($op) {
+      case 'insert':
+        $uuid = (isset($array['uuid']) && uuid_is_valid($array['uuid'])) ? $array['uuid'] : uuid_uuid();
+        db_query("INSERT INTO {%s} (%s, uuid) VALUES (%d, '%s')",
+          $types[$type]['table'], $types[$type]['colname'], $array[$types[$type]['colname']], $uuid);
+        break;
+      case 'delete':
+        db_query('DELETE FROM {%s} WHERE %s = %d',
+          $types[$type]['table'], $types[$type]['colname'], $array[$types[$type]['colname']]);
+        break;
+    }
+  }

I think it's safer to just concatenate table name/column name instead e.g. changing from {%s} to {' . $types[$type]['table'] . '}.

Also, don't you think 'colname' should be renamed to 'field' just to be inline with schema?

b-prod’s picture

StatusFileSize
new1.93 KB

Hi!

I have modified the patch to match your request. You're right, it is more clear like that.

I also corrected the query because uuid_uuid() function is defined in another patch (UUID() is a non-deterministic function and breaks with replication). For the moment we are only speaking about taxonomy so I still use MySQL UUID function.

b-prod’s picture

StatusFileSize
new1.92 KB

This is the correct patch. Patch above use a '$field' key: it is a mistake.

recidive’s picture

Status: Needs work » Needs review

Hi, the patch looks good.

It's missing update function to create the uuid_vocabulary and uuid_term_data tables.

I'd like to commit this but don't have time to test this now.

I'm moving this to needs review in the hope to get some test.

@B-Prod, can you work with some one else to test this for us?

Thank you.

b-prod’s picture

StatusFileSize
new4.59 KB

Hi!

Here is a patch which implements hook_update() and adds checkboxes in UUID UI to select which vocabularies to associate with UUID.

ayalon’s picture

What about views argument support? Will this be ever implemented?

It's a bit sad, that this patch never was commited.

recidive’s picture

@ayalon can you test patch in #10 and see if it still applies and work as expected? If so, please move issue status to RTBC and I'll do a final review and commit.

Thanks.

ayalon’s picture

Status: Needs review » Reviewed & tested by the community

Ok here are my test results:

1. Applied patch without an error to the latest version
2. Activated UUID for a certain vocabulary
3. Saved the settings
4. Updated missing entries
5. Checked the db for UUID -> Everything is there as expected, tables created, entries created

Now I wanted to deploy these UUID with the deploy module
1. Activated the module on the deploy server
2. Deployed a whole vocabulary
3. Checked the term UUID and the vocabulary UUID and -> HURRAY! They were the same!

My vote for commiting this patch!

recidive’s picture

Title: Implementation of UUID for nodes, users and taxonomy » Implementation of UUID for taxonomy
Status: Reviewed & tested by the community » Fixed

Commited to Drupal 6 dev branch. Thanks!

ayalon’s picture

StatusFileSize
new3.56 KB

In addition to this patch I also made a views integration:

It's now possible to pass a taxonomy UUID and a vocabulary UUID as a parameter.

It's also possible to sort and to display the values of taxonomy uuid and vocabulary uuid.

b-prod’s picture

Great!

recidive’s picture

@ayalon: could you open a new issue for your patch in #15?

Thanks!

Status: Fixed » Closed (fixed)

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