1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Analytics\Model;
use Magento\Analytics\Model\Config\Backend\Baseurl\SubscriptionUpdateHandler;
use Magento\Analytics\Model\Connector\OTPRequest;
use Magento\Analytics\Model\Exception\State\SubscriptionUpdateException;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\FlagManager;
/**
* Provide URL on resource with reports.
*/
class ReportUrlProvider
{
/**
* Resource for handling MBI token value.
*
* @var AnalyticsToken
*/
private $analyticsToken;
/**
* Resource which provide OTP.
*
* @var OTPRequest
*/
private $otpRequest;
/**
* @var ScopeConfigInterface
*/
private $config;
/**
* @var FlagManager
*/
private $flagManager;
/**
* Path to config value with URL which provide reports.
*
* @var string
*/
private $urlReportConfigPath = 'analytics/url/report';
/**
* @param AnalyticsToken $analyticsToken
* @param OTPRequest $otpRequest
* @param ScopeConfigInterface $config
* @param FlagManager $flagManager
*/
public function __construct(
AnalyticsToken $analyticsToken,
OTPRequest $otpRequest,
ScopeConfigInterface $config,
FlagManager $flagManager
) {
$this->analyticsToken = $analyticsToken;
$this->otpRequest = $otpRequest;
$this->config = $config;
$this->flagManager = $flagManager;
}
/**
* Provide URL on resource with reports.
*
* @return string
* @throws SubscriptionUpdateException
*/
public function getUrl()
{
if ($this->flagManager->getFlagData(SubscriptionUpdateHandler::PREVIOUS_BASE_URL_FLAG_CODE)) {
throw new SubscriptionUpdateException(__(
'Your Base URL has been changed and your reports are being updated. '
. 'Advanced Reporting will be available once this change has been processed. Please try again later.'
));
}
$url = $this->config->getValue($this->urlReportConfigPath);
if ($this->analyticsToken->isTokenExist()) {
$otp = $this->otpRequest->call();
if ($otp) {
$query = http_build_query(['otp' => $otp], '', '&');
$url .= '?' . $query;
}
}
return $url;
}
}