Looking at the storm team schema, would it not be better to store the node id of each member rather than the string name of each node object added?

So your schema would be something like

$schema['stormteam'] = array(
  'fields' => array(
    'vid' => array(
      'type' => 'int',
      'not null' => TRUE,
      'default' => 0,
    ),
    'nid' => array(
      'type' => 'int',
      'not null' => TRUE,
      'default' => 0
    ),
    'mnid' => array(
      'type' => 'int',
      'not null' => TRUE,
      'default' => 0
    ),
  ),
  'primary key' => array(
    'vid',
    'nid',
    'mnid'
  ),
);

This would allow loading a list of how a user is related to other storm nodes that much easier. Ex: tasks, tickets, notes, etc...

For example, I wanted to create a View which loaded all assigned work to a user. Since an assignment can be done with both team nodes and person nodes, it would be simpler to just load the list of nodes a user belongs to (exclude the organization nids), and pass that along as a list of parameters to the "assigned_nid" field. Should load the whole list pretty quickly.

Currently, I'd have to explode the serialized strings, do a comparison on the name field, and then send back the node id. Can't really do that in SQL.

I realize this may involve a lot of changes to get this to work, but I think it might make loading information related to a single user that much easier. I'd be willing to help write the changes as well. I just want to see if this is something you'd consider changing first.

Thanks

P.S. Great module btw.

Comments

juliangb’s picture

Yes, I'd be happy with this, as long as the node still refers to a team rather than team member. if I understand correctly, in the dv, each row would now be a member hence multiple rows for a team.

minoroffense’s picture

That's exactly it.

Ok, I'll give it a go.

minoroffense’s picture

A few questions.

I'm trying to write the hook_update_n for this (map over old stormteam members to the new schema) and I'm a little stuck. In the serialize members array (as I understand it) you store the "fullname" value from the stormorg or stormperson who belongs to that team. Does that mean if I create a stormperson with the same name as another organization or another person that they'll become a member of the same team as the original?

Essentially, trying to map the users over, I want to ensure I map the right thing. Is there a uniqueness check somewhere when a stormperson/stormorganization is created to watch for duplicate names? The schemas for either stormperson or stormorganization don't have a "unique keys" marker on the fullname fields.

Or if I'm way off, let me know.

juliangb’s picture

I don't have the code in front of me right now, but did think it was done using nids in the serialised array. Full name values are really only cached there so that lists of team members can be created without doing full node loads on those.

minoroffense’s picture

Oh, ok. I see, you used the nids as the key and the fullname as the value. Gotcha.

Thanks for clarifying. I'll adjust the update function and then start testing the new code.

minoroffense’s picture

Status: Active » Needs review
StatusFileSize
new16.74 KB

Well here's my first go at the rewrite. It passes the same number of tests as the initial version I got from CVS so I figure that's a good sign.

One major change was the use of a "members" array instead of "members_array" to store the list of members in the node object. I changed all the occurrences of 'members_array' in the code.

I also changed all the code that tried to load the name from the 'members_array' and instead had it call node_load on the nid in the 'members' array. The Drupal cache should take care of unnecessary calls to the db to load that node object data.

Lastly, I switched up the form on the team edit page to be a select box instead of several drop downs. This was initially just to test the changes I made but then it grew on me. If you don't like it I can change it back. If you don't like the idea of someone have to know to ctrl click to select multiple options, maybe adding a jquery plugin to turn the select area into selectable checkboxes (see http://plugins.jquery.com/plugin-tags/checkbox-list)

Either way, have a look. Anything you don't like I can change.

Thanks

minoroffense’s picture

StatusFileSize
new16.77 KB

Here's another patch, should fix the exception in the previous one.

juliangb’s picture

Ok, I need to look at this in more detail with a screen bigger than an inch wide, but a few initial comments:

- Deprecated views handler can be removed
- Update function should start the 62xx series as this will go into the 6.x-2.x branch
- I was a bit confused about the update function. Is it really looking at the names?
- There are a couple of helper functions in the update function. If they are only called once, would it be clearer to keep all of the logic in the update function itself?

Its great to use a multi select for the members - how much work would it be to do this in a separate patch (an issue already exists) so these can be tested independently?

Are there downsides to not storing the name? For example when displaying in views?

minoroffense’s picture

1) I'll clean out the old file.

2) I'll adjust the version number

3) The update function is not looking at the names. It is in fact using the nids as you had mentioned. Initially, with my test database, when I unserialized team members, I was getting

1 => test1
2 => test2
3 => test3
etc..

So I assumed the indexes were just sequential numbers. You were right in your previous statement, you are using nids for the index numbers. It was just by coincidence that the data I had seemed sequential. So migrating team members is fairly straightforward.

4) I can compress it all into one function. It's just force of habit for me to break stuff up like that.

5) I can break it out into a separate patch. It'll take a little more time to adjust your existing form configuration to use the new members array element I introduced.

6) Because I'm using the node views handlers for the member node id field, it's a simple matter of adding a relationship to the member nodes and then assigning the display fields to use that relationship. It's actually better now since you can easily load anything, not just the names (pretty much the whole reason I suggested the change in the first place).
As for performance issues, Drupal is pretty good at keeping loaded node objects from being loaded more than once from the database if it doesn't need to. If there's a real concern for performance for that, adding a cache table for teams would be an option. But I really think the built in node cache should suffice.

I'll do what I can to get the changes you requested as soon as possible. I have some non-code related work to complete on a few on going projects this week but I'll get back to work on this by the weekend.

