CRM-3015 CiviCRM does not correctly use drupal's hook_user

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.1
    • Component/s: Core CiviCRM
    • Labels:
      None

      Description

      As noted above the function:

      • Note that we ignore the edit field and do not follow the drupal protocol
      • of extracting values from the edit field. We extract the fields directly
      • from $_POST. This is because the underlying form package that we use
      • (HTML_QuickForm) does the form value extraction and validation.

      However this incorrectly assumes that the use object is only modified via the user account form. Several modules modify the user object directly via user_save. CiviCRM's implementation of hook_user does not follow the rules for the $edit argument, and thus does not update the email address when altered programatically (without the account form).

        Attachments

          Activity

          [CRM-3015] CiviCRM does not correctly use drupal's hook_user
          dave hansen-lange added a comment -

          Note also that most values for $op do not require civicrm to return anything. CiviCRM performs needless extra form building that is not necessary in most circumstances.

          Donald A. Lobo added a comment -


          any thoughts on how to potentially go about fixing this, specifically with regard to drupal 6. our knowledge is a bit limited in this case and help / patches would be greatly appreciated

          Donald A. Lobo added a comment -

          $_POST and QF protocol basically are intertwined with each other. changing this is a fairly large project and hence pushing it to the next release

          dave hansen-lange added a comment -

          Also related is an issue with hooks. The edit hooks are not firing if the user changes their Drupal email address, despite the fact that the email is updated in civicrm.

          dave hansen-lange added a comment -

          This issue started popping up in other places for me and I realized that the fix actually isn't that difficult. This patch adds checks to see if the user is on the profile edit form. If so it behaves in the old way, using those wacky qf forms. Otherwise hook_user must be being called via the drupal API function user_save(). In this case if the op is 'insert', then we create a CiviCRM contact with

          CRM_Core_BAO_UFMatch::synchronize($user, false, 'Drupal', civicrm_get_ctype('Individual'));

          if the op is 'update' we can do

          if (isset($edit['mail']) && $edit['mail'] != $user->mail)

          { require_once 'CRM/Core/BAO/UFMatch.php'; $contactId = CRM_Core_BAO_UFMatch::getContactId($user->uid); CRM_Core_BAO_UFMatch::updateContactEmail($contactId, $edit['mail']); }

          Easy breezy.

          The only thing that this patch doesn't address is that CiviCRM is needlessly generating html for a lot of ops that don't require a return variable. But that can be something for another day.

          I don't think hook_user has changed in Drupal 6 so this should still work as expected.

          Donald A. Lobo added a comment -


          thanx for the patch

            People

            • Assignee:
              Donald A. Lobo
              Reporter:
              dave hansen-lange

              Dates

              • Created:
                Updated:
                Resolved: