JoomlaPolska / jezyk-J4

Język polski dla Joomla 4
GNU General Public License v2.0
3 stars 5 forks source link

[5] add2scheduler-sessiongc #423

Closed joomlapl-bot closed 7 months ago

joomlapl-bot commented 1 year ago

PR w związku ze zmianą oryginału https://github.com/joomla/joomla-cms/pull/41326 Poniżej zmiany w oryginale:

Click to expand the diff! ```diff diff --git a/administrator/components/com_admin/script.php b/administrator/components/com_admin/script.php index 3f5cf6cb4d666..5fb9fae46931c 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -237,6 +237,7 @@ protected function uninstallExtensions() ['type' => 'plugin', 'element' => 'compat', 'folder' => 'system', 'client_id' => 0, 'pre_function' => 'migrateCompatPlugin'], ['type' => 'plugin', 'element' => 'logrotation', 'folder' => 'system', 'client_id' => 0, 'pre_function' => 'migrateLogRotationPlugin'], ['type' => 'plugin', 'element' => 'recaptcha', 'folder' => 'captcha', 'client_id' => 0, 'pre_function' => null], + ['type' => 'plugin', 'element' => 'sessiongc', 'folder' => 'system', 'client_id' => 0, 'pre_function' => 'migrateSessionGCPlugin'], ['type' => 'plugin', 'element' => 'updatenotification', 'folder' => 'system', 'client_id' => 0, 'pre_function' => 'migrateUpdatenotificationPlugin'], ]; @@ -360,6 +361,49 @@ private function migrateLogRotationPlugin($data) $model->save($task); } + /** + * This method is for migration for old updatenotification system plugin migration to task. + * + * @param \stdClass $data Object with the extension's record in the `#__extensions` table + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + private function migrateSessionGCPlugin($data) + { + if (!$data->enabled) { + return; + } + + // Get the plugin parameters + $params = new Registry($data->params); + + /** @var SchedulerComponent $component */ + $component = Factory::getApplication()->bootComponent('com_scheduler'); + + /** @var TaskModel $model */ + $model = $component->getMVCFactory()->createModel('Task', 'Administrator', ['ignore_request' => true]); + $task = [ + 'title' => 'SessionGC', + 'type' => 'session.gc', + 'execution_rules' => [ + 'rule-type' => 'interval-hours', + 'interval-hours' => 24, + 'exec-time' => gmdate('H:i'), + 'exec-day' => gmdate('d'), + ], + '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), + ], + ]; + $model->save($task); + } + /** * This method is for migration for old updatenotification system plugin migration to task. * diff --git a/administrator/components/com_admin/sql/updates/mysql/5.0.0-2023-09-02.sql b/administrator/components/com_admin/sql/updates/mysql/5.0.0-2023-09-02.sql index 4e74349940933..220f69cf47de2 100644 --- a/administrator/components/com_admin/sql/updates/mysql/5.0.0-2023-09-02.sql +++ b/administrator/components/com_admin/sql/updates/mysql/5.0.0-2023-09-02.sql @@ -2,6 +2,7 @@ INSERT INTO `#__extensions` (`name`, `type`, `element`, `folder`, `client_id`, ` ('plg_task_deleteactionlogs', 'plugin', 'deleteactionlogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0), ('plg_task_privacyconsent', 'plugin', 'privacyconsent', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0), ('plg_task_rotatelogs', 'plugin', 'rotatelogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0), +('plg_task_sessiongc', 'plugin', 'sessiongc', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0), ('plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0); INSERT INTO `#__mail_templates` (`template_id`, `extension`, `language`, `subject`, `body`, `htmlbody`, `attachments`, `params`) VALUES diff --git a/administrator/components/com_admin/sql/updates/postgresql/5.0.0-2023-09-02.sql b/administrator/components/com_admin/sql/updates/postgresql/5.0.0-2023-09-02.sql index 08e8541039d17..42bdee445b720 100644 --- a/administrator/components/com_admin/sql/updates/postgresql/5.0.0-2023-09-02.sql +++ b/administrator/components/com_admin/sql/updates/postgresql/5.0.0-2023-09-02.sql @@ -2,6 +2,7 @@ INSERT INTO "#__extensions" ("name", "type", "element", "folder", "client_id", " ('plg_task_deleteactionlogs', 'plugin', 'deleteactionlogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0), ('plg_task_privacyconsent', 'plugin', 'privacyconsent', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0), ('plg_task_rotatelogs', 'plugin', 'rotatelogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0), +('plg_task_sessiongc', 'plugin', 'sessiongc', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0), ('plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0); INSERT INTO "#__mail_templates" ("template_id", "extension", "language", "subject", "body", "htmlbody", "attachments", "params") VALUES diff --git a/administrator/language/en-GB/plg_system_sessiongc.ini b/administrator/language/en-GB/plg_system_sessiongc.ini deleted file mode 100644 index 092adec836261..0000000000000 --- a/administrator/language/en-GB/plg_system_sessiongc.ini +++ /dev/null @@ -1,15 +0,0 @@ -; Joomla! Project -; (C) 2018 Open Source Matters, Inc. -; License GNU General Public License version 2 or later; see LICENSE.txt -; Note : All ini files need to be saved as UTF-8 - -PLG_SYSTEM_SESSIONGC="System - Session Data Purge" -PLG_SYSTEM_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_SYSTEM_SESSIONGC_ENABLE_SESSION_GC_LABEL="Enable Session Data Cleanup" -PLG_SYSTEM_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_SYSTEM_SESSIONGC_ENABLE_SESSION_METADATA_GC_LABEL="Enable Session Metadata Cleanup" -PLG_SYSTEM_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_SYSTEM_SESSIONGC_GC_DIVISOR_LABEL="Divisor" -PLG_SYSTEM_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_SYSTEM_SESSIONGC_GC_PROBABILITY_LABEL="Probability" -PLG_SYSTEM_SESSIONGC_XML_DESCRIPTION="System Plugin that purges expired data and metadata depending on the session handler set in Global Configuration." diff --git a/administrator/language/en-GB/plg_system_sessiongc.sys.ini b/administrator/language/en-GB/plg_system_sessiongc.sys.ini deleted file mode 100644 index f5fc9424fbddb..0000000000000 --- a/administrator/language/en-GB/plg_system_sessiongc.sys.ini +++ /dev/null @@ -1,7 +0,0 @@ -; Joomla! Project -; (C) 2018 Open Source Matters, Inc. -; License GNU General Public License version 2 or later; see LICENSE.txt -; Note : All ini files need to be saved as UTF-8 - -PLG_SYSTEM_SESSIONGC="System - Session Data Purge" -PLG_SYSTEM_SESSIONGC_XML_DESCRIPTION="System Plugin that purges expired data and metadata depending on the session handler set in Global Configuration." diff --git a/administrator/language/en-GB/plg_task_sessiongc.ini b/administrator/language/en-GB/plg_task_sessiongc.ini new file mode 100644 index 0000000000000..9a69bf8f87dd9 --- /dev/null +++ b/administrator/language/en-GB/plg_task_sessiongc.ini @@ -0,0 +1,17 @@ +; Joomla! Project +; (C) 2023 Open Source Matters, Inc. +; License GNU General Public License version 2 or later; see LICENSE.txt +; Note : All ini files need to be saved as UTF-8 + +PLG_TASK_SESSIONGC="Task - Session Data Purge" +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_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_XML_DESCRIPTION="Task Plugin that purges expired data and metadata depending on the session handler set in Global Configuration." +PLG_TASK_SESSIONGC_TITLE="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." diff --git a/administrator/language/en-GB/plg_task_sessiongc.sys.ini b/administrator/language/en-GB/plg_task_sessiongc.sys.ini new file mode 100644 index 0000000000000..2cddadffd9d7b --- /dev/null +++ b/administrator/language/en-GB/plg_task_sessiongc.sys.ini @@ -0,0 +1,9 @@ +; Joomla! Project +; (C) 2023 Open Source Matters, Inc. +; License GNU General Public License version 2 or later; see LICENSE.txt +; Note : All ini files need to be saved as UTF-8 + +PLG_TASK_SESSIONGC="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." +PLG_TASK_SESSIONGC_TITLE="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." \ No newline at end of file diff --git a/installation/sql/mysql/base.sql b/installation/sql/mysql/base.sql index b978a5c41fc33..62262b328c0c6 100644 --- a/installation/sql/mysql/base.sql +++ b/installation/sql/mysql/base.sql @@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS `#__assets` ( -- INSERT INTO `#__assets` (`id`, `parent_id`, `lft`, `rgt`, `level`, `name`, `title`, `rules`) VALUES -(1, 0, 0, 181, 0, 'root.1', 'Root Asset', '{"core.login.site":{"6":1,"2":1},"core.login.admin":{"6":1},"core.login.api":{"8":1},"core.login.offline":{"6":1},"core.admin":{"8":1},"core.manage":{"7":1},"core.create":{"6":1,"3":1},"core.delete":{"6":1},"core.edit":{"6":1,"4":1},"core.edit.state":{"6":1,"5":1},"core.edit.own":{"6":1,"3":1}}'), +(1, 0, 0, 183, 0, 'root.1', 'Root Asset', '{"core.login.site":{"6":1,"2":1},"core.login.admin":{"6":1},"core.login.api":{"8":1},"core.login.offline":{"6":1},"core.admin":{"8":1},"core.manage":{"7":1},"core.create":{"6":1,"3":1},"core.delete":{"6":1},"core.edit":{"6":1,"4":1},"core.edit.state":{"6":1,"5":1},"core.edit.own":{"6":1,"3":1}}'), (2, 1, 1, 2, 1, 'com_admin', 'com_admin', '{}'), (3, 1, 3, 6, 1, 'com_banners', 'com_banners', '{"core.admin":{"7":1},"core.manage":{"6":1}}'), (4, 1, 7, 8, 1, 'com_cache', 'com_cache', '{"core.admin":{"7":1},"core.manage":{"7":1}}'), @@ -115,7 +115,8 @@ INSERT INTO `#__assets` (`id`, `parent_id`, `lft`, `rgt`, `level`, `name`, `titl (95, 1, 175, 176, 1, 'com_guidedtours', 'com_guidedtours', '{}'), (96, 18, 130, 131, 2, 'com_modules.module.109', 'Guided Tours', '{}'), (97, 1, 177, 178, 1, 'com_scheduler.task.1', 'com_scheduler.task.1', '{}'), -(98, 1, 179, 180, 1, 'com_scheduler.task.2', 'com_scheduler.task.2', '{}'); +(98, 1, 179, 180, 1, 'com_scheduler.task.2', 'com_scheduler.task.2', '{}'), +(99, 1, 181, 182, 1, 'com_scheduler.task.3', 'com_scheduler.task.3', '{}'); -- -------------------------------------------------------- @@ -357,7 +358,6 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, (0, 'plg_system_schedulerunner', 'plugin', 'schedulerunner', 'system', 0, 1, 1, 0, 1, '', '{}', '', 17, 0), (0, 'plg_system_schemaorg', 'plugin', 'schemaorg', 'system', 0, 1, 1, 0, 0, '', '{}', '', 18, 0), (0, 'plg_system_sef', 'plugin', 'sef', 'system', 0, 1, 1, 0, 1, '', '', '', 19, 0), -(0, 'plg_system_sessiongc', 'plugin', 'sessiongc', 'system', 0, 1, 1, 0, 1, '', '', '', 20, 0), (0, 'plg_system_shortcut', 'plugin', 'shortcut', 'system', 0, 1, 1, 0, 1, '', '{}', '', 21, 0), (0, 'plg_system_skipto', 'plugin', 'skipto', 'system', 0, 1, 1, 0, 1, '', '{}', '', 22, 0), (0, 'plg_system_stats', 'plugin', 'stats', 'system', 0, 1, 1, 0, 1, '', '', '', 23, 0), @@ -369,8 +369,9 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, (0, 'plg_task_requests', 'plugin', 'requests', 'task', 0, 1, 1, 0, 1, '', '{}', '', 4, 0), (0, 'plg_task_privacyconsent', 'plugin', 'privacyconsent', 'task', 0, 1, 1, 0, 1, '', '{}', '', 5, 0), (0, 'plg_task_rotatelogs', 'plugin', 'rotatelogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', 6, 0), -(0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 1, '', '{}', '', 7, 0), -(0, 'plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', 8, 0), +(0, 'plg_task_sessiongc', 'plugin', 'sessiongc', 'task', 0, 1, 1, 0, 1, '', '{}', '', 7, 0), +(0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 1, '', '{}', '', 8, 0), +(0, 'plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', 9, 0), (0, 'plg_multifactorauth_totp', 'plugin', 'totp', 'multifactorauth', 0, 1, 1, 0, 1, '', '', '', 1, 0), (0, 'plg_multifactorauth_yubikey', 'plugin', 'yubikey', 'multifactorauth', 0, 1, 1, 0, 1, '', '', '', 2, 0), (0, 'plg_multifactorauth_webauthn', 'plugin', 'webauthn', 'multifactorauth', 0, 1, 1, 0, 1, '', '', '', 3, 0), diff --git a/installation/sql/mysql/extensions.sql b/installation/sql/mysql/extensions.sql index 6e7d4734cdfe2..665f0bb84e625 100644 --- a/installation/sql/mysql/extensions.sql +++ b/installation/sql/mysql/extensions.sql @@ -927,7 +927,8 @@ 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`) 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()), -(2, 98, '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()); +(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()), +(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()); -- -------------------------------------------------------- diff --git a/installation/sql/postgresql/base.sql b/installation/sql/postgresql/base.sql index d4f3a214375fc..6d048539423b6 100644 --- a/installation/sql/postgresql/base.sql +++ b/installation/sql/postgresql/base.sql @@ -31,7 +31,7 @@ COMMENT ON COLUMN "#__assets"."rules" IS 'JSON encoded access control.'; -- INSERT INTO "#__assets" ("id", "parent_id", "lft", "rgt", "level", "name", "title", "rules") VALUES -(1, 0, 0, 181, 0, 'root.1', 'Root Asset', '{"core.login.site":{"6":1,"2":1},"core.login.admin":{"6":1},"core.login.api":{"8":1},"core.login.offline":{"6":1},"core.admin":{"8":1},"core.manage":{"7":1},"core.create":{"6":1,"3":1},"core.delete":{"6":1},"core.edit":{"6":1,"4":1},"core.edit.state":{"6":1,"5":1},"core.edit.own":{"6":1,"3":1}}'), +(1, 0, 0, 183, 0, 'root.1', 'Root Asset', '{"core.login.site":{"6":1,"2":1},"core.login.admin":{"6":1},"core.login.api":{"8":1},"core.login.offline":{"6":1},"core.admin":{"8":1},"core.manage":{"7":1},"core.create":{"6":1,"3":1},"core.delete":{"6":1},"core.edit":{"6":1,"4":1},"core.edit.state":{"6":1,"5":1},"core.edit.own":{"6":1,"3":1}}'), (2, 1, 1, 2, 1, 'com_admin', 'com_admin', '{}'), (3, 1, 3, 6, 1, 'com_banners', 'com_banners', '{"core.admin":{"7":1},"core.manage":{"6":1}}'), (4, 1, 7, 8, 1, 'com_cache', 'com_cache', '{"core.admin":{"7":1},"core.manage":{"7":1}}'), @@ -121,9 +121,10 @@ INSERT INTO "#__assets" ("id", "parent_id", "lft", "rgt", "level", "name", "titl (95, 1, 175, 176, 1, 'com_guidedtours', 'com_guidedtours', '{}'), (96, 18, 130, 131, 2, 'com_modules.module.109', 'Guided Tours', '{}'), (97, 1, 177, 178, 1, 'com_scheduler.task.1', 'com_scheduler.task.1', '{}'), -(98, 1, 179, 180, 1, 'com_scheduler.task.2', 'com_scheduler.task.2', '{}'); +(98, 1, 179, 180, 1, 'com_scheduler.task.2', 'com_scheduler.task.2', '{}'), +(99, 1, 181, 182, 1, 'com_scheduler.task.3', 'com_scheduler.task.3', '{}'); -SELECT setval('#__assets_id_seq', 99, false); +SELECT setval('#__assets_id_seq', 100, false); -- -- Table structure for table `#__extensions` @@ -363,7 +364,6 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", (0, 'plg_system_schedulerunner', 'plugin', 'schedulerunner', 'system', 0, 1, 1, 0, 1, '', '{}', '', 17, 0), (0, 'plg_system_schemaorg', 'plugin', 'schemaorg', 'system', 0, 1, 1, 0, 0, '', '{}', '', 18, 0), (0, 'plg_system_sef', 'plugin', 'sef', 'system', 0, 1, 1, 0, 1, '', '', '', 19, 0), -(0, 'plg_system_sessiongc', 'plugin', 'sessiongc', 'system', 0, 1, 1, 0, 1, '', '', '', 20, 0), (0, 'plg_system_shortcut', 'plugin', 'shortcut', 'system', 0, 1, 1, 0, 1, '', '{}', '', 21, 0), (0, 'plg_system_skipto', 'plugin', 'skipto', 'system', 0, 1, 1, 0, 1, '', '{}', '', 22, 0), (0, 'plg_system_stats', 'plugin', 'stats', 'system', 0, 1, 1, 0, 1, '', '', '', 23, 0), @@ -375,8 +375,9 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", (0, 'plg_task_requests', 'plugin', 'requests', 'task', 0, 1, 1, 0, 1, '', '{}', '', 4, 0), (0, 'plg_task_privacyconsent', 'plugin', 'privacyconsent', 'task', 0, 1, 1, 0, 1, '', '{}', '', 5, 0), (0, 'plg_task_rotatelogs', 'plugin', 'rotatelogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', 6, 0), -(0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 1, '', '{}', '', 7, 0), -(0, 'plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', 8, 0), +(0, 'plg_task_sessiongc', 'plugin', 'sessiongc', 'task', 0, 1, 1, 0, 1, '', '{}', '', 7, 0), +(0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 1, '', '{}', '', 8, 0), +(0, 'plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', 9, 0), (0, 'plg_multifactorauth_totp', 'plugin', 'totp', 'multifactorauth', 0, 1, 1, 0, 1, '', '', '', 1, 0), (0, 'plg_multifactorauth_yubikey', 'plugin', 'yubikey', 'multifactorauth', 0, 1, 1, 0, 1, '', '', '', 2, 0), (0, 'plg_multifactorauth_webauthn', 'plugin', 'webauthn', 'multifactorauth', 0, 1, 1, 0, 1, '', '', '', 3, 0), diff --git a/installation/sql/postgresql/extensions.sql b/installation/sql/postgresql/extensions.sql index abd3cfa743d1c..cc8bd964ebbc8 100644 --- a/installation/sql/postgresql/extensions.sql +++ b/installation/sql/postgresql/extensions.sql @@ -891,9 +891,10 @@ 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") 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'), -(2, 98, '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'); +(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'), +(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'); -SELECT setval('#__scheduler_tasks_id_seq', 3, false); +SELECT setval('#__scheduler_tasks_id_seq', 4, false); -- -------------------------------------------------------- diff --git a/libraries/src/Extension/ExtensionHelper.php b/libraries/src/Extension/ExtensionHelper.php index 1e2929863263c..8520cd3652d6e 100644 --- a/libraries/src/Extension/ExtensionHelper.php +++ b/libraries/src/Extension/ExtensionHelper.php @@ -309,7 +309,6 @@ class ExtensionHelper ['plugin', 'schedulerunner', 'system', 0], ['plugin', 'schemaorg', 'system', 0], ['plugin', 'sef', 'system', 0], - ['plugin', 'sessiongc', 'system', 0], ['plugin', 'shortcut', 'system', 0], ['plugin', 'skipto', 'system', 0], ['plugin', 'stats', 'system', 0], @@ -323,6 +322,7 @@ class ExtensionHelper ['plugin', 'privacyconsent', 'task', 0], ['plugin', 'requests', 'task', 0], ['plugin', 'rotatelogs', 'task', 0], + ['plugin', 'sessiongc', 'task', 0], ['plugin', 'sitestatus', 'task', 0], ['plugin', 'updatenotification', 'task', 0], diff --git a/plugins/system/sessiongc/sessiongc.xml b/plugins/system/sessiongc/sessiongc.xml deleted file mode 100644 index 4ddec915e8675..0000000000000 --- a/plugins/system/sessiongc/sessiongc.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - plg_system_sessiongc - Joomla! Project - 2018-02 - (C) 2018 Open Source Matters, Inc. - GNU General Public License version 2 or later; see LICENSE.txt - admin@joomla.org - www.joomla.org - 3.8.6 - PLG_SYSTEM_SESSIONGC_XML_DESCRIPTION - Joomla\Plugin\System\SessionGC - - services - src - - - language/en-GB/plg_system_sessiongc.ini - language/en-GB/plg_system_sessiongc.sys.ini - - - -
- - - - - - - - - - - - - -
-
-
-
diff --git a/plugins/system/sessiongc/src/Extension/SessionGC.php b/plugins/system/sessiongc/src/Extension/SessionGC.php deleted file mode 100644 index c5da6d36e326f..0000000000000 --- a/plugins/system/sessiongc/src/Extension/SessionGC.php +++ /dev/null @@ -1,84 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -namespace Joomla\Plugin\System\SessionGC\Extension; - -use Joomla\CMS\Plugin\CMSPlugin; -use Joomla\CMS\Session\MetadataManager; -use Joomla\Event\DispatcherInterface; - -// phpcs:disable PSR1.Files.SideEffects -\defined('_JEXEC') or die; -// phpcs:enable PSR1.Files.SideEffects - -/** - * Garbage collection handler for session related data - * - * @since 3.8.6 - */ -final class SessionGC extends CMSPlugin -{ - /** - * The meta data manager - * - * @var MetadataManager - * - * @since 4.4.0 - */ - private $metadataManager; - - /** - * Constructor. - * - * @param DispatcherInterface $dispatcher The dispatcher - * @param array $config An optional associative array of configuration settings - * @param MetadataManager $metadataManager The user factory - * - * @since 4.4.0 - */ - public function __construct(DispatcherInterface $dispatcher, array $config, MetadataManager $metadataManager) - { - parent::__construct($dispatcher, $config); - - $this->metadataManager = $metadataManager; - } - - /** - * 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->getApplication()->getSession()->gc(); - } - } - - if ($this->getApplication()->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) { - $this->metadataManager->deletePriorTo(time() - $this->getApplication()->getSession()->getExpire()); - } - } - } -} diff --git a/plugins/task/sessiongc/forms/sessionGCForm.xml b/plugins/task/sessiongc/forms/sessionGCForm.xml new file mode 100644 index 0000000000000..8e3fe59894a35 --- /dev/null +++ b/plugins/task/sessiongc/forms/sessionGCForm.xml @@ -0,0 +1,56 @@ + +
+ +
+ + + + + + + + + + + + + +
+
+
diff --git a/plugins/system/sessiongc/services/provider.php b/plugins/task/sessiongc/services/provider.php similarity index 86% rename from plugins/system/sessiongc/services/provider.php rename to plugins/task/sessiongc/services/provider.php index ba33eb65a943a..82ccbd8697d43 100644 --- a/plugins/system/sessiongc/services/provider.php +++ b/plugins/task/sessiongc/services/provider.php @@ -2,7 +2,7 @@ /** * @package Joomla.Plugin - * @subpackage System.sessiongc + * @subpackage Task.sessionGC * * @copyright (C) 2023 Open Source Matters, Inc. * @license GNU General Public License version 2 or later; see LICENSE.txt @@ -17,7 +17,7 @@ use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; -use Joomla\Plugin\System\SessionGC\Extension\SessionGC; +use Joomla\Plugin\Task\SessionGC\Extension\SessionGC; return new class () implements ServiceProviderInterface { /** @@ -27,7 +27,7 @@ * * @return void * - * @since 4.4.0 + * @since __DEPLOY_VERSION__ */ public function register(Container $container): void { @@ -36,7 +36,7 @@ public function register(Container $container): void function (Container $container) { $plugin = new SessionGC( $container->get(DispatcherInterface::class), - (array) PluginHelper::getPlugin('system', 'sessiongc'), + (array) PluginHelper::getPlugin('task', 'sessiongc'), $container->get(MetadataManager::class) ); $plugin->setApplication(Factory::getApplication()); diff --git a/plugins/task/sessiongc/sessiongc.xml b/plugins/task/sessiongc/sessiongc.xml new file mode 100644 index 0000000000000..a404465df486a --- /dev/null +++ b/plugins/task/sessiongc/sessiongc.xml @@ -0,0 +1,22 @@ + + + plg_task_sessiongc + Joomla! Project + 2023-08 + (C) 2023 Open Source Matters, Inc. + GNU General Public License version 2 or later; see LICENSE.txt + admin@joomla.org + www.joomla.org + 5.0.0 + PLG_TASK_SESSIONGC_XML_DESCRIPTION + Joomla\Plugin\Task\SessionGC + + services + src + forms + + + language/en-GB/plg_task_sessiongc.ini + language/en-GB/plg_task_sessiongc.sys.ini + + diff --git a/plugins/task/sessiongc/src/Extension/SessionGC.php b/plugins/task/sessiongc/src/Extension/SessionGC.php new file mode 100644 index 0000000000000..328de7c1a3c61 --- /dev/null +++ b/plugins/task/sessiongc/src/Extension/SessionGC.php @@ -0,0 +1,136 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\Plugin\Task\SessionGC\Extension; + +use Joomla\CMS\Factory; +use Joomla\CMS\Plugin\CMSPlugin; +use Joomla\CMS\Session\MetadataManager; +use Joomla\Component\Scheduler\Administrator\Event\ExecuteTaskEvent; +use Joomla\Component\Scheduler\Administrator\Task\Status; +use Joomla\Component\Scheduler\Administrator\Task\Task; +use Joomla\Component\Scheduler\Administrator\Traits\TaskPluginTrait; +use Joomla\Event\DispatcherInterface; +use Joomla\Event\SubscriberInterface; + +// phpcs:disable PSR1.Files.SideEffects +\defined('_JEXEC') or die; +// phpcs:enable PSR1.Files.SideEffects + +/** + * A task plugin. Session data purge task. + * {@see ExecuteTaskEvent}. + * + * @since __DEPLOY_VERSION__ + */ +final class SessionGC extends CMSPlugin implements SubscriberInterface +{ + use TaskPluginTrait; + + /** + * The meta data manager + * + * @var MetadataManager + * + * @since 4.4.0 + */ + private $metadataManager; + + /** + * @var string[] + * @since __DEPLOY_VERSION__ + */ + private const TASKS_MAP = [ + 'session.gc' => [ + 'langConstPrefix' => 'PLG_TASK_SESSIONGC', + 'method' => 'sessionGC', + 'form' => 'sessionGCForm', + ], + ]; + + /** + * @var boolean + * @since __DEPLOY_VERSION__ + */ + protected $autoloadLanguage = true; + + /** + * Constructor. + * + * @param DispatcherInterface $dispatcher The dispatcher + * @param array $config An optional associative array of configuration settings + * @param MetadataManager $metadataManager The user factory + * + * @since 4.4.0 + */ + public function __construct(DispatcherInterface $dispatcher, array $config, MetadataManager $metadataManager) + { + parent::__construct($dispatcher, $config); + + $this->metadataManager = $metadataManager; + } + + /** + * @inheritDoc + * + * @return string[] + * + * @since __DEPLOY_VERSION__ + */ + public static function getSubscribedEvents(): array + { + return [ + 'onTaskOptionsList' => 'advertiseRoutines', + 'onExecuteTask' => 'standardRoutineHandler', + 'onContentPrepareForm' => 'enhanceTaskItemForm', + ]; + } + + /** + * @param ExecuteTaskEvent $event The `onExecuteTask` event. + * + * @return integer The routine exit code. + * + * @since __DEPLOY_VERSION__ + * @throws \Exception + */ + 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(); + } + } + + $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->logTask('SessionGC end'); + + return Status::OK; + } +} ```