mirror of
https://github.com/bdnugget/magento2.git
synced 2026-11-07 17:27:36 +00:00
60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
*
|
|
* Copyright © Magento, Inc. All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
namespace Magento\Persistent\Observer;
|
|
|
|
use Magento\Framework\Event\ObserverInterface;
|
|
|
|
class ClearExpiredCronJobObserver
|
|
{
|
|
/**
|
|
* Website collection factory
|
|
*
|
|
* @var \Magento\Store\Model\ResourceModel\Website\CollectionFactory
|
|
*/
|
|
protected $_websiteCollectionFactory;
|
|
|
|
/**
|
|
* Session factory
|
|
*
|
|
* @var \Magento\Persistent\Model\SessionFactory
|
|
*/
|
|
protected $_sessionFactory;
|
|
|
|
/**
|
|
* @param \Magento\Store\Model\ResourceModel\Website\CollectionFactory $websiteCollectionFactory
|
|
* @param \Magento\Persistent\Model\SessionFactory $sessionFactory
|
|
*/
|
|
public function __construct(
|
|
\Magento\Store\Model\ResourceModel\Website\CollectionFactory $websiteCollectionFactory,
|
|
\Magento\Persistent\Model\SessionFactory $sessionFactory
|
|
) {
|
|
$this->_websiteCollectionFactory = $websiteCollectionFactory;
|
|
$this->_sessionFactory = $sessionFactory;
|
|
}
|
|
|
|
/**
|
|
* Clear expired persistent sessions
|
|
*
|
|
* @param \Magento\Cron\Model\Schedule $schedule
|
|
* @return $this
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
|
*/
|
|
public function execute(\Magento\Cron\Model\Schedule $schedule)
|
|
{
|
|
$websiteIds = $this->_websiteCollectionFactory->create()->getAllIds();
|
|
if (!is_array($websiteIds)) {
|
|
return $this;
|
|
}
|
|
|
|
foreach ($websiteIds as $websiteId) {
|
|
$this->_sessionFactory->create()->deleteExpired($websiteId);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|