Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Deployments.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\HTTP\ZendClient;
9 
11 {
15  const API_URL = 'https://api.newrelic.com/deployments.xml';
16 
20  protected $config;
21 
25  protected $logger;
26 
30  protected $clientFactory;
31 
39  public function __construct(
40  \Magento\NewRelicReporting\Model\Config $config,
41  \Psr\Log\LoggerInterface $logger,
42  \Magento\Framework\HTTP\ZendClientFactory $clientFactory
43  ) {
44  $this->config = $config;
45  $this->logger = $logger;
46  $this->clientFactory = $clientFactory;
47  }
48 
58  public function setDeployment($description, $change = false, $user = false)
59  {
60  $apiUrl = $this->config->getNewRelicApiUrl();
61 
62  if (empty($apiUrl)) {
63  $this->logger->notice('New Relic API URL is blank, using fallback URL');
64  $apiUrl = self::API_URL;
65  }
66 
68  $client = $this->clientFactory->create();
69  $client->setUri($apiUrl);
70  $client->setMethod(ZendClient::POST);
71 
72  $client->setHeaders(['x-api-key' => $this->config->getNewRelicApiKey()]);
73 
74  $params = [
75  'deployment[app_name]' => $this->config->getNewRelicAppName(),
76  'deployment[application_id]' => $this->config->getNewRelicAppId(),
77  'deployment[description]' => $description,
78  'deployment[changelog]' => $change,
79  'deployment[user]' => $user
80  ];
81 
82  $client->setParameterPost($params);
83 
84  try {
85  $response = $client->request();
86  } catch (\Zend_Http_Client_Exception $e) {
87  $this->logger->critical($e);
88  return false;
89  }
90 
91  if (($response->getStatus() < 200 || $response->getStatus() > 210)) {
92  $this->logger->warning('Deployment marker request did not send a 200 status code.');
93  return false;
94  }
95 
96  return $response->getBody();
97  }
98 }
$response
Definition: 404.php:11
__construct(\Magento\NewRelicReporting\Model\Config $config, \Psr\Log\LoggerInterface $logger, \Magento\Framework\HTTP\ZendClientFactory $clientFactory)
Definition: Deployments.php:39
$user
Definition: dummy_user.php:13
$change
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18