Skip to content

Commit

Permalink
[5] Task parameter SessionGC removal (#41685)
Browse files Browse the repository at this point in the history
* task param removal

* param removal

* task param removal

* task param removal

* remove task param

* remove task param
  • Loading branch information
alikon authored Sep 12, 2023
1 parent 0a3d5ba commit 60e1e36
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 49 deletions.
2 changes: 0 additions & 2 deletions administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
];
Expand Down
6 changes: 1 addition & 5 deletions administrator/language/en-GB/plg_task_sessiongc.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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."
2 changes: 1 addition & 1 deletion installation/sql/mysql/extensions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);

-- --------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion installation/sql/postgresql/extensions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 0 additions & 24 deletions plugins/task/sessiongc/forms/sessionGCForm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,6 @@
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>

<field
name="gc_probability"
type="number"
label="PLG_TASK_SESSIONGC_GC_PROBABILITY_LABEL"
description="PLG_TASK_SESSIONGC_GC_PROBABILITY_DESC"
filter="uint"
validate="number"
min="1"
default="1"
showon="enable_session_gc:1[OR]enable_session_metadata_gc:1"
/>

<field
name="gc_divisor"
type="number"
label="PLG_TASK_SESSIONGC_GC_DIVISOR_LABEL"
description="PLG_TASK_SESSIONGC_GC_DIVISOR_DESC"
filter="uint"
validate="number"
min="1"
default="100"
showon="enable_session_gc:1[OR]enable_session_metadata_gc:1"
/>
</fieldset>
</fields>
</form>
18 changes: 2 additions & 16 deletions plugins/task/sessiongc/src/Extension/SessionGC.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 60e1e36

Please sign in to comment.