Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FrontendActionsFlush.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Catalog\Cron;
7 
11 
18 {
22  private $productFrontendActionResource;
23 
27  private $frontendStorageConfigurationPool;
28 
33  public function __construct(
34  ProductFrontendAction $productFrontendActionResource,
35  FrontendStorageConfigurationPool $frontendStorageConfigurationPool
36  ) {
37  $this->productFrontendActionResource = $productFrontendActionResource;
38  $this->frontendStorageConfigurationPool = $frontendStorageConfigurationPool;
39  }
40 
49  private function getLifeTimeByNamespace($namespace)
50  {
51  $configurationObject = $this->frontendStorageConfigurationPool->get($namespace);
52  if ($configurationObject) {
53  $configuration = $configurationObject->get();
54  } else {
55  $configuration = [
57  ];
58  }
59 
61  }
62 
69  private function getUniqueNamespaces()
70  {
71  $adapter = $this->productFrontendActionResource->getConnection();
72  $query = $adapter->select()
73  ->from($this->productFrontendActionResource->getMainTable(), ['action_id', 'type_id'])
74  ->group('type_id');
75 
76  return $adapter->fetchPairs($query);
77  }
78 
82  public function execute()
83  {
84  $adapter = $this->productFrontendActionResource->getConnection();
85 
86  foreach ($this->getUniqueNamespaces() as $namespace) {
87  $lifeTime = $this->getLifeTimeByNamespace($namespace);
88 
89  $where = [
90  $adapter->quoteInto('added_at < ?', time() - $lifeTime)
91  ];
92 
93  $adapter->delete($this->productFrontendActionResource->getMainTable(), $where);
94  }
95  }
96 }
$configuration
Definition: index.php:33
__construct(ProductFrontendAction $productFrontendActionResource, FrontendStorageConfigurationPool $frontendStorageConfigurationPool)
$adapter
Definition: webapi_user.php:16