Thanks again

minoroffense’s picture

StatusFileSize
new10.1 KB

Alright, so here's the simplified patch.

All it does is change the schema, the views description for the tables and updates the stormteam.module file to handle the updated schema. The members_array and all that are in place as though nothing has changed.

Once again, this passes all the tests locally (we'll see about the testbot in a few).

Have a look, I think I've fixed everything you requested.

Thanks again for all your cooperation and patience.

juliangb’s picture

StatusFileSize
new11.05 KB

This patch has only minor changes from #10. Will commit if it passes the testbot check still.

juliangb’s picture

Title: Change schema on Storm Team module » Storm Team module schema
Category: feature » task
Status: Needs review » Fixed

Committed to 2.x.

carsten müller’s picture

Status: Fixed » Needs work

Hi,

i ran update.php and all teams are gone (on 3 different systems).

juliangb’s picture

Which Storm team tables are in the database, and do they contain the new or old structure?

Did update.php report any errors?

carsten müller’s picture

After the update the stormteam table has the new structure

Here the update messages

The following queries were executed
stormteam module
Update #6200

* CREATE TABLE {stormteam_6200} ( `vid` INT NOT NULL DEFAULT 0, `nid` INT NOT NULL DEFAULT 0, `mnid` INT NOT NULL DEFAULT 0, PRIMARY KEY (vid, nid, mnid) ) /*!40100 DEFAULT CHARACTER SET utf8 */ ENGINE=InnoDB
* DROP TABLE {stormteam}
* ALTER TABLE {stormteam_6200} RENAME TO {stormteam}

But afterwards there are only 17 rows in the table and no team is displayed in the teams list. We have over 100 Teams, but no one is left after the update

I 'll have a look at the code at the weekend ...

juliangb’s picture

Were these installations off the shelf storm, or did they have patches applied?

carsten müller’s picture

StatusFileSize
new9.16 KB

3 problems:

  • 1. nid and vid have to be changed in stormteam_update_6200(), because else the stormteam vis is used as stormteam nid after the update
  • 2. the second sql result overwrites the first of selecting all teams in stormteam_update_6200(). that is why all the teams are gone after the update
  • 3. in stormteam_list each team has to be selected only once. Because of the new structure each team nis is now multiple times in the table, not only once. A normal distinct in the query solves this problem

Here is the patch ...

juliangb’s picture

Status: Needs work » Needs review

Needs review, for testbot.

juliangb’s picture

Status: Needs review » Fixed

Committed to 2.x, thanks.

kfritsche’s picture

Status: Fixed » Needs review
StatusFileSize
new3.73 KB

Here another Patch, which fixes 3 forgotten positions which used old team schema.
These positions are:
storm.module - storm_get_assignment_options
stormteam.module - stormteam_access_sql, stormteam_storm_rewrite_where_sql
and a forgotten a in organization in stormteam_user_return_teams

juliangb’s picture

+++ stormteam/stormteam.module	21 Feb 2011 21:33:17 -0000
@@ -222,15 +222,16 @@ function stormteam_storm_rewrite_where_s
-      $cond = " WHEN 'stormteam' THEN (SELECT IF($cond,1,0) FROM {stormteam} ste1 WHERE ste1.vid=${primary_table}.vid) ";
+      $cond = " WHEN 'stormteam' THEN (SELECT DISTINCT 1 FROM {stormteam} ste1 WHERE ste1.vid=${primary_table}.vid AND ($cond)) ";

What is the reasoning behind this bit of the patch?

Powered by Dreditor.

kfritsche’s picture

For this line i needed about 1 hour to figure out, how to change this for the new table schema.
With the old SQL you get an MySQL error that the subselect returns more than one value ("Subquery returns more than 1 row query"), because ste1.vid=vid does not return one value anymore. So the condition moved to the where, to only select the specific entry. The DISTINCT is needed for the condition 'Storm team: view own' (uid=$uid), in this case you get every time all users from that team. If you are not in the team and do not created that team, it returns nothing and you do not select this team.
Works for me so far.
Error happens on db_query(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n LEFT JOIN {stormteam} s ON n.vid = s.vid WHERE n.status = 1 AND n.type="stormteam" ORDER BY title"));

juliangb’s picture

Status: Needs review » Reviewed & tested by the community

OK, makes sense. Will commit later.

kfritsche’s picture

something is still wrong with the function stormteam_access_sql (in stormteam.module).
On http://..../storm/teams it works, but on http://.../storm/tickets i got a mysql error

User warning: Unknown column 'ste.mnid' in 'where clause' query: SELECT n.nid FROM node n WHERE (n.language ='de' OR n.language ='' OR n.language IS NULL) AND ( (n.uid=82 OR ste.mnid = 1990) AND ('storm_access'='storm_access') AND ( n.type = 'stormteam' ) )ORDER BY n.title ASC in _db_query() (line 164 of /[...]/includes/database.mysqli.inc).

It have something todo with the filter, because i can't select any team. A look at the SQL statement, points out there is no join stormteam statement.

kfritsche’s picture

StatusFileSize
new3.62 KB

Error in my last Patch.
Here the last Patch with the fix.
I removed the join stormteam in storm.module, but is needed for the rewrite. sry for that...

juliangb’s picture

OK, assuming the testbot agrees, I will commit #25.

juliangb’s picture

Status: Reviewed & tested by the community » Fixed

Committed #25 to 2.x.

Status: Fixed » Closed (fixed)

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