Skip to content

Commit a9bd85b

Browse files
author
Volodymyr Klymenko
authored
Merge pull request #1007 from magento-firedrakes/bugfixes
[Firedrakes] Bugfixes
2 parents e4adb6b + 3d47143 commit a9bd85b

File tree

67 files changed

+1596
-1300
lines changed

Some content is hidden

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

67 files changed

+1596
-1300
lines changed

app/code/Magento/Analytics/Controller/Adminhtml/Subscription/Activate.php

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,24 @@
66

77
namespace Magento\Analytics\Controller\Adminhtml\Subscription;
88

9+
use Magento\Analytics\Model\Config\Backend\Enabled;
910
use Magento\Analytics\Model\NotificationTime;
10-
use Magento\Analytics\Model\Subscription;
1111
use Magento\Backend\App\Action;
1212
use Magento\Backend\App\Action\Context;
13+
use Magento\Config\Model\Config\Source\Enabledisable;
14+
use Magento\Config\Model\PreparedValueFactory;
15+
use Magento\Framework\App\Config\ScopeConfigInterface;
1316
use Magento\Framework\Controller\Result\Json;
1417
use Magento\Framework\Controller\ResultFactory;
1518
use Magento\Framework\Exception\LocalizedException;
19+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
1620
use Psr\Log\LoggerInterface;
1721

