Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MarkUserNotified.php
Go to the documentation of this file.
1 <?php
8 
14 use Psr\Log\LoggerInterface;
15 
19 class MarkUserNotified extends Action
20 {
24  private $productMetadata;
25 
29  private $notificationLogger;
30 
34  private $logger;
35 
44  public function __construct(
45  Action\Context $context,
46  ProductMetadataInterface $productMetadata,
47  NotificationLogger $notificationLogger,
48  LoggerInterface $logger
49  ) {
50  parent::__construct($context);
51  $this->productMetadata = $productMetadata;
52  $this->notificationLogger = $notificationLogger;
53  $this->logger = $logger;
54  }
55 
61  public function execute()
62  {
63  try {
64  $responseContent = [
65  'success' => $this->notificationLogger->log(
66  $this->_auth->getUser()->getId(),
67  $this->productMetadata->getVersion()
68  ),
69  'error_message' => ''
70  ];
71  } catch (LocalizedException $e) {
72  $this->logger->error($e->getMessage());
73  $responseContent = [
74  'success' => false,
75  'error_message' => $e->getMessage()
76  ];
77  } catch (\Exception $e) {
78  $this->logger->error($e->getMessage());
79  $responseContent = [
80  'success' => false,
81  'error_message' => __('It is impossible to log user action')
82  ];
83  }
84  $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
85  return $resultJson->setData($responseContent);
86  }
87 
91  protected function _isAllowed()
92  {
93  return parent::_isAllowed();
94  }
95 }
__construct(Action\Context $context, ProductMetadataInterface $productMetadata, NotificationLogger $notificationLogger, LoggerInterface $logger)
__()
Definition: __.php:13
$logger