/**
  * Update items stock status and low stock date.
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         if (!$this->newRelicWrapper->isExtensionInstalled()) {
             $this->config->disableModule();
             $this->messageManager->addError(__('The New Relic integration requires the newrelic-php5 agent, which is not installed. More 
                     information on installing the agent is available <a target="_blank" href="%1">here</a>.', 'https://docs.newrelic.com/docs/agents/php-agent/installation/php-agent-installation-overview'), $this->messageManager->getDefaultGroup());
         }
     }
 }
 /**
  * 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;
 }
 /**
  * Report system cache is flushed to New Relic
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         $user = $this->backendAuthSession->getUser();
         if ($user->getId()) {
             $this->deploymentsFactory->create()->setDeployment('Cache Flush', $user->getUsername() . ' flushed the cache.', $user->getUsername());
         }
     }
 }
 /**
  * Reports a system cache flush to the database reporting_system_updates table
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         $jsonData = ['status' => 'updated'];
         $modelData = ['type' => Config::FLUSH_CACHE, 'action' => $this->jsonEncoder->encode($jsonData)];
         /** @var \Magento\NewRelicReporting\Model\System $systemModel */
         $systemModel = $this->systemFactory->create();
         $systemModel->setData($modelData);
         $systemModel->save();
     }
 }
 /**
  * Adds New Relic custom parameters per adminhtml request for current admin user, if applicable
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         if ($this->backendAuthSession->isLoggedIn()) {
             $user = $this->backendAuthSession->getUser();
             $this->newRelicWrapper->addCustomParameter(Config::ADMIN_USER_ID, $user->getId());
             $this->newRelicWrapper->addCustomParameter(Config::ADMIN_USER, $user->getUsername());
             $this->newRelicWrapper->addCustomParameter(Config::ADMIN_NAME, $user->getFirstname() . ' ' . $user->getLastname());
         }
     }
 }
 /**
  * Reports any products created or updated to New Relic
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         /** @var \Magento\Catalog\Model\Product $product */
         $product = $observer->getEvent()->getProduct();
         if ($product->isObjectNew()) {
             $this->newRelicWrapper->addCustomParameter(\Magento\NewRelicReporting\Model\Config::PRODUCT_CHANGE, 'create');
         } else {
             $this->newRelicWrapper->addCustomParameter(\Magento\NewRelicReporting\Model\Config::PRODUCT_CHANGE, 'update');
         }
     }
 }
 /**
  * Adds New Relic custom parameters per request for store, website, and logged in user if applicable
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         $this->newRelicWrapper->addCustomParameter(Config::STORE, $this->storeManager->getStore()->getName());
         $this->newRelicWrapper->addCustomParameter(Config::WEBSITE, $this->storeManager->getWebsite()->getName());
         if ($this->customerSession->isLoggedIn()) {
             $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
             $this->newRelicWrapper->addCustomParameter(Config::CUSTOMER_ID, $customer->getId());
             $this->newRelicWrapper->addCustomParameter(Config::CUSTOMER_NAME, $customer->getFirstname() . ' ' . $customer->getLastname());
         }
     }
 }
 /**
  * Reports any products deleted to the database reporting_system_updates table
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         /** @var \Magento\Catalog\Model\Product $product */
         $product = $observer->getEvent()->getProduct();
         $jsonData = ['id' => $product->getId(), 'status' => 'deleted'];
         $modelData = ['type' => Config::PRODUCT_CHANGE, 'action' => $this->jsonEncoder->encode($jsonData), 'updated_at' => $this->dateTime->formatDate(true)];
         /** @var \Magento\NewRelicReporting\Model\System $systemModel */
         $systemModel = $this->systemFactory->create();
         $systemModel->setData($modelData);
         $systemModel->save();
     }
 }
 /**
  * Reports orders placed to New Relic
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         /** @var \Magento\Sales\Model\Order $order */
         $order = $observer->getEvent()->getOrder();
         $itemCount = $order->getTotalItemCount();
         if (!is_numeric($itemCount) && empty($itemCount)) {
             $itemCount = $order->getTotalQtyOrdered();
         }
         $this->newRelicWrapper->addCustomParameter(Config::ORDER_PLACED, 1);
         $this->newRelicWrapper->addCustomParameter(Config::ORDER_ITEMS, $itemCount);
         $this->newRelicWrapper->addCustomParameter(Config::ORDER_VALUE, $order->getBaseGrandTotal());
     }
 }
 /**
  * Reports concurrent admins to the database reporting_users table
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         if ($this->backendAuthSession->isLoggedIn()) {
             $user = $this->backendAuthSession->getUser();
             $jsonData = ['id' => $user->getId(), 'username' => $user->getUsername(), 'name' => $user->getFirstname() . ' ' . $user->getLastname()];
             $modelData = ['type' => 'admin_activity', 'action' => $this->jsonEncoder->encode($jsonData)];
             /** @var \Magento\NewRelicReporting\Model\Users $usersModel */
             $usersModel = $this->usersFactory->create();
             $usersModel->setData($modelData);
             $usersModel->save();
         }
     }
 }
 /**
  * Reports concurrent users to the database reporting_users table
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         if ($this->customerSession->isLoggedIn()) {
             $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
             $jsonData = ['id' => $customer->getId(), 'name' => $customer->getFirstname() . ' ' . $customer->getLastname(), 'store' => $this->storeManager->getStore()->getName(), 'website' => $this->storeManager->getWebsite()->getName()];
             $modelData = ['type' => 'user_action', 'action' => $this->jsonEncoder->encode($jsonData), 'updated_at' => $this->dateTime->formatDate(true)];
             /** @var \Magento\NewRelicReporting\Model\Users $usersModel */
             $usersModel = $this->usersFactory->create();
             $usersModel->setData($modelData);
             $usersModel->save();
         }
     }
 }
 /**
  * Reports orders placed to the database reporting_orders table
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         /** @var \Magento\Sales\Model\Order $order */
         $order = $observer->getEvent()->getOrder();
         $itemCount = $order->getTotalItemCount();
         if (!is_numeric($itemCount) && empty($itemCount)) {
             $itemCount = $order->getTotalQtyOrdered();
         }
         $modelData = ['customer_id' => $order->getCustomerId(), 'total' => $order->getGrandTotal(), 'total_base' => $order->getBaseGrandTotal(), 'item_count' => $itemCount];
         /** @var \Magento\NewRelicReporting\Model\Orders $orderModel */
         $orderModel = $this->ordersFactory->create();
         $orderModel->setData($modelData);
         $orderModel->save();
     }
 }
 /**
  * Reports info to New Relic by Cron
  *
  * @return \Magento\NewRelicReporting\Model\Cron\ReportCounts
  */
 public function report()
 {
     if ($this->config->isNewRelicEnabled()) {
         $this->reportModules();
         $this->reportCounts();
     }
     return $this;
 }
 /**
  * Reports Modules and module changes to the database reporting_module_status table
  *
  * @return \Magento\NewRelicReporting\Model\Cron\ReportCounts
  */
 public function report()
 {
     if ($this->config->isNewRelicEnabled()) {
         $this->reportProductsSize();
         $this->reportConfigurableProductsSize();
         $this->reportProductsActive();
         $this->reportCategorySize();
     }
     return $this;
 }
 /**
  * Reports any products created or updated to the database reporting_system_updates table
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         /** @var \Magento\Catalog\Model\Product $product */
         $product = $observer->getEvent()->getProduct();
         $jsonData = ['name' => $product->getName()];
         if ($product->isObjectNew()) {
             $jsonData['status'] = 'created';
         } else {
             $jsonData['id'] = $product->getId();
             $jsonData['status'] = 'updated';
         }
         $modelData = ['type' => Config::PRODUCT_CHANGE, 'action' => $this->jsonEncoder->encode($jsonData)];
         /** @var \Magento\NewRelicReporting\Model\System $systemModel */
         $systemModel = $this->systemFactory->create();
         $systemModel->setData($modelData);
         $systemModel->save();
     }
 }
 /**
  * Reports any products deleted to New Relic
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         $this->newRelicWrapper->addCustomParameter(Config::PRODUCT_CHANGE, 'delete');
     }
 }