Skip to content

Commit 9ea35c7

Browse files
alikonrichard67heelc29
authored
[5] add2scheduler-deleteactionlogs (#41064)
* add2schedulerdeleteactionlogs * cs * Rename 5.0.0-2023-06-27.sql to 5.0.0-2023-08-05.sql shift * Rename 5.0.0-2023-06-27.sql to 5.0.0-2023-08-05.sql shift * Rename 5.0.0-2023-08-05.sql to 5.0.0-2023-08-25.sql * Rename 5.0.0-2023-08-05.sql to 5.0.0-2023-08-25.sql * Update plugins/task/deleteactionlogs/src/Extension/DeleteActionLogs.php Co-authored-by: heelc29 <[email protected]> * blank-line * blank-line * blank-line * remove config node * Rename 5.0.0-2023-08-25.sql to 5.0.0-2023-08-30.sql * Rename 5.0.0-2023-08-25.sql to 5.0.0-2023-08-30.sql * Deprecate language strings * Single quotes * Remove extra reference assignment for dispatcher argument * Do it in the same way as in PR #40553 * Rename 5.0.0-2023-08-30.sql to 5.0.0-2023-09-02.sql * Rename 5.0.0-2023-08-30.sql to 5.0.0-2023-09-02.sql * Fix lastrun default on update * CS * deploy version * Do nothing if params is an empty JSON * Fix migration methods and comment typos * Use the right task type * Fix undefined array element "exec-day" --------- Co-authored-by: Richard Fath <[email protected]> Co-authored-by: heelc29 <[email protected]> Co-authored-by: Richard Fath <[email protected]>
1 parent 7d5237c commit 9ea35c7

File tree

15 files changed

+308
-164
lines changed

15 files changed

+308
-164
lines changed

administrator/components/com_admin/script.php

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,6 +2346,10 @@ public function postflight($action, $installer)
23462346
return false;
23472347
}
23482348

2349+
if (!$this->migrateDeleteActionlogsConfiguration()) {
2350+
return false;
2351+
}
2352+
23492353
if (!$this->migratePrivacyconsentConfiguration()) {
23502354
return false;
23512355
}
@@ -2355,6 +2359,75 @@ public function postflight($action, $installer)
23552359
return true;
23562360
}
23572361

