Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReportNewRelicCron.php
Go to the documentation of this file.
1 <?php
7 
11 use Magento\NewRelicReporting\Model\CronEventFactory;
12 use Magento\NewRelicReporting\Model\Apm\DeploymentsFactory;
13 
18 {
22  protected $config;
23 
27  protected $collect;
28 
32  protected $counter;
33 
37  protected $cronEventFactory;
38 
43 
48  protected $customParameters = [];
49 
59  public function __construct(
63  CronEventFactory $cronEventFactory,
64  DeploymentsFactory $deploymentsFactory
65  ) {
66  $this->config = $config;
67  $this->collect = $collect;
68  $this->counter = $counter;
69  $this->cronEventFactory = $cronEventFactory;
70  $this->deploymentsFactory = $deploymentsFactory;
71  }
72 
79  public function addCustomParameters(array $data)
80  {
81  foreach ($data as $key => $value) {
82  $this->customParameters[$key] = $value;
83  }
84  }
85 
91  protected function reportModules()
92  {
93  $moduleData = $this->collect->getModuleData(false);
94  $moduleDataChanges = $moduleData['changes'];
95  if (count($moduleDataChanges) > 0) {
96  $enabledChangeArray = [];
97  $disabledChangeArray = [];
98  $installedChangeArray = [];
99  $uninstalledChangeArray = [];
100  foreach ($moduleDataChanges as $change) {
101  switch ($change['type']) {
102  case Config::ENABLED:
103  $enabledChangeArray[] = $change['name'] . '-' . $change['setup_version'];
104  break;
105  case Config::DISABLED:
106  $disabledChangeArray[] = $change['name'] . '-' . $change['setup_version'];
107  break;
108  case Config::INSTALLED:
109  $installedChangeArray[] = $change['name'] . '-' . $change['setup_version'];
110  break;
111  case Config::UNINSTALLED:
112  $uninstalledChangeArray[] = $change['name'] . '-' . $change['setup_version'];
113  break;
114  }
115  }
116  $this->setModuleChangeStatusDeployment($enabledChangeArray, 'Modules Enabled');
117  $this->setModuleChangeStatusDeployment($disabledChangeArray, 'Modules Disabled');
118  $this->setModuleChangeStatusDeployment($installedChangeArray, 'Modules Installed');
119  $this->setModuleChangeStatusDeployment($uninstalledChangeArray, 'Modules Uninstalled');
120  }
124  }
125 
133  protected function setModuleChangeStatusDeployment(array $changesArray, $deploymentText = '')
134  {
135  if (count($changesArray) > 0) {
136  foreach ($changesArray as $change) {
137  $this->deploymentsFactory->create()->setDeployment(
138  $deploymentText,
139  $change,
140  'cron'
141  );
142  }
143  }
144  }
145 
152  protected function reportCounts()
153  {
154  $this->addCustomParameters([
155  Config::PRODUCT_COUNT => $this->counter->getAllProductsCount(),
156  Config::CONFIGURABLE_COUNT => $this->counter->getConfigurableCount(),
157  Config::ACTIVE_COUNT => $this->counter->getActiveCatalogSize(),
158  Config::CATEGORY_COUNT => $this->counter->getCategoryCount(),
159  Config::WEBSITE_COUNT => $this->counter->getWebsiteCount(),
160  Config::STORE_VIEW_COUNT => $this->counter->getStoreViewsCount(),
161  Config::CUSTOMER_COUNT => $this->counter->getCustomerCount(),
162  ]);
163  if (!empty($this->customParameters)) {
164  $this->cronEventFactory->create()
165  ->addData($this->customParameters)
166  ->sendRequest();
167  }
168  }
169 
175  public function report()
176  {
177  if ($this->config->isNewRelicEnabled()) {
178  $this->reportCounts();
179  }
180 
181  return $this;
182  }
183 }
setModuleChangeStatusDeployment(array $changesArray, $deploymentText='')
$value
Definition: gender.phtml:16
__construct(Config $config, Collect $collect, Counter $counter, CronEventFactory $cronEventFactory, DeploymentsFactory $deploymentsFactory)
$change