Skip to content

Commit 8e48823

Browse files
committed
MAGETWO-61018: [Github] Unable to add video to product via REST api #7153
2 parents bd2d6e7 + 7c81c1d commit 8e48823

File tree

172 files changed

+8011
-209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+8011
-209
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Analytics\Controller\Adminhtml\BasicTier;
7+
8+
use Magento\Backend\App\Action;
9+
use Magento\Config\Model\Config;
10+
use Magento\Backend\App\Action\Context;
11+
12+
/**
13+
* Class SignUp
14+
*
15+
* Provides link to Basic Tier signup
16+
*/
17+
class SignUp extends Action
18+
{
19+
/**
20+
* @var string
21+
*/
22+
private $basicTierUrlPath = 'analytics/url/basic_tier';
23+
24+
/**
25+
* @var Config
26+
*/
27+
private $config;
28+
29+
/**
30+
* @param Context $context
31+
* @param Config $config
32+
*/
33+
public function __construct(
34+
Context $context,
35+
Config $config
36+
) {
37+
$this->config = $config;
38+
parent::__construct($context);
39+
}
40+
41+
/**
42+
* Check admin permissions for this controller
43+
*
44+
* @return boolean
45+
*/
46+
protected function _isAllowed()
47+
{
48+
return $this->_authorization->isAllowed('Magento_Analytics::report_basic_tier');
49+
}
50+
51+
/**
52+
* Provides link to Basic Tier signup
53+
*
54+
* @return \Magento\Framework\Controller\AbstractResult
55+
*/
56+
public function execute()
57+
{
58+
return $this->resultRedirectFactory->create()->setUrl(
59+
$this->config->getConfigDataValue($this->basicTierUrlPath)
60+
);
61+
}
62+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Analytics\Controller\Adminhtml\Export;
8+
9+
use Magento\Backend\App\Action;
10+
use Magento\Framework\App\ResponseInterface;
11+
use Magento\Framework\App\Response\Http\FileFactory;
12+
use Magento\Analytics\Model\Export;
13+
use Magento\Framework\App\Filesystem\DirectoryList;
14+
15+
/**
16+
* Class Example
17+
*/
18+
class Example extends Action
19+
{
20+
/**
21+
* @var Export
22+
*/
23+
private $export;
24+
25+
/**
26+
* @var FileFactory
27+
*/
28+
private $fileFactory;
29+
30+
/**
31+
* Example constructor.
32+
*
33+
* @param Action\Context $context
34+
* @param Export $export
35+
* @param FileFactory $fileFactory
36+
*/
37+
public function __construct(
38+
Action\Context $context,
39+
Export $export,
40+
FileFactory $fileFactory
41+
) {
42+
parent::__construct($context);
43+
$this->export = $export;
44+
$this->fileFactory = $fileFactory;
45+
}
46+
47+
/**
48+
* Controller for demo
49+
*
50+
* @return ResponseInterface
51+
* @throws \Exception
52+
*/
53+
public function execute()
54+
{
55+
return $this->fileFactory->create(
56+
'analytics-export.tgz',
57+
$this->export->getArchiveContent(),
58+
DirectoryList::VAR_DIR
59+
);
60+
}
61+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Analytics\Controller\Adminhtml\Reports;
7+
8+
use Magento\Analytics\Model\ReportUrlProvider;
9+
use Magento\Backend\App\Action;
10+
use Magento\Backend\App\Action\Context;
11+
use Magento\Framework\Controller\Result\Redirect;
12+
use Magento\Framework\Controller\ResultFactory;
13+
use Magento\Framework\Exception\LocalizedException;
14+
15+
/**
16+
* Provide redirect to resource with reports.
17+
*/
18+
class Show extends Action
19+
{
20+
/**
21+
* @var ReportUrlProvider
22+
*/
23+
private $reportUrlProvider;
24+
25+
/**
26+
* @param Context $context
27+
* @param ReportUrlProvider $reportUrlProvider
28+
*/
29+
public function __construct(
30+
Context $context,
31+
ReportUrlProvider $reportUrlProvider
32+
) {
33+
$this->reportUrlProvider = $reportUrlProvider;
34+
parent::__construct($context);
35+
}
36+
37+
/**
38+
* Check admin permissions for this controller.
39+
*
40+
* @return boolean
41+
*/
42+
protected function _isAllowed()
43+
{
44+
return $this->_authorization->isAllowed('Magento_Analytics::analytics_settings');
45+
}
46+
47+
/**
48+
* Redirect to resource with reports.
49+
*
50+
* @return Redirect $resultRedirect
51+
*/
52+
public function execute()
53+
{
54+
/** @var Redirect $resultRedirect */
55+
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
56+
try {
57+
$resultRedirect->setUrl($this->reportUrlProvider->getUrl());
58+
} catch (LocalizedException $e) {
59+
$this->getMessageManager()->addExceptionMessage($e, $e->getMessage());
60+
$resultRedirect->setPath('adminhtml');
61+
} catch (\Exception $e) {
62+
$this->getMessageManager()->addExceptionMessage(
63+
$e,
64+
__('Sorry, there has been an error processing your request. Please try again later.')
65+
);
66+
$resultRedirect->setPath('adminhtml');
67+
}
68+
69+
return $resultRedirect;
70+
}
71+
}

app/code/Magento/Analytics/Model/AnalyticsConnector.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
99
use Magento\Framework\ObjectManagerInterface;
1010

1111
/**
12-
* Class AnalyticsConnector
12+
* A connector to external services.
1313
*
14-
* Connector to MA services, aggregates calls to external services.
14+
* Aggregates and executes commands which perform requests to external services.
1515
*/
1616
class AnalyticsConnector
1717
{
1818
/**
19+
* A list of possible commands.
20+
*
21+
* An associative array in format: 'command_name' => 'command_class_name'.
22+
*
23+
* The list may be configured in each module via '/etc/di.xml'.
24+
*
1925
* @var string[]
2026
*/
2127
private $commands;
@@ -26,7 +32,6 @@ class AnalyticsConnector
2632
private $objectManager;
2733

2834
/**
29-
* AnalyticsConnector constructor.
3035
* @param array $commands
3136
* @param ObjectManagerInterface $objectManager
3237
*/
@@ -39,18 +44,21 @@ public function __construct(
3944
}
4045

4146
/**
42-
* Create the instance of the command and execute it.
47+
* Executes a command in accordance with the given name.
4348
*
4449
* @param string $commandName
4550
* @return bool
46-
* @throws NotFoundException
51+
* @throws NotFoundException if the command is not found.
4752
*/
4853
public function execute($commandName)
4954
{
5055
if (!array_key_exists($commandName, $this->commands)) {
5156
throw new NotFoundException(__('Command was not found.'));
5257
}
58+
59+
/** @var \Magento\Analytics\Model\AnalyticsConnector\AnalyticsCommandInterface $command */
5360
$command = $this->objectManager->create($this->commands[$commandName]);
61+
5462
return $command->execute();
5563
}
5664
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Analytics\Model\AnalyticsConnector;
7+
8+
use Magento\Analytics\Model\AnalyticsToken;
9+
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
use Magento\Framework\HTTP\ZendClient as HttpClient;
11+
use Magento\Framework\HTTP\ZendClientFactory as HttpClientFactory;
12+
use Magento\Store\Model\Store;
13+
use Psr\Log\LoggerInterface;
14+
use Zend_Http_Response as HttpResponse;
15+
16+
/**
17+
* Perform direct call to MBI services for getting OTP.
18+
*
19+
* OTP (One-Time Password) is a password that is valid for only one login session
20+
* and has limited time when it is valid.
21+
*/
22+
class OTPRequest
23+
{
24+
/**
25+
* Resource for handling MBI token value.
26+
*
27+
* @var AnalyticsToken
28+
*/
29+
private $analyticsToken;
30+
31+
/**
32+
* @var HttpClientFactory
33+
*/
34+
private $clientFactory;
35+
36+
/**
37+
* @var LoggerInterface
38+
*/
39+
private $logger;
40+
41+
/**
42+
* @var ScopeConfigInterface
43+
*/
44+
private $config;
45+
46+
/**
47+
* Path to config value with URL which provide OTP for MBI.
48+
*
49+
* @var string
50+
*/
51+
private $otpUrlConfigPath = 'analytics/url/otp';
52+
53+
/**
54+
* @param AnalyticsToken $analyticsToken
55+
* @param HttpClientFactory $clientFactory
56+
* @param ScopeConfigInterface $config
57+
* @param LoggerInterface $logger
58+
*/
59+
public function __construct(
60+
AnalyticsToken $analyticsToken,
61+
HttpClientFactory $clientFactory,
62+
ScopeConfigInterface $config,
63+
LoggerInterface $logger
64+
) {
65+
$this->analyticsToken = $analyticsToken;
66+
$this->clientFactory = $clientFactory;
67+
$this->config = $config;
68+
$this->logger = $logger;
69+
}
70+
71+
/**
72+
* Performs call to MBI services for getting OTP.
73+
*
74+
* @return string|false OTP or false if request was unsuccessful.
75+
*/
76+
public function call()
77+
{
78+
$otp = false;
79+
try {
80+
if ($this->analyticsToken->isTokenExist()) {
81+
/** @var HttpClient $client */
82+
$client = $this->clientFactory->create();
83+
$client->setUri($this->config->getValue($this->otpUrlConfigPath));
84+
$client->setRawData($this->getRequestJson());
85+
$client->setMethod(HttpClient::POST);
86+
$otp = $this->extractOtp($client->request());
87+
if (!$otp) {
88+
$this->logger->critical('The request for a OTP is unsuccessful.');
89+
}
90+
}
91+
} catch (\Exception $e) {
92+
$this->logger->critical($e->getMessage());
93+
}
94+
95+
return $otp;
96+
}
97+
98+
/**
99+
* Prepares json string with data for request.
100+
*
101+
* @return string
102+
*/
103+
private function getRequestJson()
104+
{
105+
return json_encode(
106+
[
107+
"token" => $this->analyticsToken->getToken(),
108+
"url" => $this->config->getValue(Store::XML_PATH_SECURE_BASE_URL),
109+
]
110+
);
111+
}
112+
113+
/**
114+
* Extracts OTP from the response.
115+
*
116+
* @param HttpResponse $response
117+
* @return string|false False if response doesn't contain required data.
118+
*/
119+
private function extractOtp(HttpResponse $response)
120+
{
121+
$otp = false;
122+
if ($response->getStatus() === 200) {
123+
$body = json_decode($response->getBody(), 1);
124+
$otp = !empty($body['otp']) ? $body['otp'] : false;
125+
}
126+
127+
return $otp;
128+
}
129+
}

app/code/Magento/Analytics/Model/AnalyticsConnector/SignUpRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private function getRequestJson($integrationToken)
6969
return json_encode(
7070
[
7171
"token" => $integrationToken,
72-
"url" => $this->config->getConfigDataValue(Store::XML_PATH_UNSECURE_BASE_URL)
72+
"url" => $this->config->getConfigDataValue(Store::XML_PATH_SECURE_BASE_URL)
7373
]
7474
);
7575
}

0 commit comments

Comments
 (0)