-
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 #909 from magento-firedrakes/bugfixes
[Firedrakes] Bugfixes and Analytics critical changes
- Loading branch information
Showing
61 changed files
with
1,181 additions
and
334 deletions.
There are no files selected for viewing
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
101 changes: 101 additions & 0 deletions
101
app/code/Magento/Analytics/Model/Connector/NotifyDataChangedCommand.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,101 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Analytics\Model\Connector; | ||
|
||
use Magento\Analytics\Model\AnalyticsToken; | ||
use Magento\Framework\HTTP\ZendClient; | ||
use Magento\Config\Model\Config; | ||
use Psr\Log\LoggerInterface; | ||
use Magento\Store\Model\Store; | ||
|
||
/** | ||
* Command notifies MBI about that data collection was finished. | ||
*/ | ||
class NotifyDataChangedCommand implements CommandInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $notifyDataChangedUrlPath = 'analytics/url/notify_data_changed'; | ||
|
||
/** | ||
* @var AnalyticsToken | ||
*/ | ||
private $analyticsToken; | ||
|
||
/** | ||
* @var Http\ClientInterface | ||
*/ | ||
private $httpClient; | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* NotifyDataChangedCommand constructor. | ||
* @param AnalyticsToken $analyticsToken | ||
* @param Http\ClientInterface $httpClient | ||
* @param Config $config | ||
* @param LoggerInterface $logger | ||
*/ | ||
public function __construct( | ||
AnalyticsToken $analyticsToken, | ||
Http\ClientInterface $httpClient, | ||
Config $config, | ||
LoggerInterface $logger | ||
) { | ||
$this->analyticsToken = $analyticsToken; | ||
$this->httpClient = $httpClient; | ||
$this->config = $config; | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* Notify MBI about that data collection was finished | ||
* @return bool | ||
*/ | ||
public function execute() | ||
{ | ||
$result = false; | ||
try { | ||
if ($this->analyticsToken->isTokenExist()) { | ||
$this->httpClient->request( | ||
ZendClient::POST, | ||
$this->config->getConfigDataValue($this->notifyDataChangedUrlPath), | ||
$this->getRequestJson(), | ||
['Content-Type: application/json'] | ||
); | ||
$result = true; | ||
} | ||
} catch (\Exception $e) { | ||
$this->logger->critical($e); | ||
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* Prepares request data in JSON format. | ||
* @return string | ||
*/ | ||
private function getRequestJson() | ||
{ | ||
return json_encode( | ||
[ | ||
"access-token" => $this->analyticsToken->getToken(), | ||
"url" => $this->config->getConfigDataValue( | ||
Store::XML_PATH_SECURE_BASE_URL | ||
), | ||
] | ||
); | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
app/code/Magento/Analytics/Model/ExportDataHandlerInterface.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,19 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Analytics\Model; | ||
|
||
/** | ||
* The interface represents the type of classes that handling of a new data collection for MBI. | ||
*/ | ||
interface ExportDataHandlerInterface | ||
{ | ||
/** | ||
* Execute collecting new data for MBI. | ||
* | ||
* @return bool | ||
*/ | ||
public function prepareExportData(); | ||
} |
49 changes: 49 additions & 0 deletions
49
app/code/Magento/Analytics/Model/ExportDataHandlerNotification.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,49 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Analytics\Model; | ||
|
||
use Magento\Analytics\Model\ExportDataHandler; | ||
|
||
/** | ||
* Class which add notification behaviour to classes that handling of a new data collection for MBI. | ||
*/ | ||
class ExportDataHandlerNotification implements ExportDataHandlerInterface | ||
{ | ||
/** | ||
* @var ExportDataHandler | ||
*/ | ||
private $exportDataHandler; | ||
|
||
/** | ||
* @var Connector | ||
*/ | ||
private $analyticsConnector; | ||
|
||
/** | ||
* ExportDataHandlerNotification constructor. | ||
* | ||
* @param ExportDataHandlerInterface $exportDataHandler | ||
* @param Connector $connector | ||
*/ | ||
public function __construct(ExportDataHandler $exportDataHandler, Connector $connector) | ||
{ | ||
$this->exportDataHandler = $exportDataHandler; | ||
$this->analyticsConnector = $connector; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* Execute notification command. | ||
* | ||
* @return bool | ||
*/ | ||
public function prepareExportData() | ||
{ | ||
$result = $this->exportDataHandler->prepareExportData(); | ||
$this->analyticsConnector->execute('notifyDataChanged'); | ||
return $result; | ||
} | ||
} |
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
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
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
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
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.