Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-14510

CiviMember Roles Sync for Drupal 7 does not remove roles when membership deleted

    Details

      Description

      The Drupal 7 version of CiviMember Roles Sync does not remove the relevant roles from a user when a membership is deleted.

      I tracked this down to a query that was incorrectly ported from the Drupal 6 version to DBTNG for Drupal 7.

      Drupal 6 version:
      civicrm-4.4.5-drupal6 civicrm_member_roles.module, lines 509-512 (also 518-521):

      if (is_array($rid))

      { $rid = implode(",", $rid); }
      db_query('DELETE FROM {users_roles} WHERE uid = ' . $uid . ' AND rid IN( ' . $rid . ' )');

      This was ported to D7 as:
      civicrm-4.4.5-drupal civicrm_member_roles.module, lines 528-531 (also 536-539):

      if (is_array($rid)) { $rid = implode(",", $rid); }

      db_delete('users_roles')>condition('uid', $uid)>condition('rid', $rid)->execute();

      The problem with that is that the default operator for condition() is '=' if the supplied value is not an array. Which it isn't, because $rid has just been turned from an array to a comma-separated string. So, if $rid has more than one value, the condition becomes something like " rid = '1, 2, 3' ", which never matches because rid is an integer field.

      The attached patch against 4.4.5-drupal (D7) fixes it for me.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                kurund Kurund Jalmi
                Reporter:
                davej Dave Jenkins
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: