Using role-names instead of ids caused problems with other languages

guldi - April 24, 2009 - 13:15
Project:Invite
Version:6.x-2.0-alpha1
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:duplicate
Description

I had some irregularities with proper assigning of the maximum invites allowed to send by role.
After reviewing the code, I found the bug.

In invite_get_role_limit, we compare the names of $account->roles with names of the results user_roles().
As long as we use only English, this is not a problem. Although the version with $role_no_space is not very nice.
But when we use another language than English, we compare the translated role-names of $account-roles with the untranslated ones of user_roles().

My suggestion: let's use the roles id's instead of the names.
I tried to change every position where the names were used to the id-using behaviour.

AttachmentSize
invite.module.patch1.6 KB
invite_admin.inc_.patch1.99 KB

#1

guldi - May 5, 2009 - 10:18

Could someone please have a look at this?

#2

smk-ka - May 5, 2009 - 12:17

This looks good to me except that the default target role setting was lost, so I've put it back in.
All we need now is an update function that performs the role names to rid conversion.

AttachmentSize
invite-role_ids.patch 5.09 KB

#3

guldi - May 11, 2009 - 14:45

This should be it.

Would be glad if you could check it...

<?php
  $result
= db_query('SELECT * FROM {role} ORDER BY name');
    while(
$role = db_fetch_object($result)) {
       
$role_no_space = str_replace(' ', '_', t($role->name));
       
$query1 = db_query("UPDATE {variable} SET name='%s' WHERE name='%s'",'invite_maxnum_'.$role->rid,'invite_maxnum_'.$role_no_space);
       
$query2 = db_query("UPDATE {variable} SET name='%s' WHERE name='%s'",'invite_target_role_'.$role->rid,'invite_target_role_'.$role_no_space);
    }
?>

#4

guldi - July 2, 2009 - 09:05

what's the state here??

#5

andypost - July 25, 2009 - 02:36
Status:needs review» duplicate

Same patch :) but with upgrade path
http://drupal.org/node/322748#comment-1850916

 
 

Drupal is a registered trademark of Dries Buytaert.