-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #822 from magento-firedrakes/analytics-sprint-2
Implemented features: MAGETWO-62539 Collect Data by Default Data Definition MAGETWO-62542 Define and Change Verticals MAGETWO-62552 Link to MA Free Tier MAGETWO-62546 Provide button with link to MA Basic Tier
- Loading branch information
Showing
124 changed files
with
7,420 additions
and
36 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
app/code/Magento/Analytics/Controller/Adminhtml/BasicTier/SignUp.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Analytics\Controller\Adminhtml\BasicTier; | ||
|
||
use Magento\Backend\App\Action; | ||
use Magento\Config\Model\Config; | ||
use Magento\Backend\App\Action\Context; | ||
|
||
/** | ||
* Class SignUp | ||
* | ||
* Provides link to Basic Tier signup | ||
*/ | ||
class SignUp extends Action | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $basicTierUrlPath = 'analytics/url/basic_tier'; | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @param Context $context | ||
* @param Config $config | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Config $config | ||
) { | ||
$this->config = $config; | ||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* Check admin permissions for this controller | ||
* | ||
* @return boolean | ||
*/ | ||
protected function _isAllowed() | ||
{ | ||
return $this->_authorization->isAllowed('Magento_Analytics::report_basic_tier'); | ||
} | ||
|
||
/** | ||
* Provides link to Basic Tier signup | ||
* | ||
* @return \Magento\Framework\Controller\AbstractResult | ||
*/ | ||
public function execute() | ||
{ | ||
return $this->resultRedirectFactory->create()->setUrl( | ||
$this->config->getConfigDataValue($this->basicTierUrlPath) | ||
); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
app/code/Magento/Analytics/Controller/Adminhtml/Export/Example.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Analytics\Controller\Adminhtml\Export; | ||
|
||
use Magento\Backend\App\Action; | ||
use Magento\Framework\App\ResponseInterface; | ||
use Magento\Framework\App\Response\Http\FileFactory; | ||
use Magento\Analytics\Model\Export; | ||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
|
||
/** | ||
* Class Example | ||
*/ | ||
class Example extends Action | ||
{ | ||
/** | ||
* @var Export | ||
*/ | ||
private $export; | ||
|
||
/** | ||
* @var FileFactory | ||
*/ | ||
private $fileFactory; | ||
|
||
/** | ||
* Example constructor. | ||
* | ||
* @param Action\Context $context | ||
* @param Export $export | ||
* @param FileFactory $fileFactory | ||
*/ | ||
public function __construct( | ||
Action\Context $context, | ||
Export $export, | ||
FileFactory $fileFactory | ||
) { | ||
parent::__construct($context); | ||
$this->export = $export; | ||
$this->fileFactory = $fileFactory; | ||
} | ||
|
||
/** | ||
* Controller for demo | ||
* | ||
* @return ResponseInterface | ||
* @throws \Exception | ||
*/ | ||
public function execute() | ||
{ | ||
return $this->fileFactory->create( | ||
'analytics-export.tgz', | ||
$this->export->getArchiveContent(), | ||
DirectoryList::VAR_DIR | ||
); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
app/code/Magento/Analytics/Controller/Adminhtml/Reports/Show.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Analytics\Controller\Adminhtml\Reports; | ||
|
||
use Magento\Analytics\Model\ReportUrlProvider; | ||
use Magento\Backend\App\Action; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\Framework\Controller\Result\Redirect; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\Exception\LocalizedException; | ||
|
||
/** | ||
* Provide redirect to resource with reports. | ||
*/ | ||
class Show extends Action | ||
{ | ||
/** | ||
* @var ReportUrlProvider | ||
*/ | ||
private $reportUrlProvider; | ||
|
||
/** | ||
* @param Context $context | ||
* @param ReportUrlProvider $reportUrlProvider | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
ReportUrlProvider $reportUrlProvider | ||
) { | ||
$this->reportUrlProvider = $reportUrlProvider; | ||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* Check admin permissions for this controller. | ||
* | ||
* @return boolean | ||
*/ | ||
protected function _isAllowed() | ||
{ | ||
return $this->_authorization->isAllowed('Magento_Analytics::analytics_settings'); | ||
} | ||
|
||
/** | ||
* Redirect to resource with reports. | ||
* | ||
* @return Redirect $resultRedirect | ||
*/ | ||
public function execute() | ||
{ | ||
/** @var Redirect $resultRedirect */ | ||
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); | ||
try { | ||
$resultRedirect->setUrl($this->reportUrlProvider->getUrl()); | ||
} catch (LocalizedException $e) { | ||
$this->getMessageManager()->addExceptionMessage($e, $e->getMessage()); | ||
$resultRedirect->setPath('adminhtml'); | ||
} catch (\Exception $e) { | ||
$this->getMessageManager()->addExceptionMessage( | ||
$e, | ||
__('Sorry, there has been an error processing your request. Please try again later.') | ||
); | ||
$resultRedirect->setPath('adminhtml'); | ||
} | ||
|
||
return $resultRedirect; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
app/code/Magento/Analytics/Model/AnalyticsConnector/OTPRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Analytics\Model\AnalyticsConnector; | ||
|
||
use Magento\Analytics\Model\AnalyticsToken; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\HTTP\ZendClient as HttpClient; | ||
use Magento\Framework\HTTP\ZendClientFactory as HttpClientFactory; | ||
use Magento\Store\Model\Store; | ||
use Psr\Log\LoggerInterface; | ||
use Zend_Http_Response as HttpResponse; | ||
|
||
/** | ||
* Perform direct call to MBI services for getting OTP. | ||
* | ||
* OTP (One-Time Password) is a password that is valid for only one login session | ||
* and has limited time when it is valid. | ||
*/ | ||
class OTPRequest | ||
{ | ||
/** | ||
* Resource for handling MBI token value. | ||
* | ||
* @var AnalyticsToken | ||
*/ | ||
private $analyticsToken; | ||
|
||
/** | ||
* @var HttpClientFactory | ||
*/ | ||
private $clientFactory; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* Path to config value with URL which provide OTP for MBI. | ||
* | ||
* @var string | ||
*/ | ||
private $otpUrlConfigPath = 'analytics/url/otp'; | ||
|
||
/** | ||
* @param AnalyticsToken $analyticsToken | ||
* @param HttpClientFactory $clientFactory | ||
* @param ScopeConfigInterface $config | ||
* @param LoggerInterface $logger | ||
*/ | ||
public function __construct( | ||
AnalyticsToken $analyticsToken, | ||
HttpClientFactory $clientFactory, | ||
ScopeConfigInterface $config, | ||
LoggerInterface $logger | ||
) { | ||
$this->analyticsToken = $analyticsToken; | ||
$this->clientFactory = $clientFactory; | ||
$this->config = $config; | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* Performs call to MBI services for getting OTP. | ||
* | ||
* @return string|false OTP or false if request was unsuccessful. | ||
*/ | ||
public function call() | ||
{ | ||
$otp = false; | ||
try { | ||
if ($this->analyticsToken->isTokenExist()) { | ||
/** @var HttpClient $client */ | ||
$client = $this->clientFactory->create(); | ||
$client->setUri($this->config->getValue($this->otpUrlConfigPath)); | ||
$client->setRawData($this->getRequestJson()); | ||
$client->setMethod(HttpClient::POST); | ||
$otp = $this->extractOtp($client->request()); | ||
if (!$otp) { | ||
$this->logger->critical('The request for a OTP is unsuccessful.'); | ||
} | ||
} | ||
} catch (\Exception $e) { | ||
$this->logger->critical($e->getMessage()); | ||
} | ||
|
||
return $otp; | ||
} | ||
|
||
/** | ||
* Prepares json string with data for request. | ||
* | ||
* @return string | ||
*/ | ||
private function getRequestJson() | ||
{ | ||
return json_encode( | ||
[ | ||
"token" => $this->analyticsToken->getToken(), | ||
"url" => $this->config->getValue(Store::XML_PATH_SECURE_BASE_URL), | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Extracts OTP from the response. | ||
* | ||
* @param HttpResponse $response | ||
* @return string|false False if response doesn't contain required data. | ||
*/ | ||
private function extractOtp(HttpResponse $response) | ||
{ | ||
$otp = false; | ||
if ($response->getStatus() === 200) { | ||
$body = json_decode($response->getBody(), 1); | ||
$otp = !empty($body['otp']) ? $body['otp'] : false; | ||
} | ||
|
||
return $otp; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.