Applying the Updates

Applying Updates

The syncit.php script performs the actual work of updating the membership list, as follows:

  1. For each line in the membership-list.csv file:
    1. Save the fields in an array.
    2. Increment a counter for the first/last name pair (see Duplicate Names below)
  2. Create a map of existing IAC numbers to Drupal User IDs (UIDs) by:
    1. Running a SQL query that joins the profile and field_data_field_iac_number tables, filters out "special" Drupal accounts (see IAC Numbers), and returns IAC Number / UID pairs
    2. Traversing the query result, appending each IAC Number / UID pair to an associative array
  3. Traverse the rows stored in 1.1 above as follows:
    1. If the associative array indicates that we already have a record with the same IAC number in our database...
      1. We check to see if any EAA-supplied fields differ from the data in our database, and
      2. If so, update our database accordingly.
      3. Note: As of June 2015, EAA has started to replace email addresses that 'bounce' with a blank string. If/when that happens, we retain the old address for the sake of Drupal uniqueness. If we start doing regular email blasts we should add a flag to skip known bad addresses.
      4. Note: Some fields (e.g. first and last names and email addresses) are stored in the user record, while others (e.g. the IAC number and zip code) are stored in the profile record.
    2. Otherwise this is a new user to us, so add a user and profile record.
      1. If the EAA-supplied member record lacks an email address, we must generate one because Drupal requires that every user have a unique email address. The only unique field we can count on is the IAC number, therefore auto-generated email addresses will be in the form: <iacnum>@ignore.iac.org, where <iacnum> is the member's IAC number.
      2. If the EAA-supplied email address is already in the database, output an error message and skip the member record.
      3. Send the user an email stating that their account is now active, with instructions on how to log in.

Duplicate Names

As of this writing, the IAC membership list has about sixty members whose first and last names match those of another member. Unfortunately, Drupal user names (e.g. John Smith) must be unique. Therefore we need to de-conflict the duplicates.

Per paragraph 1b above, the script maintains a count of how many times it encounters a given first/last name pair in the EAA download file. When manipulating a user record, we check that counter. If its value is 1, we simply combine the first and last names. If the value is greater than one, we also append the member's IAC number in parentheses, e.g. John Smith (12345). While this approach has some minor drawbacks in terms of the end user experience, it's the best automated solution I could think of.