From 93b168139a508d797822c726e0ccc22da268f64e Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 15 Nov 2024 16:24:05 +0100 Subject: [PATCH] Migrate cronjob log clear to modern code --- .../Core/Api/Cronjobs/Logs/ClearLogs.ts | 22 +++++++ wcfsetup/install/files/acp/js/WCF.ACP.js | 57 ------------------- .../files/acp/templates/cronjobLogList.tpl | 22 +++++-- .../Core/Api/Cronjobs/Logs/ClearLogs.js | 23 ++++++++ .../files/lib/bootstrap/com.woltlab.wcf.php | 1 + .../cronjob/log/CronjobLogAction.class.php | 22 ------- .../core/cronjobs/logs/ClearLogs.class.php | 33 +++++++++++ 7 files changed, 95 insertions(+), 85 deletions(-) create mode 100644 ts/WoltLabSuite/Core/Api/Cronjobs/Logs/ClearLogs.ts create mode 100644 wcfsetup/install/files/js/WoltLabSuite/Core/Api/Cronjobs/Logs/ClearLogs.js create mode 100644 wcfsetup/install/files/lib/system/endpoint/controller/core/cronjobs/logs/ClearLogs.class.php diff --git a/ts/WoltLabSuite/Core/Api/Cronjobs/Logs/ClearLogs.ts b/ts/WoltLabSuite/Core/Api/Cronjobs/Logs/ClearLogs.ts new file mode 100644 index 0000000000..e6396c6826 --- /dev/null +++ b/ts/WoltLabSuite/Core/Api/Cronjobs/Logs/ClearLogs.ts @@ -0,0 +1,22 @@ +/** + * Deletes all entries of the cronjob log. + * + * @author Marcel Werk + * @copyright 2001-2024 WoltLab GmbH + * @license GNU Lesser General Public License + * @since 6.2 + * @woltlabExcludeBundle tiny + */ + +import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend"; +import { ApiResult, apiResultFromError, apiResultFromValue } from "../../Result"; + +export async function clearLogs(): Promise> { + try { + await prepareRequest(`${window.WSC_RPC_API_URL}core/cronjobs/logs`).delete().fetchAsJson(); + } catch (e) { + return apiResultFromError(e); + } + + return apiResultFromValue([]); +} diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index d559e5869d..782d9cdb8c 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -92,63 +92,6 @@ WCF.ACP.Cronjob.ExecutionHandler = Class.extend({ } }); -/** - * Handles the cronjob log list. - */ -WCF.ACP.Cronjob.LogList = Class.extend({ - /** - * error message dialog - * @var jQuery - */ - _dialog: null, - - /** - * Initializes WCF.ACP.Cronjob.LogList object. - */ - init: function() { - // bind event listener to delete cronjob log button - $('.jsCronjobLogDelete').click(function() { - WCF.System.Confirmation.show(WCF.Language.get('wcf.acp.cronjob.log.clear.confirm'), function(action) { - if (action == 'confirm') { - new WCF.Action.Proxy({ - autoSend: true, - data: { - actionName: 'clearAll', - className: 'wcf\\data\\cronjob\\log\\CronjobLogAction' - }, - success: function() { - window.location.reload(); - } - }); - } - }); - }); - - // bind event listeners to error badges - $('.jsCronjobError').click($.proxy(this._showError, this)); - }, - - /** - * Shows certain error message - * - * @param object event - */ - _showError: function(event) { - var $errorBadge = $(event.currentTarget); - - if (this._dialog === null) { - this._dialog = $('
' + $errorBadge.next().html() + '
').hide().appendTo(document.body); - this._dialog.wcfDialog({ - title: WCF.Language.get('wcf.acp.cronjob.log.error.details') - }); - } - else { - this._dialog.html('
' + $errorBadge.next().html() + '
'); - this._dialog.wcfDialog('open'); - } - } -}); - /** * Namespace for ACP package management. */ diff --git a/wcfsetup/install/files/acp/templates/cronjobLogList.tpl b/wcfsetup/install/files/acp/templates/cronjobLogList.tpl index af482fc14c..1140d117a2 100644 --- a/wcfsetup/install/files/acp/templates/cronjobLogList.tpl +++ b/wcfsetup/install/files/acp/templates/cronjobLogList.tpl @@ -1,13 +1,23 @@ {include file='header' pageTitle='wcf.acp.cronjob.log'} diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Cronjobs/Logs/ClearLogs.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Cronjobs/Logs/ClearLogs.js new file mode 100644 index 0000000000..e0fa3cd712 --- /dev/null +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Api/Cronjobs/Logs/ClearLogs.js @@ -0,0 +1,23 @@ +/** + * Deletes all entries of the cronjob log. + * + * @author Marcel Werk + * @copyright 2001-2024 WoltLab GmbH + * @license GNU Lesser General Public License + * @since 6.2 + * @woltlabExcludeBundle tiny + */ +define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend", "../../Result"], function (require, exports, Backend_1, Result_1) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + exports.clearLogs = clearLogs; + async function clearLogs() { + try { + await (0, Backend_1.prepareRequest)(`${window.WSC_RPC_API_URL}core/cronjobs/logs`).delete().fetchAsJson(); + } + catch (e) { + return (0, Result_1.apiResultFromError)(e); + } + return (0, Result_1.apiResultFromValue)([]); + } +}); diff --git a/wcfsetup/install/files/lib/bootstrap/com.woltlab.wcf.php b/wcfsetup/install/files/lib/bootstrap/com.woltlab.wcf.php index f3554ed8ec..7a17748c74 100644 --- a/wcfsetup/install/files/lib/bootstrap/com.woltlab.wcf.php +++ b/wcfsetup/install/files/lib/bootstrap/com.woltlab.wcf.php @@ -134,6 +134,7 @@ return static function (): void { $event->register(new \wcf\system\endpoint\controller\core\comments\responses\RenderResponse); $event->register(new \wcf\system\endpoint\controller\core\comments\responses\RenderResponses); $event->register(new \wcf\system\endpoint\controller\core\comments\responses\UpdateResponse); + $event->register(new \wcf\system\endpoint\controller\core\cronjobs\logs\ClearLogs); $event->register(new \wcf\system\endpoint\controller\core\messages\GetMentionSuggestions); $event->register(new \wcf\system\endpoint\controller\core\sessions\DeleteSession); } diff --git a/wcfsetup/install/files/lib/data/cronjob/log/CronjobLogAction.class.php b/wcfsetup/install/files/lib/data/cronjob/log/CronjobLogAction.class.php index bd295ba1f5..b3da9bfe79 100644 --- a/wcfsetup/install/files/lib/data/cronjob/log/CronjobLogAction.class.php +++ b/wcfsetup/install/files/lib/data/cronjob/log/CronjobLogAction.class.php @@ -3,7 +3,6 @@ namespace wcf\data\cronjob\log; use wcf\data\AbstractDatabaseObjectAction; -use wcf\system\WCF; /** * Executes cronjob log-related actions. @@ -22,25 +21,4 @@ class CronjobLogAction extends AbstractDatabaseObjectAction * @inheritDoc */ protected $className = CronjobLogEditor::class; - - /** - * @inheritDoc - */ - protected $requireACP = ['clearAll']; - - /** - * Validates the clear all action. - */ - public function validateClearAll() - { - WCF::getSession()->checkPermissions(['admin.management.canManageCronjob']); - } - - /** - * Deletes the entire cronjob log. - */ - public function clearAll() - { - CronjobLogEditor::clearLogs(); - } } diff --git a/wcfsetup/install/files/lib/system/endpoint/controller/core/cronjobs/logs/ClearLogs.class.php b/wcfsetup/install/files/lib/system/endpoint/controller/core/cronjobs/logs/ClearLogs.class.php new file mode 100644 index 0000000000..e17abcab5d --- /dev/null +++ b/wcfsetup/install/files/lib/system/endpoint/controller/core/cronjobs/logs/ClearLogs.class.php @@ -0,0 +1,33 @@ + + * @since 6.2 + */ +#[DeleteRequest('/core/cronjobs/logs')] +final class ClearLogs implements IController +{ + #[\Override] + public function __invoke(ServerRequestInterface $request, array $variables): ResponseInterface + { + WCF::getSession()->checkPermissions(['admin.management.canManageCronjob']); + + CronjobLogEditor::clearLogs(); + + return new JsonResponse([]); + } +} -- 2.20.1