}
if (!$found) {
- if ($config->userSystem->is_drupal) {
- $mail = 'mail';
- }
- elseif ($uf == 'WordPress') {
- $mail = 'user_email';
- }
- else {
- $mail = 'email';
- }
-
+ // Not sure why we're testing for this. Is there ever a case
+ // in which $user is not an object?
if (is_object($user)) {
- $params = array('email-Primary' => $user->$mail);
+ if ($config->userSystem->is_drupal) {
+ $primary_email = $uniqId;
+ }
+ elseif ($uf == 'WordPress') {
+ $primary_email = $user->user_email;
+ }
+ else {
+ $primary_email = $user->email;
+ }
+ $params = array('email-Primary' => $primary_email);
}
if ($ctype == 'Organization') {
return $modules;
}
+ /**
+ * @inheritDoc
+ */
+ public function getUniqueIdentifierFromUserObject($user) {
+ return $user->get('mail')->value;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getUserIDFromUserObject($user) {
+ return $user->get('uid')->value;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function synchronizeUsers() {
+ $config = CRM_Core_Config::singleton();
+ if (PHP_SAPI != 'cli') {
+ set_time_limit(300);
+ }
+
+ $users = array();
+ $users = \Drupal::entityTypeManager()->getStorage('user')->loadByProperties();
+
+ $uf = $config->userFramework;
+ $contactCount = 0;
+ $contactCreated = 0;
+ $contactMatching = 0;
+ foreach ($users as $user) {
+ $mail = $user->get('mail')->value;
+ if (empty($mail)) {
+ continue;
+ }
+ $uid = $user->get('uid')->value;
+ $contactCount++;
+ if ($match = CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $uid, $mail, $uf, 1, 'Individual', TRUE)) {
+ $contactCreated++;
+ }
+ else {
+ $contactMatching++;
+ }
+ if (is_object($match)) {
+ $match->free();
+ }
+ }
+
+ return array(
+ 'contactCount' => $contactCount,
+ 'contactMatching' => $contactMatching,
+ 'contactCreated' => $contactCreated,
+ );
+ }
+
}