2362+
/**
2363+
* Migrate Deleteactionlogs plugin configuration
2364+
*
2365+
* @return boolean True on success
2366+
*
2367+
* @since __DEPLOY_VERSION__
2368+
*/
2369+
private function migrateDeleteActionlogsConfiguration(): bool
2370+
{
2371+
$db = Factory::getDbo();
2372+
2373+
try {
2374+
// Get the ActionLogs system plugin's parameters
2375+
$row = $db->setQuery(
2376+
$db->getQuery(true)
2377+
->select([$db->quotename('enabled'), $db->quoteName('params')])
2378+
->from($db->quoteName('#__extensions'))
2379+
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
2380+
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
2381+
->where($db->quoteName('element') . ' = ' . $db->quote('actionlogs'))
2382+
)->loadObject();
2383+
} catch (Exception $e) {
2384+
echo Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br>';
2385+
2386+
return false;
2387+
}
2388+
2389+
// If not existing or disabled there is nothing to migrate
2390+
if (!$row || !$row->enabled) {
2391+
return true;
2392+
}
2393+
2394+
$params = new Registry($row->params);
2395+
2396+
// If deletion of outdated logs was disabled there is nothing to migrate
2397+
if (!$params->get('logDeletePeriod', 0)) {
2398+
return true;
2399+
}
2400+
2401+
/** @var SchedulerComponent $component */
2402+
$component = Factory::getApplication()->bootComponent('com_scheduler');
2403+
2404+
/** @var TaskModel $model */
2405+
$model = $component->getMVCFactory()->createModel('Task', 'Administrator', ['ignore_request' => true]);
2406+
$task = [
2407+
'title' => 'DeleteActionLogs',
2408+
'type' => 'delete.actionlogs',
2409+
'execution_rules' => [
2410+
'rule-type' => 'interval-hours',
2411+
'interval-hours' => 24,
2412+
'exec-time' => gmdate('H:i', $params->get('lastrun', time())),
2413+
'exec-day' => gmdate('d'),
2414+
],
2415+
'state' => 1,
2416+
'params' => [
2417+
'logDeletePeriod' => $params->get('logDeletePeriod', 0),
2418+
],
2419+
];
2420+
2421+
try {
2422+
$model->save($task);
2423+
} catch (Exception $e) {
2424+
echo Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br>';
2425+
2426+
return false;
2427+
}
2428+
2429+
return true;
2430+
}
23582431
/**
23592432
* Migrate privacyconsents system plugin configuration
23602433
*
@@ -2370,7 +2443,7 @@ private function migratePrivacyconsentConfiguration(): bool
23702443
// Get the PrivacyConsent system plugin's parameters
23712444
$row = $db->setQuery(
23722445
$db->getQuery(true)
2373-
->select($db->quotename('enabled'), $db->quoteName('params'))
2446+
->select([$db->quotename('enabled'), $db->quoteName('params')])
23742447
->from($db->quoteName('#__extensions'))
23752448
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
23762449
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
@@ -2382,14 +2455,14 @@ private function migratePrivacyconsentConfiguration(): bool
23822455
return false;
23832456
}
23842457

2385-
// If not existing or disbled there is nothing to migrate
2458+
// If not existing or disabled there is nothing to migrate
23862459
if (!$row || !$row->enabled) {
23872460
return true;
23882461
}
23892462

23902463
$params = new Registry($row->params);
23912464

2392-
// If consent expiration was disbled there is nothing to migrate
2465+
// If consent expiration was disabled there is nothing to migrate
23932466
if (!$params->get('enabled', 0)) {
23942467
return true;
23952468
}

administrator/components/com_admin/sql/updates/mysql/5.0.0-2023-09-02.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
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
2+
('plg_task_deleteactionlogs', 'plugin', 'deleteactionlogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0),
23
('plg_task_privacyconsent', 'plugin', 'privacyconsent', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0),
34
('plg_task_rotatelogs', 'plugin', 'rotatelogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0),
45
('plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0);

administrator/components/com_admin/sql/updates/postgresql/5.0.0-2023-09-02.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
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
2+
('plg_task_deleteactionlogs', 'plugin', 'deleteactionlogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0),
23
('plg_task_privacyconsent', 'plugin', 'privacyconsent', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0),
34
('plg_task_rotatelogs', 'plugin', 'rotatelogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0),
45
('plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', NULL, NULL, 0, 0);

administrator/language/en-GB/plg_system_actionlogs.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ PLG_SYSTEM_ACTIONLOGS_INFO_DESC="The Action Log - Joomla plugin is disabled"
99
PLG_SYSTEM_ACTIONLOGS_INFO_LABEL="Information"
1010
PLG_SYSTEM_ACTIONLOGS_JOOMLA_ACTIONLOG_DISABLED="Action Log - Joomla"
1111
PLG_SYSTEM_ACTIONLOGS_JOOMLA_ACTIONLOG_DISABLED_REDIRECT="The %s plugin is disabled."
12-
PLG_SYSTEM_ACTIONLOGS_LOG_DELETE_PERIOD="Days to delete logs after"
13-
PLG_SYSTEM_ACTIONLOGS_LOG_DELETE_PERIOD_DESC="Enter 0 if you don't want to delete the logs."
1412
PLG_SYSTEM_ACTIONLOGS_NOTIFICATIONS="Email Notifications"
1513
PLG_SYSTEM_ACTIONLOGS_OPTIONS="User Actions Log Options"
1614
PLG_SYSTEM_ACTIONLOGS_XML_DESCRIPTION="Records the actions of users on the site so they can be reviewed if required."
@@ -22,3 +20,7 @@ PLG_SYSTEM_ACTIONLOGS_CONTENT_PUBLISHED="User <a href=\"{accountlink}\">{usernam
2220
PLG_SYSTEM_ACTIONLOGS_CONTENT_TRASHED="User <a href=\"{accountlink}\">{username}</a> trashed the {type} <a href=\"{itemlink}\">{title}</a>"
2321
PLG_SYSTEM_ACTIONLOGS_CONTENT_UNPUBLISHED="User <a href=\"{accountlink}\">{username}</a> unpublished the {type} <a href=\"{itemlink}\">{title}</a>"
2422
PLG_SYSTEM_ACTIONLOGS_CONTENT_UPDATED="User <a href=\"{accountlink}\">{username}</a> updated the {type} <a href=\"{itemlink}\">{title}</a>"
23+
24+
; All the following strings are deprecated and will be removed with 6.0
25+
PLG_SYSTEM_ACTIONLOGS_LOG_DELETE_PERIOD="Days to delete logs after"
26+
PLG_SYSTEM_ACTIONLOGS_LOG_DELETE_PERIOD_DESC="Enter 0 if you don't want to delete the logs."
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; Joomla! Project
2+
; (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
3+
; License GNU General Public License version 2 or later; see LICENSE.txt
4+
; Note : All ini files need to be saved as UTF-8
5+
6+
PLG_TASK_DELETEACTIONLOGS="Task - Delete Action Logs"
7+
PLG_TASK_DELETEACTIONLOGS_DELETE_DESC="Delete Action logs after days"
8+
PLG_TASK_DELETEACTIONLOGS_DELETE_TITLE="Delete ActionLogs - Task"
9+
PLG_TASK_DELETEACTIONLOGS_LOG_DELETE_PERIOD="Days to delete action logs after"
10+
PLG_TASK_DELETEACTIONLOGS_XML_DESCRIPTION="This plugin for schedule Action Logs delete Tasks."
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
; Joomla! Project
2+
; (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
3+
; License GNU General Public License version 2 or later; see LICENSE.txt
4+
; Note : All ini files need to be saved as UTF-8
5+
6+
PLG_TASK_DELETEACTIONLOGS="Task - Delete Action Logs"
7+
PLG_TASK_DELETEACTIONLOGS_XML_DESCRIPTION="This plugin for schedule Action Logs delete Tasks."

installation/sql/mysql/base.sql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,13 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
364364
(0, 'plg_system_tasknotification', 'plugin', 'tasknotification', 'system', 0, 1, 1, 0, 1, '', '', '', 24, 0),
365365
(0, 'plg_system_webauthn', 'plugin', 'webauthn', 'system', 0, 1, 1, 0, 1, '', '{}', '', 26, 0),
366366
(0, 'plg_task_checkfiles', 'plugin', 'checkfiles', 'task', 0, 1, 1, 0, 1, '', '{}', '', 1, 0),
367-
(0, 'plg_task_globalcheckin', 'plugin', 'globalcheckin', 'task', 0, 1, 1, 0, 0, '', '{}', '', 2, 0),
368-
(0, 'plg_task_requests', 'plugin', 'requests', 'task', 0, 1, 1, 0, 1, '', '{}', '', 3, 0),
369-
(0, 'plg_task_privacyconsent', 'plugin', 'privacyconsent', 'task', 0, 1, 1, 0, 1, '', '{}', '', 4, 0),
370-
(0, 'plg_task_rotatelogs', 'plugin', 'rotatelogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', 5, 0),
371-
(0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 1, '', '{}', '', 6, 0),
372-
(0, 'plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', 7, 0),
367+
(0, 'plg_task_deleteactionlogs', 'plugin', 'deleteactionlogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', 2, 0),
368+
(0, 'plg_task_globalcheckin', 'plugin', 'globalcheckin', 'task', 0, 1, 1, 0, 0, '', '{}', '', 3, 0),
369+
(0, 'plg_task_requests', 'plugin', 'requests', 'task', 0, 1, 1, 0, 1, '', '{}', '', 4, 0),
370+
(0, 'plg_task_privacyconsent', 'plugin', 'privacyconsent', 'task', 0, 1, 1, 0, 1, '', '{}', '', 5, 0),
371+
(0, 'plg_task_rotatelogs', 'plugin', 'rotatelogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', 6, 0),
372+
(0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 1, '', '{}', '', 7, 0),
373+
(0, 'plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', 8, 0),
373374
(0, 'plg_multifactorauth_totp', 'plugin', 'totp', 'multifactorauth', 0, 1, 1, 0, 1, '', '', '', 1, 0),
374375
(0, 'plg_multifactorauth_yubikey', 'plugin', 'yubikey', 'multifactorauth', 0, 1, 1, 0, 1, '', '', '', 2, 0),
375376
(0, 'plg_multifactorauth_webauthn', 'plugin', 'webauthn', 'multifactorauth', 0, 1, 1, 0, 1, '', '', '', 3, 0),

installation/sql/postgresql/base.sql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,13 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
370370
(0, 'plg_system_tasknotification', 'plugin', 'tasknotification', 'system', 0, 1, 1, 0, 1, '', '', '', 24, 0),
371371
(0, 'plg_system_webauthn', 'plugin', 'webauthn', 'system', 0, 1, 1, 0, 1, '', '{}', '', 26, 0),
372372
(0, 'plg_task_checkfiles', 'plugin', 'checkfiles', 'task', 0, 1, 1, 0, 1, '', '{}', '', 1, 0),
373-
(0, 'plg_task_globalcheckin', 'plugin', 'globalcheckin', 'task', 0, 1, 1, 0, 0, '', '{}', '', 2, 0),
374-
(0, 'plg_task_requests', 'plugin', 'requests', 'task', 0, 1, 1, 0, 1, '', '{}', '', 3, 0),
375-
(0, 'plg_task_privacyconsent', 'plugin', 'privacyconsent', 'task', 0, 1, 1, 0, 1, '', '{}', '', 4, 0),
376-
(0, 'plg_task_rotatelogs', 'plugin', 'rotatelogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', 5, 0),
377-
(0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 1, '', '{}', '', 6, 0),
378-
(0, 'plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', 7, 0),
373+
(0, 'plg_task_deleteactionlogs', 'plugin', 'deleteactionlogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', 2, 0),
374+
(0, 'plg_task_globalcheckin', 'plugin', 'globalcheckin', 'task', 0, 1, 1, 0, 0, '', '{}', '', 3, 0),
375+
(0, 'plg_task_requests', 'plugin', 'requests', 'task', 0, 1, 1, 0, 1, '', '{}', '', 4, 0),
376+
(0, 'plg_task_privacyconsent', 'plugin', 'privacyconsent', 'task', 0, 1, 1, 0, 1, '', '{}', '', 5, 0),
377+
(0, 'plg_task_rotatelogs', 'plugin', 'rotatelogs', 'task', 0, 1, 1, 0, 1, '', '{}', '', 6, 0),
378+
(0, 'plg_task_sitestatus', 'plugin', 'sitestatus', 'task', 0, 1, 1, 0, 1, '', '{}', '', 7, 0),
379+
(0, 'plg_task_updatenotification', 'plugin', 'updatenotification', 'task', 0, 1, 1, 0, 1, '', '{}', '', 8, 0),
379380
(0, 'plg_multifactorauth_totp', 'plugin', 'totp', 'multifactorauth', 0, 1, 1, 0, 1, '', '', '', 1, 0),
380381
(0, 'plg_multifactorauth_yubikey', 'plugin', 'yubikey', 'multifactorauth', 0, 1, 1, 0, 1, '', '', '', 2, 0),
381382
(0, 'plg_multifactorauth_webauthn', 'plugin', 'webauthn', 'multifactorauth', 0, 1, 1, 0, 1, '', '', '', 3, 0),

libraries/src/Extension/ExtensionHelper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ class ExtensionHelper
318318

319319
// Core plugin extensions - task scheduler
320320
['plugin', 'checkfiles', 'task', 0],
321+
['plugin', 'deleteactionlogs', 'task', 0],
321322
['plugin', 'globalcheckin', 'task', 0],
322323
['plugin', 'privacyconsent', 'task', 0],
323324
['plugin', 'requests', 'task', 0],

plugins/system/actionlogs/actionlogs.xml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,4 @@
1919
<language tag="en-GB">language/en-GB/plg_system_actionlogs.ini</language>
2020
<language tag="en-GB">language/en-GB/plg_system_actionlogs.sys.ini</language>
2121
</languages>
22-
<config>
23-
<fields name="params">
24-
<fieldset name="basic">
25-
<field
26-
name="logDeletePeriod"
27-
type="number"
28-
label="PLG_SYSTEM_ACTIONLOGS_LOG_DELETE_PERIOD"
29-
description="PLG_SYSTEM_ACTIONLOGS_LOG_DELETE_PERIOD_DESC"
30-
default="0"
31-
min="0"
32-
filter="int"
33-
validate="number"
34-
/>
35-
<field
36-
name="lastrun"
37-
type="hidden"
38-
default="0"
39-
filter="integer"
40-
/>
41-
</fieldset>
42-
</fields>
43-
</config>
4422
</extension>

0 commit comments

Comments
 (0)