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 00000000000..e6396c68264 --- /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 d559e5869da..782d9cdb8c2 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 af482fc14c2..1140d117a29 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 00000000000..e0fa3cd7129 --- /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 f3554ed8ecd..7a17748c74c 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 @@ static function (\wcf\event\endpoint\ControllerCollecting $event) { $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 bd295ba1f51..b3da9bfe79f 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 00000000000..e17abcab5dc --- /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([]); + } +}