Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RefreshRecent.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
10 
14 class RefreshRecent extends \Magento\Reports\Controller\Adminhtml\Report\Statistics implements HttpPostActionInterface
15 {
21  public function execute()
22  {
23  try {
24  $collectionsNames = $this->_getCollectionNames();
26  $currentDate = $this->_objectManager->get(
27  \Magento\Framework\Stdlib\DateTime\TimezoneInterface::class
28  )->date();
29  $date = $currentDate->modify('-25 hours');
30  foreach ($collectionsNames as $collectionName) {
31  $this->_objectManager->create($collectionName)->aggregate($date);
32  }
33  $this->messageManager->addSuccess(__('Recent statistics have been updated.'));
34  } catch (\Magento\Framework\Exception\LocalizedException $e) {
35  $this->messageManager->addError($e->getMessage());
36  } catch (\Exception $e) {
37  $this->messageManager->addError(__('We can\'t refresh recent statistics.'));
38  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
39  }
40 
41  if ($this->_getSession()->isFirstPageAfterLogin()) {
42  $this->_redirect('adminhtml/*');
43  } else {
44  $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl('*/*'));
45  }
46  }
47 }
__()
Definition: __.php:13