* @static
*/
static function synchronize(&$user, $update, $uf, $ctype, $isLogin = FALSE) {
- $config = CRM_Core_Config::singleton();
+ $userSystem = CRM_Core_Config::singleton()->userSystem;
$session = CRM_Core_Session::singleton();
if (!is_object($session)) {
CRM_Core_Error::fatal('wow, session is not an object?');
return;
}
- $userSystemID = $config->userSystem->getBestUFID($user);
- if ($config->userSystem->is_drupal) {
- $mail = 'mail';
- }
- elseif ($uf == 'Joomla') {
- $mail = 'email';
- }
- elseif ($uf == 'WordPress') {
- $mail = 'user_email';
- }
- else {
- CRM_Core_Error::statusBounce(ts('Please set the user framework variable'));
- }
+ $userSystemID = $userSystem->getBestUFID($user);
+ $uniqId = $userSystem->getBestUFUniqueIdentifier($user);
// if the id of the object is zero (true for anon users in drupal)
// have we already processed this user, if so early
return;
}
- $uniqId = $user->$mail;
-
$ufmatch = self::synchronizeUFMatch($user, $userSystemID, $uniqId, $uf, NULL, $ctype, $isLogin);
if (!$ufmatch) {
return;
function getTimeZoneString() {
return NULL;
}
+
+ /**
+ * Get Unique Identifier from UserFramework system (CMS)
+ * @param object $user object as described by the User Framework
+ * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
+ *
+ */
+ function getUniqueIdentifierFromUserObject($user) {}
+
/**
* Get User ID from UserFramework system (CMS)
* @param object $user object as described by the User Framework
*/
function getLoggedInUfID() {}
+ /**
+ * Get currently logged in user unique identifier - this tends to be the email address or user name.
+ *
+ * @return string $userID logged in user unique identifier
+ */
+ function getLoggedInUniqueIdentifier() {}
+
/**
* return a UFID (user account ID from the UserFramework / CMS system being based on the user object
* passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
*
* Note there is already a function getUFId which takes $username as a param - we could add $user
* as a second param to it but it seems messy - just overloading it because the name is taken
- * @param string $user
+ * @param object $user
* @return int $ufid - user ID of UF System
*/
function getBestUFID($user = NULL) {
}
return $this->getLoggedInUfID();
}
+
+ /**
+ * return a unique identifier (usually an email address or username) from the UserFramework / CMS system being based on the user object
+ * passed, defaulting to the logged in user if not passed. Note that ambiguous situation occurs
+ * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the unique identifier before calling
+ * the function
+ *
+ * @param object $user
+ * @return string $uniqueIdentifier - unique identifier from the UF System
+ */
+ function getBestUFUniqueIdentifier($user = NULL) {
+ if($user) {
+ return $this->getUniqueIdentifierFromUserObject($user);
+ }
+ return $this->getLoggedInUniqueIdentifier();
+ }
}
function getUserIDFromUserObject($user) {
return !empty($user->uid) ? $user->uid : NULL;
}
+
+ /**
+ * Get Unique Identifier from UserFramework system (CMS)
+ * @param object $user object as described by the User Framework
+ * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
+ *
+ */
+ function getUniqueIdentifierFromUserObject($user) {
+ return empty($user->mail) ? NULL : $user->mail;
+ }
+
+ /**
+ * Get currently logged in user unique identifier - this tends to be the email address or user name.
+ *
+ * @return string $userID logged in user unique identifier
+ */
+ function getLoggedInUniqueIdentifier() {
+ global $user;
+ return $this->getUniqueIdentifierFromUserObject($user);
+ }
}
return ($user->guest) ? NULL : $user->id;
}
+ /**
+ * Get currently logged in user unique identifier - this tends to be the email address or user name.
+ *
+ * @return string $userID logged in user unique identifier
+ */
+ function getLoggedInUniqueIdentifier() {
+ $user = JFactory::getUser();
+ return $this->getUniqueIdentifierFromUserObject($user);
+ }
/**
* Get User ID from UserFramework system (Joomla)
* @param object $user object as described by the CMS
return !empty($user->id) ? $user->id : NULL;
}
+ /**
+ * Get Unique Identifier from UserFramework system (CMS)
+ * @param object $user object as described by the User Framework
+ * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
+ *
+ */
+ function getUniqueIdentifierFromUserObject($user) {
+ return ($user->guest) ? NULL : $user->email;
+ }
+
/**
* Get a list of all installed modules, including enabled and disabled ones
*
return $isloggedIn;
}
+ function getLoggedInUserObject() {
+ if (function_exists('is_user_logged_in') &&
+ is_user_logged_in()) {
+ global $current_user;
+ }
+ return $current_user;
+ }
/**
* Get currently logged in user uf id.
*
*/
public function getLoggedInUfID() {
$ufID = NULL;
- if (function_exists('is_user_logged_in') &&
- is_user_logged_in()
- ) {
- global $current_user;
- $ufID = $current_user->ID;
- }
- return $ufID;
+ $current_user = $this->getLoggedInUserObject();
+ return isset($current_user->ID) ? $current_user->ID : NULL;
+ }
+
+ /**
+ * Get currently logged in user unique identifier - this tends to be the email address or user name.
+ *
+ * @return string $userID logged in user unique identifier
+ */
+ function getLoggedInUniqueIdentifier() {
+ $user = $this->getLoggedInUserObject();
+ return $this->getUniqueIdentifierFromUserObject($user);
}
/**
return !empty($user->ID) ? $user->ID : NULL;
}
+ /**
+ * Get Unique Identifier from UserFramework system (CMS)
+ * @param object $user object as described by the User Framework
+ * @return mixed $uniqueIdentifer Unique identifier from the user Framework system
+ *
+ */
+ function getUniqueIdentifierFromUserObject($user) {
+ return empty($user->user_email) ? NULL : $user->user_email;
+ }
+
/**
* Get user login URL for hosting CMS (method declared in each CMS system class)
*