- md5
- bb8cdcd3b0dd5ad6498022273d1e014e
- sha1
- f17ec71f38f0b74a39ea4182edc075493c937118
- sha256
- f1c1bc3ad85235f7a2074790be1d022fddb26e7996e074c771ab40c3dc245061
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
<?php
/**
* @package Joomla.Plugin
* @subpackage System.sessiongc
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Session\MetadataManager;
/**
* Garbage collection handler for session related data
*
* @since 3.8.6
*/
class PlgSystemSessionGc extends CMSPlugin
{
/**
* Application object
*
* @var CMSApplication
* @since 3.8.6
*/
protected $app;
/**
* Database driver
*
* @var \Joomla\Database\DatabaseDriver
* @since 3.8.6
*/
protected $db;
/**
* Runs after the HTTP response has been sent to the client and performs garbage collection tasks
*
* @return void
*
* @since 3.8.6
*/
public function onAfterRespond()
{
if ($this->params->get('enable_session_gc', 1)) {
$probability = $this->params->get('gc_probability', 1);
$divisor = $this->params->get('gc_divisor', 100);
$random = $divisor * lcg_value();
if ($probability > 0 && $random < $probability) {
$this->app->getSession()->gc();
}
}
if ($this->app->get('session_handler', 'none') !== 'database' && $this->params->get('enable_session_metadata_gc', 1)) {
$probability = $this->params->get('gc_probability', 1);
$divisor = $this->params->get('gc_divisor', 100);
$random = $divisor * lcg_value();
if ($probability > 0 && $random < $probability) {
/** @var MetadataManager $metadataManager */
$metadataManager = Factory::getContainer()->get(MetadataManager::class);
$metadataManager->deletePriorTo(time() - $this->app->getSession()->getExpire());
}
}
}
}
The same content is in 5 releases, Joomla 4.2.0-beta3 to 4.2.1-rc2. See them all, or every version of this file.