From 60e1e363ce38a41a252806eab539b23fdcc8e564 Mon Sep 17 00:00:00 2001 From: Nicola Galgano Date: Tue, 12 Sep 2023 13:17:01 +0200 Subject: [PATCH] [5] Task parameter SessionGC removal (#41685) * task param removal * param removal * task param removal * task param removal * remove task param * remove task param --- administrator/components/com_admin/script.php | 2 -- .../language/en-GB/plg_task_sessiongc.ini | 6 +---- installation/sql/mysql/extensions.sql | 2 +- installation/sql/postgresql/extensions.sql | 2 +- .../task/sessiongc/forms/sessionGCForm.xml | 24 ------------------- .../sessiongc/src/Extension/SessionGC.php | 18 ++------------ 6 files changed, 5 insertions(+), 49 deletions(-) diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 741580b32b993..b2bad0bd593bb 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -396,8 +396,6 @@ private function migrateSessionGCPlugin($data) 'state' => 1, 'params' => [ 'enable_session_gc' => $params->get('enable_session_gc', 1), - 'gc_probability' => $params->get('gc_probability', 1), - 'gc_divisor' => $params->get('gc_divisor', 100), 'enable_session_metadata_gc' => $params->get('enable_session_metadata_gc', 1), ], ]; diff --git a/administrator/language/en-GB/plg_task_sessiongc.ini b/administrator/language/en-GB/plg_task_sessiongc.ini index 193998cf227a6..0064055c70eb8 100644 --- a/administrator/language/en-GB/plg_task_sessiongc.ini +++ b/administrator/language/en-GB/plg_task_sessiongc.ini @@ -5,13 +5,9 @@ PLG_TASK_SESSIONGC="Task - Session Data Purge" PLG_TASK_SESSIONGC_DESC="Task Plugin that purges expired data and metadata depending on the session handler set in Global Configuration." -PLG_TASK_SESSIONGC_ENABLE_SESSION_GC_DESC="When enabled, this plugin will attempt to purge expired data based on the frequency calculated by the probability and divisor." +PLG_TASK_SESSIONGC_ENABLE_SESSION_GC_DESC="When enabled, this plugin will attempt to purge expired data." PLG_TASK_SESSIONGC_ENABLE_SESSION_GC_LABEL="Enable Session Data Cleanup" PLG_TASK_SESSIONGC_ENABLE_SESSION_METADATA_GC_DESC="When enabled, this plugin will clean optional session metadata from the database. Note that this operation will not run when the database handler is in use as that data is cleared as part of the Session Data Cleanup operation." PLG_TASK_SESSIONGC_ENABLE_SESSION_METADATA_GC_LABEL="Enable Session Metadata Cleanup" -PLG_TASK_SESSIONGC_GC_DIVISOR_DESC="In combination with the probability field, these two fields are used to determine the frequency of the session data cleanup operation being triggered on a request. The probability is calculated by using probability/divisor, eg 1/100 means there is a 1% chance that the process runs on each request." -PLG_TASK_SESSIONGC_GC_DIVISOR_LABEL="Divisor" -PLG_TASK_SESSIONGC_GC_PROBABILITY_DESC="In combination with the divisor field, these two fields are used to determine the frequency of the session data cleanup operation being triggered on a request." -PLG_TASK_SESSIONGC_GC_PROBABILITY_LABEL="Probability" PLG_TASK_SESSIONGC_TITLE="Task - Session Data Purge" PLG_TASK_SESSIONGC_XML_DESCRIPTION="Task Plugin that purges expired data and metadata depending on the session handler set in Global Configuration." diff --git a/installation/sql/mysql/extensions.sql b/installation/sql/mysql/extensions.sql index 66068e924bdc7..7c29f88f10a13 100644 --- a/installation/sql/mysql/extensions.sql +++ b/installation/sql/mysql/extensions.sql @@ -927,7 +927,7 @@ CREATE TABLE IF NOT EXISTS `#__scheduler_tasks` ( INSERT INTO `#__scheduler_tasks` (`id`, `asset_id`, `title`, `type`, `execution_rules`, `cron_rules`, `state`, `last_execution`, `next_execution`, `locked`, `params`, `created`, `created_by`) VALUES (1, 97, 'RotateLogs', 'rotation.logs', CONCAT('{"rule-type":"interval-days","interval-days":"30","exec-day":"', DATE_FORMAT(NOW(), '%e'), '","exec-time":"', TIME_FORMAT(NOW(), '%H:00'), '"}'), '{"type":"interval","exp":"P30D"}', 1, NULL, DATE_FORMAT(NOW() + INTERVAL 30 DAY, '%Y-%m-%d %H:00:00'), NULL, '{"individual_log":false,"log_file":"","notifications":{"success_mail":"0","failure_mail":"1","fatal_failure_mail":"1","orphan_mail":"1"},"logstokeep":1}', NOW(), 42), -(2, 98, 'SessionGC', 'session.gc', CONCAT('{"rule-type":"interval-hours","interval-hours":"24","exec-day":"01","exec-time":"', TIME_FORMAT(NOW(), '%H:00'), '"}'), '{"type":"interval","exp":"PT24H"}', 1, NULL, DATE_FORMAT(NOW() + INTERVAL 24 HOUR, '%Y-%m-%d %H:00:00'), NULL, '{"individual_log":false,"log_file":"","notifications":{"success_mail":"0","failure_mail":"1","fatal_failure_mail":"1","orphan_mail":"1"},"enable_session_gc":1,"enable_session_metadata_gc":1,"gc_probability":1,"gc_divisor":100}', NOW(), 42), +(2, 98, 'SessionGC', 'session.gc', CONCAT('{"rule-type":"interval-hours","interval-hours":"24","exec-day":"01","exec-time":"', TIME_FORMAT(NOW(), '%H:00'), '"}'), '{"type":"interval","exp":"PT24H"}', 1, NULL, DATE_FORMAT(NOW() + INTERVAL 24 HOUR, '%Y-%m-%d %H:00:00'), NULL, '{"individual_log":false,"log_file":"","notifications":{"success_mail":"0","failure_mail":"1","fatal_failure_mail":"1","orphan_mail":"1"},"enable_session_gc":1,"enable_session_metadata_gc":1}', NOW(), 42), (3, 99, 'UpdateNotification', 'update.notification', CONCAT('{"rule-type":"interval-hours","interval-hours":"24","exec-day":"01","exec-time":"', TIME_FORMAT(NOW(), '%H:00'), '"}'), '{"type":"interval","exp":"PT24H"}', 1, NULL, DATE_FORMAT(NOW() + INTERVAL 24 HOUR, '%Y-%m-%d %H:00:00'), NULL, '{"individual_log":false,"log_file":"","notifications":{"success_mail":"0","failure_mail":"1","fatal_failure_mail":"1","orphan_mail":"1"},"email":"","language_override":""}', NOW(), 42); -- -------------------------------------------------------- diff --git a/installation/sql/postgresql/extensions.sql b/installation/sql/postgresql/extensions.sql index 6a6efa2c5886e..44260c10055ca 100644 --- a/installation/sql/postgresql/extensions.sql +++ b/installation/sql/postgresql/extensions.sql @@ -891,7 +891,7 @@ CREATE INDEX "#__scheduler_tasks_idx_checked_out" ON "#__scheduler_tasks" ("chec INSERT INTO "#__scheduler_tasks" ("id", "asset_id", "title", "type", "execution_rules", "cron_rules", "state", "last_execution", "next_execution", "locked", "params", "created", "created_by") VALUES (1, 97, 'RotateLogs', 'rotation.logs', CONCAT('{"rule-type":"interval-days","interval-days":"30","exec-day":"', TO_CHAR(CURRENT_TIMESTAMP AT TIME ZONE 'UTC', 'FMDD'), '","exec-time":"', TO_CHAR(CURRENT_TIMESTAMP AT TIME ZONE 'UTC', 'HH24:00'), '"}'), '{"type":"interval","exp":"P30D"}', 1, NULL, TO_TIMESTAMP(TO_CHAR(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' + INTERVAL '30 days', 'YYYY-MM-DD HH24:00:00'), 'YYYY-MM-DD HH24:MI:SS'), NULL, '{"individual_log":false,"log_file":"","notifications":{"success_mail":"0","failure_mail":"1","fatal_failure_mail":"1","orphan_mail":"1"},"logstokeep":1}', CURRENT_TIMESTAMP AT TIME ZONE 'UTC', 42), -(2, 98, 'SessionGC', 'session.gc', CONCAT('{"rule-type":"interval-hours","interval-hours":"24","exec-day":"01","exec-time":"', TO_CHAR(CURRENT_TIMESTAMP AT TIME ZONE 'UTC', 'HH24:00'), '"}'), '{"type":"interval","exp":"PT24H"}', 1, NULL, TO_TIMESTAMP(TO_CHAR(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' + INTERVAL '24 hours', 'YYYY-MM-DD HH24:00:00'), 'YYYY-MM-DD HH24:MI:SS'), NULL, '{"individual_log":false,"log_file":"","notifications":{"success_mail":"0","failure_mail":"1","fatal_failure_mail":"1","orphan_mail":"1"},"enable_session_gc":1,"enable_session_metadata_gc":1,"gc_probability":1,"gc_divisor":100}', CURRENT_TIMESTAMP AT TIME ZONE 'UTC', 42), +(2, 98, 'SessionGC', 'session.gc', CONCAT('{"rule-type":"interval-hours","interval-hours":"24","exec-day":"01","exec-time":"', TO_CHAR(CURRENT_TIMESTAMP AT TIME ZONE 'UTC', 'HH24:00'), '"}'), '{"type":"interval","exp":"PT24H"}', 1, NULL, TO_TIMESTAMP(TO_CHAR(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' + INTERVAL '24 hours', 'YYYY-MM-DD HH24:00:00'), 'YYYY-MM-DD HH24:MI:SS'), NULL, '{"individual_log":false,"log_file":"","notifications":{"success_mail":"0","failure_mail":"1","fatal_failure_mail":"1","orphan_mail":"1"},"enable_session_gc":1,"enable_session_metadata_gc":1}', CURRENT_TIMESTAMP AT TIME ZONE 'UTC', 42), (3, 99, 'UpdateNotification', 'update.notification', CONCAT('{"rule-type":"interval-hours","interval-hours":"24","exec-day":"01","exec-time":"', TO_CHAR(CURRENT_TIMESTAMP AT TIME ZONE 'UTC', 'HH24:00'), '"}'), '{"type":"interval","exp":"PT24H"}', 1, NULL, TO_TIMESTAMP(TO_CHAR(CURRENT_TIMESTAMP AT TIME ZONE 'UTC' + INTERVAL '24 hours', 'YYYY-MM-DD HH24:00:00'), 'YYYY-MM-DD HH24:MI:SS'), NULL, '{"individual_log":false,"log_file":"","notifications":{"success_mail":"0","failure_mail":"1","fatal_failure_mail":"1","orphan_mail":"1"},"email":"","language_override":""}', CURRENT_TIMESTAMP AT TIME ZONE 'UTC', 42); SELECT setval('#__scheduler_tasks_id_seq', 4, false); diff --git a/plugins/task/sessiongc/forms/sessionGCForm.xml b/plugins/task/sessiongc/forms/sessionGCForm.xml index 8e3fe59894a35..63802e408433c 100644 --- a/plugins/task/sessiongc/forms/sessionGCForm.xml +++ b/plugins/task/sessiongc/forms/sessionGCForm.xml @@ -27,30 +27,6 @@ - - - - diff --git a/plugins/task/sessiongc/src/Extension/SessionGC.php b/plugins/task/sessiongc/src/Extension/SessionGC.php index 8c7b353871707..956367a4844d1 100644 --- a/plugins/task/sessiongc/src/Extension/SessionGC.php +++ b/plugins/task/sessiongc/src/Extension/SessionGC.php @@ -106,27 +106,13 @@ private function sessionGC(ExecuteTaskEvent $event): int $enableGC = (int) $event->getArgument('params')->enable_session_gc ?? 1; if ($enableGC) { - $probability = (int) $event->getArgument('params')->gc_probability ?? 1; - $divisor = (int) $event->getArgument('params')->gc_divisor ?? 100; - - $random = $divisor * lcg_value(); - - if ($probability > 0 && $random < $probability) { - $this->getApplication()->getSession()->gc(); - } + $this->getApplication()->getSession()->gc(); } $enableMetadata = (int) $event->getArgument('params')->enable_session_metadata_gc ?? 1; if ($this->getApplication()->get('session_handler', 'none') !== 'database' && $enableMetadata) { - $probability = (int) $event->getArgument('params')->gc_probability ?? 1; - $divisor = (int) $event->getArgument('params')->gc_divisor ?? 100; - - $random = $divisor * lcg_value(); - - if ($probability > 0 && $random < $probability) { - $this->metadataManager->deletePriorTo(time() - $this->getApplication()->getSession()->getExpire()); - } + $this->metadataManager->deletePriorTo(time() - $this->getApplication()->getSession()->getExpire()); } $this->logTask('SessionGC end');