/** * Reports Modules and module changes to the database reporting_module_status table * * @return \Magento\NewRelicReporting\Model\Cron\ReportModulesInfo */ public function report() { if ($this->config->isNewRelicEnabled()) { $moduleData = $this->collect->getModuleData(); if (count($moduleData['changes']) > 0) { foreach ($moduleData['changes'] as $change) { switch ($change['type']) { case Config::ENABLED: $modelData = ['type' => Config::MODULE_ENABLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)]; break; case Config::DISABLED: $modelData = ['type' => Config::MODULE_DISABLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)]; break; case Config::INSTALLED: $modelData = ['type' => Config::MODULE_INSTALLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)]; break; case Config::UNINSTALLED: $modelData = ['type' => Config::MODULE_UNINSTALLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)]; break; } /** @var \Magento\NewRelicReporting\Model\System $systemModel */ $systemModel = $this->systemFactory->create(); $systemModel->setData($modelData); $systemModel->save(); } } } return $this; }
/** * Reports current total module counts to Insights * * @return void */ protected function reportModules() { $moduleData = $this->collect->getModuleData(false); $moduleDataChanges = $moduleData['changes']; if (count($moduleDataChanges) > 0) { $enabledChangeArray = []; $disabledChangeArray = []; $installedChangeArray = []; $uninstalledChangeArray = []; foreach ($moduleDataChanges as $change) { switch ($change['type']) { case Config::ENABLED: $enabledChangeArray[] = $change['name'] . '-' . $change['setup_version']; break; case Config::DISABLED: $disabledChangeArray[] = $change['name'] . '-' . $change['setup_version']; break; case Config::INSTALLED: $installedChangeArray[] = $change['name'] . '-' . $change['setup_version']; break; case Config::UNINSTALLED: $uninstalledChangeArray[] = $change['name'] . '-' . $change['setup_version']; break; } } $this->setModuleChangeStatusDeployment($enabledChangeArray, 'Modules Enabled'); $this->setModuleChangeStatusDeployment($disabledChangeArray, 'Modules Disabled'); $this->setModuleChangeStatusDeployment($installedChangeArray, 'Modules Installed'); $this->setModuleChangeStatusDeployment($uninstalledChangeArray, 'Modules Uninstalled'); } $this->addCustomParameters([Config::MODULES_ENABLED => $moduleData[Config::ENABLED]]); $this->addCustomParameters([Config::MODULES_DISABLED => $moduleData[Config::DISABLED]]); $this->addCustomParameters([Config::MODULES_INSTALLED => $moduleData[Config::INSTALLED]]); }
/** * Tests modules data returns array and saving in DB * * @dataProvider itemDataProvider * @return void */ public function testGetModuleDataRefreshOrStatement($data) { $moduleCollectionMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\ResourceModel\\Module\\Collection')->disableOriginalConstructor()->getMock(); /** @var \Magento\NewRelicReporting\Model\Module|\PHPUnit_Framework_MockObject_MockObject $itemMock */ $itemMock = $this->getMock('Magento\\NewRelicReporting\\Model\\Module', ['getName', 'getData', 'setData', 'getState', 'save'], [], '', false); $modulesMockArray = ['Module_Name1' => ['name' => 'Module_Name1', 'setup_version' => '2.0.0', 'sequence' => []]]; $itemMock->setData($data); $testChangesMockArray = ['entity_id' => '3', 'name' => 'Name', 'active' => 'false', 'state' => 'enabled', 'setup_version' => '2.0.0', 'some_param' => 'some_value', 'updated_at' => '2015-09-02 18:38:17']; $itemMockArray = [$itemMock]; $enabledModulesMockArray = ['Module_Name2']; $allModulesMockArray = ['Module_Name1', 'Module_Name2']; $this->moduleCollectionFactoryMock->expects($this->any())->method('create')->willReturn($moduleCollectionMock); $this->moduleFactoryMock->expects($this->any())->method('create')->willReturn($itemMock); $itemMock->expects($this->any())->method('setData')->willReturnSelf(); $itemMock->expects($this->any())->method('save')->willReturnSelf(); $itemMock->expects($this->any())->method('getState')->willReturn($data['state']); $itemMock->expects($this->any())->method('getName')->willReturn($data['name']); $moduleCollectionMock->expects($this->any())->method('getItems')->willReturn($itemMockArray); $itemMock->expects($this->any())->method('getData')->willReturn($testChangesMockArray); $this->fullModuleListMock->expects($this->once())->method('getAll')->willReturn($modulesMockArray); $this->fullModuleListMock->expects($this->any())->method('getNames')->willReturn($allModulesMockArray); $this->moduleListMock->expects($this->any())->method('getNames')->willReturn($enabledModulesMockArray); $this->moduleManagerMock->expects($this->any())->method('isOutputEnabled')->will($this->returnValue(true)); $this->assertInternalType('array', $this->model->getModuleData()); }