/** * Activate user with user or deactivate and create new eZUserAccountKey with user hash * depending on $enableUser being true or not. * * @param int $userID * @param string $userHash * @param bool $enableUser * * @return array An array with operation status, always true if userID is ok */ public static function activation($userID, $userHash, $enableUser = false) { $user = eZUser::fetch($userID); $userSetting = eZUserSetting::fetch($userID); if ($user && $userSetting) { $userChange = $userSetting->attribute('is_enabled') != $enableUser; if ($enableUser) { $userSetting->setAttribute('is_enabled', 1); $userSetting->store(); eZUserAccountKey::removeByUserID($userID); } else { $userSetting->setAttribute('is_enabled', 0); $userSetting->store(); $accountKey = eZUserAccountKey::createNew($userID, $userHash, time()); $accountKey->store(); } if ($userChange) { if (!$enableUser) { eZUser::removeSessionData($userID); } eZContentCacheManager::clearContentCacheIfNeeded($userID); } return array('status' => true); } else { eZDebug::writeError("Failed to activate user {$userID} (could not fetch)", __METHOD__); return array('status' => false); } }