Answers.Body: <p>What you've found is that the error appears whenever your sync runsTwo things:</p>
  
  <ol>
  <li>This is a PHP notice, which is a very low-importance message to receive.  Nothing is breaking; this is just something to say that something mildly improper is going on in the code.  Notices like this are actually something you should suppress on a production site: in the Drupal menu, go to <strong>Configuration</strong>, then under Development click <strong>Logging and Errors</strong>.  Select <code>none</code> under Error messages to display.  That will make the error quit appearing on screen, but it will still probably appear in your log, so it's worth getting to the bottom of it.</li>
  <li>It does reflect an actual bug (albeit small) in CiviCRM's code.  Basically, <a href="https://github.com/civicrm/civicrm-drupal/blob/7.x-4.4.6.x/modules/civicrm_member_roles/civicrm_member_roles.module#L541" rel="nofollow">this line</a> of code asks whether the item in the <code>$memberroles</code> array for a contact's membership's membership type is an array.  Well, it's possible that the <code>$memberroles</code> array doesn't have an item for that membership type: it's only <a href="https://github.com/civicrm/civicrm-drupal/blob/7.x-4.4.6.x/modules/civicrm_member_roles/civicrm_member_roles.module#L463" rel="nofollow">populated</a> with the membership types for which you've got sync rules set up.  Apparently, in your case, at least someone has a membership of a type that doesn't sync with a Drupal role.  This is normal and okay; the code just doesn't consider this situation.</li>
  </ol>
  
  <p>Apparently, the problem <a href="https://github.com/civicrm/civicrm-drupal/blob/7.x-master/modules/civicrm_member_roles/civicrm_member_roles.module#L564" rel="nofollow">still exists</a> in the development version of the code.  Please <a href="https://issues.civicrm.org/" rel="nofollow">log in at issues.civicrm.org</a> and log an issue for this.  The fix will take no time, but it's good to have a record of the bug there.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-18T03:45:24.033Z
Answers.LastActivityDate: 2015-09-18T03:45:24.033Z
Answers.UserDisplayName: Andie Hunt
Body: <p>I'm using drupal 7 with CiviCRM 4.4.6.  </p>
  
  <p>I'm using CiviMember Roles Sync with below Association Rules:  </p>
  
  <p>Rule ID: 3<br>
  "CiviMember Membership Type" --> "Drupal Role": Member (PG) --> member<br>
  Current Codes: New, Current<br>
  Expired Codes: Grace, Expired, Pending, Cancelled, Deceased</p>
  
  <p>Rule ID: 4<br>
  "CiviMember Membership Type" --> "Drupal Role": Member (KK) --> member<br>
  Current Codes: New, Current<br>
  Expired Codes: Grace, Expired, Pending, Cancelled, Deceased</p>
  
  <p>In setting "Automatic Synchronization Method", I select "Synchronize whenever a user logs in or logs out."  </p>
  
  <p>When user login, error appear as below:</p>
  
  <blockquote>
    <p>Notice: Undefined index: 4 in _civicrm_member_roles_sync() (line 541
    of
    /home/warrior/www/beta/sites/all/modules/civicrm/drupal/modules/civicrm_member_roles/civicrm_member_roles.module).</p>
  </blockquote>
  
  <p>Here are drupal user roles available on my site:  </p>
  
  <p>ID 3: Web Developer<br>
  ID 4: Content &amp; Membership<br>
  ID 5: member<br>
  ID 6: Membership Admin  </p>
  
  <p>I tried to change "Automatic Synchronization Method", but the error still appears.<br>
  When I change to "Synchronize when membership is updated", error appears after payment made (membership updated).<br>
  When I change to "Synchronize when Drupal cron is ran", error appears when I run cron.</p>
  
  <p>Any idea how to solve this error?</p>
  
Tags: <drupal><civimember><roles>
Title: Undefined index in civicrm_member_roles_sync
ThreadText: # Undefined index in civicrm_member_roles_sync
  
  (Asked by: username_0 on 2015-09-18)
  
  I'm using drupal 7 with CiviCRM 4.4.6.
  
  I'm using CiviMember Roles Sync with below Association Rules:
  
  Rule ID: 3  
  "CiviMember Membership Type" --> "Drupal Role": Member (PG) --> member  
  Current Codes: New, Current  
  Expired Codes: Grace, Expired, Pending, Cancelled, Deceased
  
  Rule ID: 4  
  "CiviMember Membership Type" --> "Drupal Role": Member (KK) --> member  
  Current Codes: New, Current  
  Expired Codes: Grace, Expired, Pending, Cancelled, Deceased
  
  In setting "Automatic Synchronization Method", I select "Synchronize whenever a user logs in or logs out."
  
  When user login, error appear as below:
  
  > Notice: Undefined index: 4 in \_civicrm\_member\_roles\_sync() (line 541
  > of
  > /home/warrior/www/beta/sites/all/modules/civicrm/drupal/modules/civicrm\_member\_roles/civicrm\_member\_roles.module).
  
  Here are drupal user roles available on my site:
  
  ID 3: Web Developer  
  ID 4: Content & Membership  
  ID 5: member  
  ID 6: Membership Admin
  
  I tried to change "Automatic Synchronization Method", but the error still appears.  
  When I change to "Synchronize when membership is updated", error appears after payment made (membership updated).  
  When I change to "Synchronize when Drupal cron is ran", error appears when I run cron.
  
  Any idea how to solve this error?
  
  **Tags:** drupal, civimember, roles
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-09-18. Score: 2 | Accepted answer
  
  What you've found is that the error appears whenever your sync runsTwo things:
  
  1. This is a PHP notice, which is a very low-importance message to receive. Nothing is breaking; this is just something to say that something mildly improper is going on in the code. Notices like this are actually something you should suppress on a production site: in the Drupal menu, go to **Configuration**, then under Development click **Logging and Errors**. Select `none` under Error messages to display. That will make the error quit appearing on screen, but it will still probably appear in your log, so it's worth getting to the bottom of it.
  2. It does reflect an actual bug (albeit small) in CiviCRM's code. Basically, [this line](https://github.com/civicrm/civicrm-drupal/blob/7.x-4.4.6.x/modules/civicrm_member_roles/civicrm_member_roles.module#L541) of code asks whether the item in the `$memberroles` array for a contact's membership's membership type is an array. Well, it's possible that the `$memberroles` array doesn't have an item for that membership type: it's only [populated](https://github.com/civicrm/civicrm-drupal/blob/7.x-4.4.6.x/modules/civicrm_member_roles/civicrm_member_roles.module#L463) with the membership types for which you've got sync rules set up. Apparently, in your case, at least someone has a membership of a type that doesn't sync with a Drupal role. This is normal and okay; the code just doesn't consider this situation.
  
  Apparently, the problem [still exists](https://github.com/civicrm/civicrm-drupal/blob/7.x-master/modules/civicrm_member_roles/civicrm_member_roles.module#L564) in the development version of the code. Please [log in at issues.civicrm.org](https://issues.civicrm.org/) and log an issue for this. The fix will take no time, but it's good to have a record of the bug there.
  
  
  ---
  
  