Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/cartforge.co/vendor/magento/module-catalog/Cron/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/cartforge.co/vendor/magento/module-catalog/Cron/FrontendActionsFlush.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Catalog\Cron;

use Magento\Catalog\Model\FrontendStorageConfigurationInterface;
use Magento\Catalog\Model\FrontendStorageConfigurationPool;
use Magento\Catalog\Model\ResourceModel\ProductFrontendAction;

/**
 * Find deprecated frontend actions (@see \Magento\Catalog\Api\Data\ProductFrontendActionInterface)
 * Frontend actions deprecates by lifetime.
 * For each scope we have own lifetime.
 */
class FrontendActionsFlush
{
    /**
     * @var ProductFrontendAction
     */
    private $productFrontendActionResource;

    /**
     * @var FrontendStorageConfigurationPool
     */
    private $frontendStorageConfigurationPool;

    /**
     * @param ProductFrontendAction $productFrontendActionResource
     * @param FrontendStorageConfigurationPool $frontendStorageConfigurationPool
     */
    public function __construct(
        ProductFrontendAction $productFrontendActionResource,
        FrontendStorageConfigurationPool $frontendStorageConfigurationPool
    ) {
        $this->productFrontendActionResource = $productFrontendActionResource;
        $this->frontendStorageConfigurationPool = $frontendStorageConfigurationPool;
    }

    /**
     * Find lifetime in configuration. Configuration is hold in Stores Configuration
     * Also this configuration is generated by:
     * @see \Magento\Catalog\Model\Widget\RecentlyViewedStorageConfiguration
     *
     * @param string $namespace
     * @return int
     */
    private function getLifeTimeByNamespace($namespace)
    {
        $configurationObject = $this->frontendStorageConfigurationPool->get($namespace);
        if ($configurationObject) {
            $configuration = $configurationObject->get();
        } else {
            $configuration = [
                'lifetime' => FrontendStorageConfigurationInterface::DEFAULT_LIFETIME
            ];
        }

        return (int)$configuration['lifetime'] ?? FrontendStorageConfigurationInterface::DEFAULT_LIFETIME;
    }

    /**
     * Retrieve unique namespaces FROM frontend actions. Namespace can be represented by:
     * recently_viewed_product, recently_compared_product, etc...
     *
     * @return array
     */
    private function getUniqueNamespaces()
    {
        $adapter = $this->productFrontendActionResource->getConnection();
        $query = $adapter->select()
            ->from($this->productFrontendActionResource->getMainTable(), ['action_id', 'type_id'])
            ->group('type_id');

        return $adapter->fetchPairs($query);
    }

    /**
     * @inheritdoc
     */
    public function execute()
    {
        $adapter = $this->productFrontendActionResource->getConnection();

        foreach ($this->getUniqueNamespaces() as $namespace) {
            $lifeTime = $this->getLifeTimeByNamespace($namespace);

            $where = [
                $adapter->quoteInto('added_at < ?', time() - $lifeTime)
            ];

            $adapter->delete($this->productFrontendActionResource->getMainTable(), $where);
        }
    }
}

Spamworldpro Mini