ReportSystemCacheFlush.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\NewRelicReporting\Model\Observer;
  7. use Magento\Framework\Event\Observer;
  8. use Magento\Framework\Event\ObserverInterface;
  9. use Magento\NewRelicReporting\Model\Config;
  10. /**
  11. * Class ReportSystemCacheFlush
  12. */
  13. class ReportSystemCacheFlush implements ObserverInterface
  14. {
  15. /**
  16. * @var Config
  17. */
  18. protected $config;
  19. /**
  20. * @var \Magento\NewRelicReporting\Model\SystemFactory
  21. */
  22. protected $systemFactory;
  23. /**
  24. * @var \Magento\Framework\Json\EncoderInterface
  25. */
  26. protected $jsonEncoder;
  27. /**
  28. * @param Config $config
  29. * @param \Magento\NewRelicReporting\Model\SystemFactory $systemFactory
  30. * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
  31. */
  32. public function __construct(
  33. Config $config,
  34. \Magento\NewRelicReporting\Model\SystemFactory $systemFactory,
  35. \Magento\Framework\Json\EncoderInterface $jsonEncoder
  36. ) {
  37. $this->config = $config;
  38. $this->systemFactory = $systemFactory;
  39. $this->jsonEncoder = $jsonEncoder;
  40. }
  41. /**
  42. * Reports a system cache flush to the database reporting_system_updates table
  43. *
  44. * @param Observer $observer
  45. * @return void
  46. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  47. */
  48. public function execute(Observer $observer)
  49. {
  50. if ($this->config->isNewRelicEnabled()) {
  51. $jsonData = ['status' => 'updated'];
  52. $modelData = [
  53. 'type' => Config::FLUSH_CACHE,
  54. 'action' => $this->jsonEncoder->encode($jsonData)
  55. ];
  56. /** @var \Magento\NewRelicReporting\Model\System $systemModel */
  57. $systemModel = $this->systemFactory->create();
  58. $systemModel->setData($modelData);
  59. $systemModel->save();
  60. }
  61. }
  62. }