1822
/**
1923
* Activates subscription to Magento BI Advanced Reporting.
2024
*/
2125
class Activate extends Action
2226
{
23-
/**
24-
* Resource for managing subscription to Magento BI.
25-
*
26-
* @var Subscription
27-
*/
28-
private $subscription;
29-
3027
/**
3128
* @var LoggerInterface
3229
*/
@@ -46,23 +43,36 @@ class Activate extends Action
4643
*/
4744
private $subscriptionApprovedField = 'analytics_subscription_checkbox';
4845

46+
/**
47+
* @var AbstractDb
48+
*/
49+
private $configValueResource;
50+
51+
/**
52+
* @var PreparedValueFactory
53+
*/
54+
private $preparedValueFactory;
55+
4956
/**
5057
* Activate constructor.
5158
*
5259
* @param Context $context
53-
* @param Subscription $subscription
5460
* @param LoggerInterface $logger
5561
* @param NotificationTime $notificationTime
62+
* @param AbstractDb $configValueResource
63+
* @param PreparedValueFactory $preparedValueFactory
5664
*/
5765
public function __construct(
5866
Context $context,
59-
Subscription $subscription,
6067
LoggerInterface $logger,
61-
NotificationTime $notificationTime
68+
NotificationTime $notificationTime,
69+
AbstractDb $configValueResource,
70+
PreparedValueFactory $preparedValueFactory
6271
) {
63-
$this->subscription = $subscription;
6472
$this->logger = $logger;
6573
$this->notificationTime = $notificationTime;
74+
$this->configValueResource = $configValueResource;
75+
$this->preparedValueFactory = $preparedValueFactory;
6676
parent::__construct($context);
6777
}
6878

@@ -85,7 +95,14 @@ public function execute()
8595
{
8696
try {
8797
if ($this->getRequest()->getParam($this->subscriptionApprovedField)) {
88-
$this->subscription->enable();
98+
$configValue = $this->preparedValueFactory->create(
99+
Enabled::XML_ENABLED_CONFIG_STRUCTURE_PATH,
100+
Enabledisable::ENABLE_VALUE,
101+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
102+
);
103+
104+
$this->configValueResource
105+
->save($configValue);
89106
} else {
90107
$this->notificationTime->unsetLastTimeNotificationValue();
91108
}

app/code/Magento/Analytics/Controller/Adminhtml/Subscription/Retry.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Magento\Analytics\Controller\Adminhtml\Subscription;
88

9-
use Magento\Analytics\Model\Subscription;
9+
use Magento\Analytics\Model\Config\Backend\Enabled\SubscriptionHandler;
1010
use Magento\Backend\App\Action;
1111
use Magento\Backend\App\Action\Context;
1212
use Magento\Framework\Controller\Result\Redirect;
@@ -21,19 +21,19 @@ class Retry extends Action
2121
/**
2222
* Resource for managing subscription to Magento Analytics.
2323
*
24-
* @var Subscription
24+
* @var SubscriptionHandler
2525
*/
26-
private $subscription;
26+
private $subscriptionHandler;
2727

2828
/**
2929
* @param Context $context
30-
* @param Subscription $subscription
30+
* @param SubscriptionHandler $subscriptionHandler
3131
*/
3232
public function __construct(
3333
Context $context,
34-
Subscription $subscription
34+
SubscriptionHandler $subscriptionHandler
3535
) {
36-
$this->subscription = $subscription;
36+
$this->subscriptionHandler = $subscriptionHandler;
3737
parent::__construct($context);
3838
}
3939

@@ -58,7 +58,7 @@ public function execute()
5858
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
5959
try {
6060
$resultRedirect->setPath('adminhtml');
61-
$this->subscription->retry();
61+
$this->subscriptionHandler->processEnabled();
6262
} catch (LocalizedException $e) {
6363
$this->getMessageManager()->addExceptionMessage($e, $e->getMessage());
6464
} catch (\Exception $e) {

app/code/Magento/Analytics/Model/Config/Backend/Enabled.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
*/
2121
class Enabled extends Value
2222
{
23+
/**
24+
* Path to field subscription enabled into config structure.
25+
*/
26+
const XML_ENABLED_CONFIG_STRUCTURE_PATH = 'analytics/general/enabled';
27+
2328
/**
2429
* Service for processing of activation/deactivation MBI subscription.
2530
*

app/code/Magento/Analytics/Model/Config/Backend/Enabled/SubscriptionHandler.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
use Magento\Analytics\Model\AnalyticsToken;
99
use Magento\Analytics\Model\Config\Backend\CollectionTime;
1010
use Magento\Analytics\Model\NotificationTime;
11-
use Magento\Framework\FlagManager;
11+
use Magento\Framework\App\Config\ReinitableConfigInterface;
1212
use Magento\Framework\App\Config\Storage\WriterInterface;
13+
use Magento\Framework\FlagManager;
1314

1415
/**
1516
* Class for processing of activation/deactivation MBI subscription.
@@ -61,22 +62,30 @@ class SubscriptionHandler
6162
*/
6263
private $notificationTime;
6364

65+
/**
66+
* @var ReinitableConfigInterface
67+
*/
68+
private $reinitableConfig;
69+
6470
/**
6571
* @param WriterInterface $configWriter
6672
* @param FlagManager $flagManager
6773
* @param AnalyticsToken $analyticsToken
6874
* @param NotificationTime $notificationTime
75+
* @param ReinitableConfigInterface $reinitableConfig
6976
*/
7077
public function __construct(
7178
WriterInterface $configWriter,
7279
FlagManager $flagManager,
7380
AnalyticsToken $analyticsToken,
74-
NotificationTime $notificationTime
81+
NotificationTime $notificationTime,
82+
ReinitableConfigInterface $reinitableConfig
7583
) {
7684
$this->configWriter = $configWriter;
7785
$this->flagManager = $flagManager;
7886
$this->analyticsToken = $analyticsToken;
7987
$this->notificationTime = $notificationTime;
88+
$this->reinitableConfig = $reinitableConfig;
8089
}
8190

8291
/**
@@ -92,6 +101,7 @@ public function processEnabled()
92101
$this->setCronSchedule();
93102
$this->setAttemptsFlag();
94103
$this->notificationTime->unsetLastTimeNotificationValue();
104+
$this->reinitableConfig->reinit();
95105
}
96106

97107
return true;

app/code/Magento/Analytics/Model/Connector/CommandInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ interface CommandInterface
1414
/**
1515
* Execute call to external service
1616
* Information about destination and arguments appears from config
17-
* @return void
17+
*
18+
* @return bool
1819
*/
1920
public function execute();
2021
}

app/code/Magento/Analytics/Model/Connector/Http/Client/Curl.php

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
*/
66
namespace Magento\Analytics\Model\Connector\Http\Client;
77

8-
use Magento\Analytics\Model\Connector\Http\ResponseFactory;
9-
use Magento\Framework\HTTP\Adapter\CurlFactory;
8+
use Magento\Analytics\Model\Connector\Http\ConverterInterface;
109
use Psr\Log\LoggerInterface;
10+
use Magento\Framework\HTTP\Adapter\CurlFactory;
11+
use Magento\Analytics\Model\Connector\Http\ResponseFactory;
1112

1213
/**
1314
* A CURL HTTP client.
@@ -16,11 +17,6 @@
1617
*/
1718
class Curl implements \Magento\Analytics\Model\Connector\Http\ClientInterface
1819
{
19-
/**
20-
* @var LoggerInterface
21-
*/
22-
private $logger;
23-
2420
/**
2521
* @var CurlFactory
2622
*/
@@ -31,46 +27,83 @@ class Curl implements \Magento\Analytics\Model\Connector\Http\ClientInterface
3127
*/
3228
private $responseFactory;
3329

30+
/**
31+
* @var ConverterInterface
32+
*/
33+
private $converter;
34+
35+
/**
36+
* @var LoggerInterface
37+
*/
38+
private $logger;
39+
3440
/**
3541
* @param CurlFactory $curlFactory
3642
* @param ResponseFactory $responseFactory
43+
* @param ConverterInterface $converter
3744
* @param LoggerInterface $logger
3845
*/
3946
public function __construct(
4047
CurlFactory $curlFactory,
4148
ResponseFactory $responseFactory,
49+
ConverterInterface $converter,
4250
LoggerInterface $logger
4351
) {
4452
$this->curlFactory = $curlFactory;
4553
$this->responseFactory = $responseFactory;
54+
$this->converter = $converter;
4655
$this->logger = $logger;
4756
}
4857

4958
/**
5059
* {@inheritdoc}
5160
*/
52-
public function request($method, $url, $body = '', array $headers = [], $version = '1.1')
61+
public function request($method, $url, array $body = [], array $headers = [], $version = '1.1')
5362
{
54-
$curl = $this->curlFactory->create();
63+
$response = new \Zend_Http_Response(0, []);
5564

56-
$curl->write($method, $url, $version, $headers, $body);
65+
try {
66+
$curl = $this->curlFactory->create();
67+
$headers = $this->applyContentTypeHeaderFromConverter($headers);
5768

58-
$result = $curl->read();
69+
$curl->write($method, $url, $version, $headers, $this->converter->toBody($body));
5970

60-
if ($curl->getErrno()) {
61-
$this->logger->critical(
62-
new \Exception(
63-
sprintf(
64-
'MBI service CURL connection error #%s: %s',
65-
$curl->getErrno(),
66-
$curl->getError()
71+
$result = $curl->read();
72+
73+
if ($curl->getErrno()) {
74+
$this->logger->critical(
75+
new \Exception(
76+
sprintf(
77+
'MBI service CURL connection error #%s: %s',
78+
$curl->getErrno(),
79+
$curl->getError()
80+
)
6781
)
68-
)
69-
);
82+
);
83+
84+
return $response;
85+
}
7086

71-
return false;
87+
$response = $this->responseFactory->create($result);
88+
} catch (\Exception $e) {
89+
$this->logger->critical($e);
90+
}
91+
92+
return $response;
93+
}
94+
95+
/**
96+
* @param array $headers
97+
*
98+
* @return array
99+
*/
100+
private function applyContentTypeHeaderFromConverter(array $headers)
101+
{
102+
$contentTypeHeaderKey = array_search($this->converter->getContentTypeHeader(), $headers);
103+
if ($contentTypeHeaderKey === false) {
104+
$headers[] = $this->converter->getContentTypeHeader();
72105
}
73106

74-
return $this->responseFactory->create($result);
107+
return $headers;
75108
}
76109
}

app/code/Magento/Analytics/Model/Connector/Http/ClientInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ interface ClientInterface
1919
*
2020
* @param string $method
2121
* @param string $url
22-
* @param string $body
22+
* @param array $body
2323
* @param array $headers
2424
* @param string $version
2525
*
26-
* @return \Zend_Http_Response|bool
26+
* @return \Zend_Http_Response
2727
*/
28-
public function request($method, $url, $body = '', array $headers = [], $version = '1.1');
28+
public function request($method, $url, array $body = [], array $headers = [], $version = '1.1');
2929
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Analytics\Model\Connector\Http;
7+
8+
/**
9+
* Represents converter interface for http request and response body.
10+
*/
11+
interface ConverterInterface
12+
{
13+
/**
14+
* @param string $body
15+
*
16+
* @return array
17+
*/
18+
public function fromBody($body);
19+
20+
/**
21+
* @param array $data
22+
*
23+
* @return string
24+
*/
25+
public function toBody(array $data);
26+
27+
/**
28+
* @return string
29+
*/
30+
public function getContentTypeHeader();
31+
}

0 commit comments

Comments
 (0)