CRM_Core_Error::fatal('wow, session is not an object?');
return;
}
+ $userSystemID = $config->userSystem->getBestUFID($user);
if ($config->userSystem->is_drupal) {
- $key = 'uid';
- $login = 'name';
$mail = 'mail';
}
elseif ($uf == 'Joomla') {
- $key = 'id';
- $login = 'username';
$mail = 'email';
- if (!isset($user->id) || !isset($user->email)) {
- $user = JFactory::getUser();
- }
}
elseif ($uf == 'WordPress') {
- $key = 'ID';
- $login = 'user_login';
$mail = 'user_email';
}
else {
$userID = $session->get('userID');
$ufID = $session->get('ufID');
- if (!$update && $ufID == $user->$key) {
+ if (!$update && $ufID == $userSystemID) {
return;
}
$isUserLoggedIn = CRM_Utils_System::isUserLoggedIn();
// reset the session if we are a different user
- if ($ufID && $ufID != $user->$key) {
+ if ($ufID && $ufID != $userSystemID) {
$session->reset();
//get logged in user ids, and set to session.
}
// return early
- if ($user->$key == 0) {
+ if ($userSystemID == 0) {
return;
}
- if (!isset($uniqId) || !$uniqId) {
- $uniqId = $user->$mail;
- }
+ $uniqId = $user->$mail;
- $ufmatch = self::synchronizeUFMatch($user, $user->$key, $uniqId, $uf, NULL, $ctype, $isLogin);
+ $ufmatch = self::synchronizeUFMatch($user, $userSystemID, $uniqId, $uf, NULL, $ctype, $isLogin);
if (!$ufmatch) {
return;
}
function getTimeZoneString() {
return NULL;
}
+ /**
+ * Get User ID from UserFramework system (CMS)
+ * @param object $user object as described by the User Framework
+ * @return mixed <NULL, number>
+ *
+ */
+ function getUserIDFromUserObject($user) {}
+
+ /**
+ * Get currently logged in user uf id.
+ *
+ * @return int $userID logged in user uf id.
+ */
+ function getLoggedInUfID() {}
+
+ /**
+ * 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
+ * in CRM_Core_BAO_UFMatch::synchronize - a cleaner approach would seem to be resolving the user id before calling
+ * the function
+ *
+ * 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
+ * @return int $ufid - user ID of UF System
+ */
+ function getBestUFID($user = NULL) {
+ if($user) {
+ return $this->getUserIDFromUserObject($user);
+ }
+ return $this->getLoggedInUfID();
+ }
}
}
}
}
+
+ /**
+ * Get User ID from UserFramework system (Drupal)
+ * @param object $user object as described by the CMS
+ * @return mixed <NULL, number>
+ */
+ function getUserIDFromUserObject($user) {
+ return !empty($user->uid) ? $user->uid : NULL;
+ }
}
return ($user->guest) ? NULL : $user->id;
}
+ /**
+ * Get User ID from UserFramework system (Joomla)
+ * @param object $user object as described by the CMS
+ * @return mixed <NULL, number>
+ */
+ function getUserIDFromUserObject($user) {
+ return !empty($user->id) ? $user->id : NULL;
+ }
+
/**
* Get a list of all installed modules, including enabled and disabled ones
*
return $ufID;
}
+ /**
+ * Get User ID from UserFramework system (Joomla)
+ * @param object $user object as described by the CMS
+ * @return mixed <NULL, number>
+ */
+ function getUserIDFromUserObject($user) {
+ return !empty($user->ID) ? $user->ID : NULL;
+ }
+
/**
* Get user login URL for hosting CMS (method declared in each CMS system class)
*