JoomlaPolska / jezyk-J4

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

[5] add2scheduler-rotationlog #415

Closed joomlapl-bot closed 5 months ago

joomlapl-bot commented 1 year ago

PR w związku ze zmianą oryginału https://github.com/joomla/joomla-cms/pull/40519 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 fd7b8c35a357a..1eefc688d1621 100644 --- a/administrator/components/com_admin/script.php +++ b/administrator/components/com_admin/script.php @@ -235,6 +235,7 @@ protected function uninstallExtensions() */ ['type' => 'plugin', 'element' => 'demotasks', 'folder' => 'task', 'client_id' => 0, 'pre_function' => null], ['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' => 'updatenotification', 'folder' => 'system', 'client_id' => 0, 'pre_function' => 'migrateUpdatenotificationPlugin'], ]; @@ -316,6 +317,49 @@ private function migrateCompatPlugin($rowOld) )->execute(); } + /** + * This method is for migration for old logrotation 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 migrateLogRotationPlugin($data) + { + if (!$data->enabled) { + return; + } + + /** @var SchedulerComponent $component */ + $component = Factory::getApplication()->bootComponent('com_scheduler'); + + /** @var TaskModel $model */ + $model = $component->getMVCFactory()->createModel('Task', 'Administrator', ['ignore_request' => true]); + + // Get the timeout, as configured in plg_system_logrotation + $params = new Registry($data->params); + $cachetimeout = (int) $params->get('cachetimeout', 30); + $lastrun = (int) $params->get('lastrun', time()); + + $task = [ + 'title' => 'RotateLogs', + 'type' => 'rotation.logs', + 'execution_rules' => [ + 'rule-type' => 'interval-days', + 'interval-days' => $cachetimeout, + 'exec-time' => gmdate('H:i', $lastrun), + 'exec-day' => gmdate('d'), + ], + 'state' => 1, + 'params' => [ + 'logstokeep' => $params->get('logstokeep', 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 fedce0a7dfaf3..5552693d22c2e 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 @@ -1,6 +1,9 @@ INSERT INTO `#__extensions` (`name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `custom_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES +('plg_task_rotatelogs', 'plugin', 'rotatelogs', '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 ('plg_task_updatenotification.mail', 'plg_task_updatenotification', '', 'PLG_TASK_UPDATENOTIFICATION_EMAIL_SUBJECT', 'PLG_TASK_UPDATENOTIFICATION_EMAIL_BODY', '', '', '{"tags":["newversion","curversion","sitename","url","link","releasenews"]}'); + DELETE FROM `#__mail_templates` WHERE `template_id` = 'plg_system_updatenotification.mail'; DELETE FROM `#__postinstall_messages` WHERE `condition_file` = 'site://plugins/system/updatenotification/postinstall/updatecachetime.php'; 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 276d7d87668d6..fc99290a3d629 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 @@ -1,6 +1,9 @@ INSERT INTO "#__extensions" ("name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "custom_data", "checked_out", "checked_out_time", "ordering", "state") VALUES +('plg_task_rotatelogs', 'plugin', 'rotatelogs', '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 ('plg_task_updatenotification.mail', 'plg_task_updatenotification', '', 'PLG_TASK_UPDATENOTIFICATION_EMAIL_SUBJECT', 'PLG_TASK_UPDATENOTIFICATION_EMAIL_BODY', '', '', '{"tags":["newversion","curversion","sitename","url","link","releasenews"]}'); + DELETE FROM "#__mail_templates" WHERE "template_id" = 'plg_system_updatenotification.mail'; DELETE FROM "#__postinstall_messages" WHERE "condition_file" = 'site://plugins/system/updatenotification/postinstall/updatecachetime.php'; diff --git a/administrator/language/en-GB/plg_system_logrotation.ini b/administrator/language/en-GB/plg_system_logrotation.ini deleted file mode 100644 index c55fc9fa19758..0000000000000 --- a/administrator/language/en-GB/plg_system_logrotation.ini +++ /dev/null @@ -1,9 +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_LOGROTATION="System - Log Rotation" -PLG_SYSTEM_LOGROTATION_CACHETIMEOUT_LABEL="Log Rotation (in days)" -PLG_SYSTEM_LOGROTATION_LOGSTOKEEP_LABEL="Maximum Logs" -PLG_SYSTEM_LOGROTATION_XML_DESCRIPTION="This plugin periodically rotates system log files." diff --git a/administrator/language/en-GB/plg_system_logrotation.sys.ini b/administrator/language/en-GB/plg_system_logrotation.sys.ini deleted file mode 100644 index 131c5d8174c80..0000000000000 --- a/administrator/language/en-GB/plg_system_logrotation.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_LOGROTATION="System - Log Rotation" -PLG_SYSTEM_LOGROTATION_XML_DESCRIPTION="This plugin periodically rotates system log files." diff --git a/administrator/language/en-GB/plg_task_rotatelogs.ini b/administrator/language/en-GB/plg_task_rotatelogs.ini new file mode 100644 index 0000000000000..c533473a0c0dd --- /dev/null +++ b/administrator/language/en-GB/plg_task_rotatelogs.ini @@ -0,0 +1,10 @@ +; 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_ROTATELOGS="Task - Rotate Logs" +PLG_TASK_ROTATELOGS_LOGSTOKEEP_LABEL="Maximum Logs" +PLG_TASK_ROTATELOGS_ROTATION_DESC="Periodically rotates log files." +PLG_TASK_ROTATELOGS_ROTATION_TITLE="Rotate Logs" +PLG_TASK_ROTATELOGS_XML_DESCRIPTION="Task routines to schedule Log Rotation." diff --git a/administrator/language/en-GB/plg_task_rotatelogs.sys.ini b/administrator/language/en-GB/plg_task_rotatelogs.sys.ini new file mode 100644 index 0000000000000..c08a06a9e3226 --- /dev/null +++ b/administrator/language/en-GB/plg_task_rotatelogs.sys.ini @@ -0,0 +1,7 @@ +; 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_ROTATELOGS="Task - Rotate Logs" +PLG_TASK_ROTATELOGS_XML_DESCRIPTION="Task routines to schedule Log Rotation." diff --git a/installation/sql/mysql/base.sql b/installation/sql/mysql/base.sql index 4fe6d63f26514..d5ed86c6dd526 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, 179, 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, 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}}'), (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}}'), @@ -114,7 +114,8 @@ INSERT INTO `#__assets` (`id`, `parent_id`, `lft`, `rgt`, `level`, `name`, `titl (94, 1, 173, 174, 1, 'com_workflow', 'com_workflow', '{}'), (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', '{}'); +(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', '{}'); -- -------------------------------------------------------- @@ -350,7 +351,6 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, (0, 'plg_system_languagefilter', 'plugin', 'languagefilter', 'system', 0, 0, 1, 0, 1, '', '', '', 10, 0), (0, 'plg_system_log', 'plugin', 'log', 'system', 0, 1, 1, 0, 1, '', '', '', 11, 0), (0, 'plg_system_logout', 'plugin', 'logout', 'system', 0, 1, 1, 0, 1, '', '', '', 12, 0), -(0, 'plg_system_logrotation', 'plugin', 'logrotation', 'system', 0, 1, 1, 0, 1, '', '{}', '', 13, 0), (0, 'plg_system_privacyconsent', 'plugin', 'privacyconsent', 'system', 0, 0, 1, 0, 1, '', '{}', '', 14, 0), (0, 'plg_system_redirect', 'plugin', 'redirect', 'system', 0, 0, 1, 0, 1, '', '', '', 15, 0), (0, 'plg_system_remember', 'plugin', 'remember', 'system', 0, 1, 1, 0, 1, '', '', '', 16, 0), @@ -366,8 +366,9 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, (0, 'plg_task_checkfiles', 'plugin', 'checkfiles', 'task', 0, 1, 1, 0, 1, '', '{}', '', 1, 0), (0, 'plg_task_globalcheckin', 'plugin', 'globalcheckin', 'task', 0, 1, 1, 0, 0, '', '{}', '', 2, 0), (0, 'plg_task_requests', 'plugin', 'requests', 'task', 0, 1, 1, 0, 1, '', '{}', '', 3, 0), -(0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 1, '', '{}', '', 4, 0), -(0, 'plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', 5, 0), +(0, 'plg_task_rotatelogs', 'plugin', 'rotatelogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', 4, 0), +(0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 1, '', '{}', '', 5, 0), +(0, 'plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', 6, 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 187b1cddebf3d..6e7d4734cdfe2 100644 --- a/installation/sql/mysql/extensions.sql +++ b/installation/sql/mysql/extensions.sql @@ -925,8 +925,9 @@ CREATE TABLE IF NOT EXISTS `#__scheduler_tasks` ( KEY `idx_checked_out` (`checked_out`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 DEFAULT COLLATE = utf8mb4_unicode_ci; -INSERT INTO `#__scheduler_tasks` (`id`, `asset_id`, `title`, `type`, `execution_rules`, `cron_rules`, `state`, `last_execution`, `next_execution`, `locked`, `params`, `created`) -VALUES (1, 97, '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()); +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()); -- -------------------------------------------------------- diff --git a/installation/sql/postgresql/base.sql b/installation/sql/postgresql/base.sql index 9ce505797c40f..58314488cbdeb 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, 179, 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, 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}}'), (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}}'), @@ -120,9 +120,10 @@ INSERT INTO "#__assets" ("id", "parent_id", "lft", "rgt", "level", "name", "titl (94, 1, 173, 174, 1, 'com_workflow', 'com_workflow', '{}'), (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', '{}'); +(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', '{}'); -SELECT setval('#__assets_id_seq', 98, false); +SELECT setval('#__assets_id_seq', 99, false); -- -- Table structure for table `#__extensions` @@ -356,7 +357,6 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", (0, 'plg_system_languagefilter', 'plugin', 'languagefilter', 'system', 0, 0, 1, 0, 1, '', '', '', 10, 0), (0, 'plg_system_log', 'plugin', 'log', 'system', 0, 1, 1, 0, 1, '', '', '', 11, 0), (0, 'plg_system_logout', 'plugin', 'logout', 'system', 0, 1, 1, 0, 1, '', '', '', 12, 0), -(0, 'plg_system_logrotation', 'plugin', 'logrotation', 'system', 0, 1, 1, 0, 1, '', '{}', '', 13, 0), (0, 'plg_system_privacyconsent', 'plugin', 'privacyconsent', 'system', 0, 0, 1, 0, 1, '', '{}', '', 14, 0), (0, 'plg_system_redirect', 'plugin', 'redirect', 'system', 0, 0, 1, 0, 1, '', '', '', 15, 0), (0, 'plg_system_remember', 'plugin', 'remember', 'system', 0, 1, 1, 0, 1, '', '', '', 16, 0), @@ -372,8 +372,9 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", (0, 'plg_task_checkfiles', 'plugin', 'checkfiles', 'task', 0, 1, 1, 0, 1, '', '{}', '', 1, 0), (0, 'plg_task_globalcheckin', 'plugin', 'globalcheckin', 'task', 0, 1, 1, 0, 0, '', '{}', '', 2, 0), (0, 'plg_task_requests', 'plugin', 'requests', 'task', 0, 1, 1, 0, 1, '', '{}', '', 3, 0), -(0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 1, '', '{}', '', 4, 0), -(0, 'plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', 5, 0), +(0, 'plg_task_rotatelogs', 'plugin', 'rotatelogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', 4, 0), +(0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 1, '', '{}', '', 5, 0), +(0, 'plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', 6, 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 9b6fb607ded30..abd3cfa743d1c 100644 --- a/installation/sql/postgresql/extensions.sql +++ b/installation/sql/postgresql/extensions.sql @@ -889,10 +889,11 @@ CREATE INDEX "#__scheduler_tasks_idx_priority" ON "#__scheduler_tasks" ("priorit CREATE INDEX "#__scheduler_tasks_idx_cli_exclusive" ON "#__scheduler_tasks" ("cli_exclusive"); CREATE INDEX "#__scheduler_tasks_idx_checked_out" ON "#__scheduler_tasks" ("checked_out"); -INSERT INTO "#__scheduler_tasks" ("id", "asset_id", "title", "type", "execution_rules", "cron_rules", "state", "last_execution", "next_execution", "locked", "params", "created") -VALUES (1, 97, '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'); +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'); -SELECT setval('#__scheduler_tasks_id_seq', 2, false); +SELECT setval('#__scheduler_tasks_id_seq', 3, false); -- -------------------------------------------------------- diff --git a/libraries/src/Extension/ExtensionHelper.php b/libraries/src/Extension/ExtensionHelper.php index 5a316e1aac37d..e52390c4cb9a4 100644 --- a/libraries/src/Extension/ExtensionHelper.php +++ b/libraries/src/Extension/ExtensionHelper.php @@ -303,7 +303,6 @@ class ExtensionHelper ['plugin', 'languagefilter', 'system', 0], ['plugin', 'log', 'system', 0], ['plugin', 'logout', 'system', 0], - ['plugin', 'logrotation', 'system', 0], ['plugin', 'privacyconsent', 'system', 0], ['plugin', 'redirect', 'system', 0], ['plugin', 'remember', 'system', 0], @@ -321,6 +320,7 @@ class ExtensionHelper ['plugin', 'checkfiles', 'task', 0], ['plugin', 'globalcheckin', 'task', 0], ['plugin', 'requests', 'task', 0], + ['plugin', 'rotatelogs', 'task', 0], ['plugin', 'sitestatus', 'task', 0], ['plugin', 'updatenotification', 'task', 0], diff --git a/plugins/system/logrotation/logrotation.xml b/plugins/system/logrotation/logrotation.xml deleted file mode 100644 index 191c73ca67c14..0000000000000 --- a/plugins/system/logrotation/logrotation.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - plg_system_logrotation - Joomla! Project - 2018-05 - (C) 2018 Open Source Matters, Inc. - GNU General Public License version 2 or later; see LICENSE.txt - admin@joomla.org - www.joomla.org - 3.9.0 - PLG_SYSTEM_LOGROTATION_XML_DESCRIPTION - Joomla\Plugin\System\LogRotation - - services - src - - - language/en-GB/plg_system_logrotation.ini - language/en-GB/plg_system_logrotation.sys.ini - - - -
- - - - - -
-
-
-
diff --git a/plugins/system/logrotation/src/Extension/LogRotation.php b/plugins/system/logrotation/src/Extension/LogRotation.php deleted file mode 100644 index a078523075aaa..0000000000000 --- a/plugins/system/logrotation/src/Extension/LogRotation.php +++ /dev/null @@ -1,238 +0,0 @@ - - * @license GNU General Public License version 2 or later; see LICENSE.txt - */ - -namespace Joomla\Plugin\System\LogRotation\Extension; - -use Joomla\CMS\Cache\Cache; -use Joomla\CMS\Filesystem\Folder; -use Joomla\CMS\Plugin\CMSPlugin; -use Joomla\Database\DatabaseAwareTrait; -use Joomla\Filesystem\File; -use Joomla\Filesystem\Path; - -// phpcs:disable PSR1.Files.SideEffects -\defined('_JEXEC') or die; -// phpcs:enable PSR1.Files.SideEffects - -/** - * Joomla! Log Rotation plugin - * - * Rotate the log files created by Joomla core - * - * @since 3.9.0 - */ -final class LogRotation extends CMSPlugin -{ - use DatabaseAwareTrait; - - /** - * Load the language file on instantiation. - * - * @var boolean - * - * @since 3.9.0 - */ - protected $autoloadLanguage = true; - - /** - * The log check and rotation code is triggered after the page has fully rendered. - * - * @return void - * - * @since 3.9.0 - */ - public function onAfterRender() - { - // Get the timeout as configured in plugin parameters - - /** @var \Joomla\Registry\Registry $params */ - $cache_timeout = (int) $this->params->get('cachetimeout', 30); - $cache_timeout = 24 * 3600 * $cache_timeout; - $logsToKeep = (int) $this->params->get('logstokeep', 1); - - // Do we need to run? Compare the last run timestamp stored in the plugin's options with the current - // timestamp. If the difference is greater than the cache timeout we shall not execute again. - $now = time(); - $last = (int) $this->params->get('lastrun', 0); - - if ((abs($now - $last) < $cache_timeout)) { - return; - } - - // Update last run status - $this->params->set('lastrun', $now); - - $paramsJson = $this->params->toString('JSON'); - $db = $this->getDatabase(); - $query = $db->getQuery(true) - ->update($db->quoteName('#__extensions')) - ->set($db->quoteName('params') . ' = :params') - ->where($db->quoteName('type') . ' = ' . $db->quote('plugin')) - ->where($db->quoteName('folder') . ' = ' . $db->quote('system')) - ->where($db->quoteName('element') . ' = ' . $db->quote('logrotation')) - ->bind(':params', $paramsJson); - - try { - // Lock the tables to prevent multiple plugin executions causing a race condition - $db->lockTable('#__extensions'); - } catch (\Exception $e) { - // If we can't lock the tables it's too risky to continue execution - return; - } - - try { - // Update the plugin parameters - $result = $db->setQuery($query)->execute(); - - $this->clearCacheGroups(['com_plugins'], [0, 1]); - } catch (\Exception $exc) { - // If we failed to execute - $db->unlockTables(); - $result = false; - } - - try { - // Unlock the tables after writing - $db->unlockTables(); - } catch (\Exception $e) { - // If we can't lock the tables assume we have somehow failed - $result = false; - } - - // Stop on failure - if (!$result) { - return; - } - - // Get the log path - $logPath = Path::clean($this->getApplication()->get('log_path')); - - // Invalid path, stop processing further - if (!is_dir($logPath)) { - return; - } - - $logFiles = $this->getLogFiles($logPath); - - // Sort log files by version number in reserve order - krsort($logFiles, SORT_NUMERIC); - - foreach ($logFiles as $version => $files) { - if ($version >= $logsToKeep) { - // Delete files which has version greater than or equals $logsToKeep - foreach ($files as $file) { - File::delete($logPath . '/' . $file); - } - } else { - // For files which has version smaller than $logsToKeep, rotate (increase version number) - foreach ($files as $file) { - $this->rotate($logPath, $file, $version); - } - } - } - } - - /** - * Get log files from log folder - * - * @param string $path The folder to get log files - * - * @return array The log files in the given path grouped by version number (not rotated files has number 0) - * - * @since 3.9.0 - */ - private function getLogFiles($path) - { - $logFiles = []; - $files = Folder::files($path, '\.php$'); - - foreach ($files as $file) { - $parts = explode('.', $file); - - /* - * Rotated log file has this filename format [VERSION].[FILENAME].php. So if $parts has at least 3 elements - * and the first element is a number, we know that it's a rotated file and can get it's current version - */ - if (count($parts) >= 3 && is_numeric($parts[0])) { - $version = (int) $parts[0]; - } else { - $version = 0; - } - - if (!isset($logFiles[$version])) { - $logFiles[$version] = []; - } - - $logFiles[$version][] = $file; - } - - return $logFiles; - } - - /** - * Method to rotate (increase version) of a log file - * - * @param string $path Path to file to rotate - * @param string $filename Name of file to rotate - * @param int $currentVersion The current version number - * - * @return void - * - * @since 3.9.0 - */ - private function rotate($path, $filename, $currentVersion) - { - if ($currentVersion === 0) { - $rotatedFile = $path . '/1.' . $filename; - } else { - /* - * Rotated log file has this filename format [VERSION].[FILENAME].php. To rotate it, we just need to explode - * the filename into an array, increase value of first element (keep version) and implode it back to get the - * rotated file name - */ - $parts = explode('.', $filename); - $parts[0] = $currentVersion + 1; - - $rotatedFile = $path . '/' . implode('.', $parts); - } - - File::move($path . '/' . $filename, $rotatedFile); - } - - /** - * Clears cache groups. We use it to clear the plugins cache after we update the last run timestamp. - * - * @param array $clearGroups The cache groups to clean - * @param array $cacheClients The cache clients (site, admin) to clean - * - * @return void - * - * @since 3.9.0 - */ - private function clearCacheGroups(array $clearGroups, array $cacheClients = [0, 1]) - { - foreach ($clearGroups as $group) { - foreach ($cacheClients as $client_id) { - try { - $options = [ - 'defaultgroup' => $group, - 'cachebase' => $client_id ? JPATH_ADMINISTRATOR . '/cache' : - $this->getApplication()->get('cache_path', JPATH_SITE . '/cache'), - ]; - - $cache = Cache::getInstance('callback', $options); - $cache->clean(); - } catch (\Exception $e) { - // Ignore it - } - } - } - } -} diff --git a/plugins/task/rotatelogs/forms/rotateForm.xml b/plugins/task/rotatelogs/forms/rotateForm.xml new file mode 100644 index 0000000000000..80b95abbe9460 --- /dev/null +++ b/plugins/task/rotatelogs/forms/rotateForm.xml @@ -0,0 +1,18 @@ + +
+ +
+ +
+
+
diff --git a/plugins/task/rotatelogs/rotatelogs.xml b/plugins/task/rotatelogs/rotatelogs.xml new file mode 100644 index 0000000000000..45311f120f583 --- /dev/null +++ b/plugins/task/rotatelogs/rotatelogs.xml @@ -0,0 +1,22 @@ + + + plg_task_rotatelogs + Joomla! Project + 2023-07 + (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_ROTATELOGS_XML_DESCRIPTION + Joomla\Plugin\Task\RotateLogs + + forms + services + src + + + language/en-GB/plg_task_rotatelogs.ini + language/en-GB/plg_task_rotatelogs.sys.ini + + diff --git a/plugins/system/logrotation/services/provider.php b/plugins/task/rotatelogs/services/provider.php similarity index 78% rename from plugins/system/logrotation/services/provider.php rename to plugins/task/rotatelogs/services/provider.php index 30a9dbaf39c72..b2f8c50576064 100644 --- a/plugins/system/logrotation/services/provider.php +++ b/plugins/task/rotatelogs/services/provider.php @@ -2,7 +2,7 @@ /** * @package Joomla.Plugin - * @subpackage System.logrotation + * @subpackage Task.rotatelogs * * @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\LogRotation\Extension\LogRotation; +use Joomla\Plugin\Task\RotateLogs\Extension\RotateLogs; return new class () implements ServiceProviderInterface { /** @@ -27,16 +27,16 @@ * * @return void * - * @since 4.4.0 + * @since __DEPLOY_VERSION__ */ - public function register(Container $container): void + public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { - $plugin = new LogRotation( + $plugin = new RotateLogs( $container->get(DispatcherInterface::class), - (array) PluginHelper::getPlugin('system', 'logrotation') + (array) PluginHelper::getPlugin('task', 'rotatelogs') ); $plugin->setApplication(Factory::getApplication()); $plugin->setDatabase($container->get(DatabaseInterface::class)); diff --git a/plugins/task/rotatelogs/src/Extension/RotateLogs.php b/plugins/task/rotatelogs/src/Extension/RotateLogs.php new file mode 100644 index 0000000000000..930b5b4bc933d --- /dev/null +++ b/plugins/task/rotatelogs/src/Extension/RotateLogs.php @@ -0,0 +1,183 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\Plugin\Task\RotateLogs\Extension; + +use Joomla\CMS\Filesystem\File; +use Joomla\CMS\Filesystem\Folder; +use Joomla\CMS\Plugin\CMSPlugin; +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\Database\DatabaseAwareTrait; +use Joomla\Event\SubscriberInterface; +use Joomla\Filesystem\Path; + +// phpcs:disable PSR1.Files.SideEffects +\defined('_JEXEC') or die; +// phpcs:enable PSR1.Files.SideEffects + +/** + * A task plugin. Offers 1 task routines Rotate Logs + * {@see ExecuteTaskEvent}. + * + * @since __DEPLOY_VERSION__ + */ +final class RotateLogs extends CMSPlugin implements SubscriberInterface +{ + use DatabaseAwareTrait; + use TaskPluginTrait; + + /** + * @var string[] + * @since __DEPLOY_VERSION__ + */ + private const TASKS_MAP = [ + 'rotation.logs' => [ + 'langConstPrefix' => 'PLG_TASK_ROTATELOGS_ROTATION', + 'method' => 'rotateLogs', + 'form' => 'rotateForm', + ], + ]; + + /** + * @var boolean + * @since __DEPLOY_VERSION__ + */ + protected $autoloadLanguage = true; + + /** + * @inheritDoc + * + * @return string[] + * + * @since __DEPLOY_VERSION__ + */ + public static function getSubscribedEvents(): array + { + return [ + 'onTaskOptionsList' => 'advertiseRoutines', + 'onExecuteTask' => 'standardRoutineHandler', + 'onContentPrepareForm' => 'enhanceTaskItemForm', + ]; + } + + /** + * Method for the logs rotation task. + * + * @param ExecuteTaskEvent $event The `onExecuteTask` event. + * + * @return integer The routine exit code. + * + * @since __DEPLOY_VERSION__ + * @throws \Exception + */ + private function rotateLogs(ExecuteTaskEvent $event): int + { + $logsToKeep = (int) $event->getArgument('params')->logstokeep ?? 1; + + // Get the log path + $logPath = Path::clean($this->getApplication()->get('log_path')); + + // Invalid path, stop processing further + if (!is_dir($logPath)) { + return Status::KNOCKOUT; + } + + $logFiles = $this->getLogFiles($logPath); + + // Sort log files by version number in reverse order + krsort($logFiles, SORT_NUMERIC); + + foreach ($logFiles as $version => $files) { + if ($version >= $logsToKeep) { + // Delete files which have version greater than or equals $logsToKeep + foreach ($files as $file) { + File::delete($logPath . '/' . $file); + } + } else { + // For files which have version smaller than $logsToKeep, rotate (increase version number) + foreach ($files as $file) { + $this->rotate($logPath, $file, $version); + } + } + } + + return Status::OK; + } + + /** + * Method to rotate (increase version) of a log file + * + * @param string $path Path to file to rotate + * @param string $filename Name of file to rotate + * @param int $currentVersion The current version number + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + private function rotate($path, $filename, $currentVersion) + { + if ($currentVersion === 0) { + $rotatedFile = $path . '/1.' . $filename; + } else { + /* + * Rotated log file has this filename format [VERSION].[FILENAME].php. To rotate it, we just need to explode + * the filename into an array, increase value of first element (keep version) and implode it back to get the + * rotated file name + */ + $parts = explode('.', $filename); + $parts[0] = $currentVersion + 1; + + $rotatedFile = $path . '/' . implode('.', $parts); + } + + File::move($path . '/' . $filename, $rotatedFile); + } + + /** + * Get log files from log folder + * + * @param string $path The folder to get log files + * + * @return array The log files in the given path grouped by version number (not rotated files have number 0) + * + * @since __DEPLOY_VERSION__ + */ + private function getLogFiles($path) + { + $logFiles = []; + $files = Folder::files($path, '\.php$'); + + foreach ($files as $file) { + $parts = explode('.', $file); + + /* + * Rotated log file has this filename format [VERSION].[FILENAME].php. So if $parts has at least 3 elements + * and the first element is a number, we know that it's a rotated file and can get it's current version + */ + if (count($parts) >= 3 && is_numeric($parts[0])) { + $version = (int) $parts[0]; + } else { + $version = 0; + } + + if (!isset($logFiles[$version])) { + $logFiles[$version] = []; + } + + $logFiles[$version][] = $file; + } + + return $logFiles; + } +} ```