Skip to content

Commit

Permalink
Merge pull request #68 from gigya/develop
Browse files Browse the repository at this point in the history
5.4.0
  • Loading branch information
Ynhockey authored Jul 14, 2019
2 parents 1c9a300 + d5288bd commit 762c73a
Show file tree
Hide file tree
Showing 27 changed files with 736 additions and 248 deletions.
13 changes: 9 additions & 4 deletions Controller/Raas/GigyaEditPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Magento\Framework\Exception\AuthenticationException;
use Magento\Framework\Exception\InputException;
use Gigya\GigyaIM\Model\Config as GigyaConfig;
use Gigya\GigyaIM\Logger\Logger as GigyaLogger;

class GigyaEditPost extends \Magento\Customer\Controller\Account\EditPost
{
Expand Down Expand Up @@ -48,6 +49,9 @@ class GigyaEditPost extends \Magento\Customer\Controller\Account\EditPost
/** @var GigyaConfig */
protected $config;

/** @var GigyaLogger */
protected $logger;

/**
* @param Context $context
* @param Session $customerSession
Expand All @@ -58,6 +62,7 @@ class GigyaEditPost extends \Magento\Customer\Controller\Account\EditPost
* @param CustomerExtractor $customerExtractor
* @param GigyaConfig $config
* @param GigyaMageHelper $gigyaMageHelper
* @param GigyaLogger $logger
*/
public function __construct(
Context $context,
Expand All @@ -68,7 +73,8 @@ public function __construct(
Validator $formKeyValidator,
CustomerExtractor $customerExtractor,
GigyaConfig $config,
GigyaMageHelper $gigyaMageHelper
GigyaMageHelper $gigyaMageHelper,
GigyaLogger $logger
)
{
parent::__construct(
Expand All @@ -83,10 +89,11 @@ public function __construct(
$this->gigyaMageHelper = $gigyaMageHelper;
$this->gigyaSyncHelper = $gigyaSyncHelper;
$this->config = $config;
$this->logger = $logger;
}

/**
* Change customer password action
* Edit profile and change customer password action
*
* @return \Magento\Framework\Controller\Result\Redirect
*
Expand Down Expand Up @@ -123,7 +130,6 @@ public function execute()
}

try {

$gigyaAccount = $this->gigyaMageHelper->getGigyaAccountDataFromLoginData($this->getRequest()->getParam('gigya_user'));

if ($gigyaAccount == false || $gigyaAccount->getUID() != $this->session->getGigyaAccountData()->getUID()) {
Expand All @@ -139,7 +145,6 @@ public function execute()
$this->gigyaMageHelper->transferAttributes($customer, $eligibleCustomer);

$this->customerRepository->save($eligibleCustomer);

} catch (AuthenticationException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
} catch (InputException $e) {
Expand Down
2 changes: 0 additions & 2 deletions Controller/Raas/GigyaPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,6 @@ protected function doLogin(GigyaUser $valid_gigya_user)
* Retrieve success message
*
* @return string
*
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
protected function getSuccessMessage()
{
Expand Down
46 changes: 46 additions & 0 deletions Helper/CmsStarterKit/GigyaApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function fetchGigyaAccount($uid, $include = null, $extraProfileFields = n
$include = 'identities-active,identities-all,identities-global,loginIDs,emails,profile,data,password,isLockedOut,'
. 'lastLoginLocation,regSource,irank,rba,subscriptions,userInfo,preferences';
}

if (null === $extraProfileFields)
{
$extraProfileFields = 'languages,address,phones,education,educationLevel,honors,publications,patents,certifications,'
Expand All @@ -139,6 +140,51 @@ public function fetchGigyaAccount($uid, $include = null, $extraProfileFields = n
return $gigyaUser;
}

/**
* Queries Gigya with the accounts.search call
*
* @param string|array $query The literal query to send to accounts.search, or a set of params to send instead (useful for cursors)
* @param bool $useCursor
*
* @return GigyaUser[]
*
* @throws GSApiException
* @throws sdk\GSException
*/
public function searchGigyaUsers($query, $useCursor = false) {
$gigyaUsers = array();

if (is_array($query)) /* Query is actually a set of params. Useful for setting cursor ID instead of query */
{
$params = $query;
}
else
{
$params = array(
'openCursor' => $useCursor,
'query' => $query,
);
}

$gigyaData = $this->sendApiCall('accounts.search', $params)->getData()->serialize();

foreach ($gigyaData['results'] as $userData) {
$profileArray = $userData['profile'];
$gigyaUser = GigyaUserFactory::createGigyaUserFromArray($userData);
$gigyaProfile = GigyaUserFactory::createGigyaProfileFromArray($profileArray);
$gigyaUser->setProfile($gigyaProfile);

$gigyaUsers[] = $gigyaUser;
}

if (!empty($gigyaData['nextCursorId'])) {
$cursorId = $gigyaData['nextCursorId'];
return array_merge($gigyaUsers, $this->searchGigyaUsers(['cursorId' => $cursorId]));
}

return $gigyaUsers;
}

/**
* Send all the Gigya data for the user specified by the UID
*
Expand Down
20 changes: 12 additions & 8 deletions Helper/CmsStarterKit/fieldMapping/CmsUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ public function __construct($gigyaAccount, $mappingFilePath) {
}

/**
* @param mixed $cmsAccount
* @param $cmsAccountSaver
* @param mixed $cmsAccount
* @param $cmsAccountSaver
* @param boolean $skipCache Determines whether to skip the caching and cache retrieval for field mapping
*
* @throws \Gigya\GigyaIM\Helper\CmsStarterKit\fieldMapping\CmsUpdaterException
*/
public function updateCmsAccount(&$cmsAccount, $cmsAccountSaver = null) {
public function updateCmsAccount(&$cmsAccount, $cmsAccountSaver = null, $skipCache = false) {
if (!isset($this->gigyaMapping))
{
$this->retrieveFieldMappings();
$this->retrieveFieldMappings($skipCache);
}

if (method_exists($this, 'callCmsHook'))
Expand All @@ -62,9 +63,11 @@ abstract protected function callCmsHook();
abstract protected function saveCmsAccount(&$cmsAccount, $cmsAccountSaver);

/**
* @throws \Gigya\GigyaIM\Helper\CmsStarterKit\fieldMapping\CmsUpdaterException
* @param boolean $skipCache
*
* @throws CmsUpdaterException
*/
public function retrieveFieldMappings() {
public function retrieveFieldMappings($skipCache = false) {
if (file_exists($this->path))
{
$mappingJson = file_get_contents($this->path);
Expand All @@ -73,10 +76,11 @@ public function retrieveFieldMappings() {
{
throw new CmsUpdaterException("Field Mapping file could not be found at " . $this->path);
}
if (false === $mappingJson)

if ($mappingJson === false)
{
$err = error_get_last();
$message = "Could not retrieve field mapping configuration file. message was:" . $err['message'];
$message = "CMSUpdater: Could not retrieve field mapping configuration file. The message was: " . $err['message'];
throw new CmsUpdaterException("$message");
}
$conf = new Conf($mappingJson);
Expand Down
33 changes: 18 additions & 15 deletions Helper/CmsStarterKit/fieldMapping/Conf.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,25 @@ public function __construct($json) {
$this->mappingConf = json_decode($json, true);
}

/**
* @return array
*/
public function getCmsKeyed() {
if (empty($this->cmsKeyed))
{
$this->buildKeyedArrays($this->mappingConf);
}

return $this->cmsKeyed;
}

protected function buildKeyedArrays($array) {
$cmsKeyedArray = [];
$gigyaKeyedArray = [];

$allowedDirections = ['cms2g', 'g2cms', 'both'];

foreach ($array as $confItem)
{
$cmsKey = $confItem['cmsName'];
$gigyaKey = $confItem['gigyaName'];
$direction = isset($confItem['direction']) ? $confItem['direction'] : "g2cms";
$direction = (isset($confItem['direction']) and in_array($confItem['direction'], $allowedDirections)) ? $confItem['direction'] : 'g2cms';
$conf = new ConfItem($confItem);

switch ($direction)
{
case "cms2g":
case 'cms2g':
$cmsKeyedArray[$cmsKey][] = $conf;
break;
case "both":
case 'both':
$gigyaKeyedArray[$gigyaKey][] = $conf;
$cmsKeyedArray[$cmsKey][] = $conf;
break;
Expand All @@ -55,6 +46,18 @@ protected function buildKeyedArrays($array) {
$this->cmsKeyed = $cmsKeyedArray;
}

/**
* @return array
*/
public function getCmsKeyed() {
if (empty($this->cmsKeyed))
{
$this->buildKeyedArrays($this->mappingConf);
}

return $this->cmsKeyed;
}

/**
* @return array
*/
Expand Down
2 changes: 2 additions & 0 deletions Helper/CmsStarterKit/fieldMapping/ConfItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class ConfItem

/**
* ConfItem constructor.
*
* @param array $array
*/
public function __construct($array) {
foreach ($array as $key => $value)
Expand Down
4 changes: 3 additions & 1 deletion Helper/CmsStarterKit/fieldMapping/GigyaUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,14 @@ protected function retrieveFieldMappings() {
if (false === $mappingJson)
{
$err = error_get_last();
$message = "Could not retrieve field mapping configuration file. message was:" . $err['message'];
$message = "GigyaUpdater: Could not retrieve field mapping configuration file. The message was: " . $err['message'];
throw new \Exception($message);
}

$conf = new Conf($mappingJson);
$this->setMappingCache($conf);
}

$this->cmsMappings = $conf->getCmsKeyed();
}

Expand Down
Loading

0 comments on commit 762c73a

Please sign in to comment.