tags:

views:

523

answers:

3

I am developing a site that is saving non visible user data upon login (e.g. external ID on another site). We are going to create/save this data as soon as the account is created.

I could see us saving data using

  1. the content profile module (already in use on our side)
  2. the profile module
  3. the data column in the user table
  4. creating our own table

I feel like #1 is probably the most logical place, however creating a node within a module does not seem to be a trivial thing.

#3 feels like a typical way to solve this, but just having a bunch of serialized data in a catchall field does not feel like the best design.

Any suggestions?

A: 

I would go for option 3. Eventually even other modules will store the data in the database against a user. So you could directly save it yourself probably in a more efficient way than those modules.

Of course depending on the size of the data, you can take a call whether to add a new column in the users table or to create a new table for your data with the user's id as the foreign key.

Srirangan
The dis-advantage of the data column is that it simply stores a serialized array, which can't be directly queried against using something like Views. For the use-case above, that may be fine, but it's worth mentioning.Methods 1, and 2 will work with Views, method 4 can work with views, but would require an additional step of telling views about the new table.
jhedstrom
A: 

If you're already using the Content Profile module, then I'd really suggest continuing to use it and attach the field to it. You're saving the data when the account is created, and creating a node for the user at the same time isn't that hard. Really.

$node = new stdClass();
$node->title = $user->name; // what I'd use, or you can have node auto title handle the title for you.  Up to you!
$node->field_hidden_field[0]['value'] = '$*#$f82hff';
$node->uid = $user->uid;
node_save($node);

Bob's your uncle!

John Fiala
+3  A: 

IMO, each option has its pro's and con's, and you should be the one to make the final call, given that you are the only one to know what your project is about, what are the critical points of the project, what is the expected typical user pattern, what are the resources available, etc...

If I was totally free to chose, my personal favourites would be option #4, #1 and #5 (wait! #5? Yes: see below!). My guiding principles in making the choice would be:

  • Keep it clean
  • Keep it simple
  • Make it extensible

#1 - The content profile module

This would be a clean solution in that you would make easier for developer to maintain your code, as all the alteration to the user would pass through the same channel, and it would be easier to track down problems or add new functionality.

I do not find it particularly simple as it requires you to interact with the custom API of that module.

As for extensibility that depends from how well the content profile module API is designed. The temptation could be to simply use the tables done by said module for your purpose, bypassing the API's but that exposes you to the possibility that on a critical security update one day in which you are in a hurry the entire system will break down because the schema has changed...

#4 - Creating your own table

This would be a clean solution because you could design your table (and your module to do exactly what you need to), and you could create your own API to be used by other modules. On the other hand you would introduce yet another piece of code altering the registration process, and this might make it more difficult for devs to track problems and expand the system in a consistent way.

This would be very simple to implement code-wise. Also the DB design would benefit though: another thing to consider is that the tables would be very easy to inspect and query. Creating a new handler for views is dead easy in most of the cases: 4 out of 5 you simply use one of the prototype objects shipping with views.

This would be extremely easy to extend, of course. Once you created the module for one field, you could manage as many as you want by mostly copy/pasting the code for one field to another (or to inherit from the same ancestor if you go OOP).

I understand you are already knowledgeable about drupal, but if you need a pointer on how to do that, I gave some direction in this other answer.

#5 - Creating your own table and porting already existing fields there

That would essentailly be #4 minus the drawback of scattering functionality across various modules... Of course if you are already managing 200 fields the other way this is not a viable option, but if you are early into your design, you could consider this.

In my experience nearly every project that requires system integration (meaning: synchronising data for the same user in multiple systems) has custom needs for user registration, and I found this solution the one that suits my need best for two reasons:

  1. I found I reuse a lot of the custom code I wrote from project to project.
  2. It's the most flexible way to integrate data with the other system (in some case I even split data for the user in two custom tables managed by the same module: one that contains custom fields used by drupal only and one that contains the "non visible fields", as you call them. I find this very handy in a lot of scenarios, as it makes very easy to inspect and manipulate the data of the two systems separately.

HTH!

mac

related questions