--- /dev/null
+/**
+ * Deletes all entries of the cronjob log.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.2
+ * @woltlabExcludeBundle tiny
+ */
+
+import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend";
+import { ApiResult, apiResultFromError, apiResultFromValue } from "../../Result";
+
+export async function clearLogs(): Promise<ApiResult<[]>> {
+ try {
+ await prepareRequest(`${window.WSC_RPC_API_URL}core/cronjobs/logs`).delete().fetchAsJson();
+ } catch (e) {
+ return apiResultFromError(e);
+ }
+
+ return apiResultFromValue([]);
+}
}
});
-/**
- * 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 = $('<div style="overflow: auto"><pre>' + $errorBadge.next().html() + '</pre></div>').hide().appendTo(document.body);
- this._dialog.wcfDialog({
- title: WCF.Language.get('wcf.acp.cronjob.log.error.details')
- });
- }
- else {
- this._dialog.html('<pre>' + $errorBadge.next().html() + '</pre>');
- this._dialog.wcfDialog('open');
- }
- }
-});
-
/**
* Namespace for ACP package management.
*/
{include file='header' pageTitle='wcf.acp.cronjob.log'}
<script data-relocate="true">
- $(function() {
- WCF.Language.addObject({
- 'wcf.acp.cronjob.log.clear.confirm': '{jslang}wcf.acp.cronjob.log.clear.confirm{/jslang}',
- 'wcf.acp.cronjob.log.error.details': '{jslang}wcf.acp.cronjob.log.error.details{/jslang}'
+ require(['WoltLabSuite/Core/Api/Cronjobs/Logs/ClearLogs', 'Ui/Notification', 'WoltLabSuite/Core/Component/Confirmation'], ({ clearLogs }, UiNotification, { confirmationFactory }) => {
+ document.querySelectorAll('.jsCronjobLogDelete').forEach((button) => {
+ button.addEventListener('click', async () => {
+ const result = await confirmationFactory()
+ .custom('{jslang}wcf.acp.cronjob.log.clear.confirm{/jslang}')
+ .withoutMessage();
+
+ if (result) {
+ const response = await clearLogs();
+ if (response.ok) {
+ UiNotification.show(undefined, () => {
+ window.location.reload();
+ });
+ }
+ }
+ });
});
-
- new WCF.ACP.Cronjob.LogList();
});
</script>
--- /dev/null
+/**
+ * Deletes all entries of the cronjob log.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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)([]);
+ }
+});
$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);
}
namespace wcf\data\cronjob\log;
use wcf\data\AbstractDatabaseObjectAction;
-use wcf\system\WCF;
/**
* Executes cronjob log-related actions.
* @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();
- }
}
--- /dev/null
+<?php
+
+namespace wcf\system\endpoint\controller\core\cronjobs\logs;
+
+use Laminas\Diactoros\Response\JsonResponse;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use wcf\data\cronjob\log\CronjobLogEditor;
+use wcf\system\endpoint\DeleteRequest;
+use wcf\system\endpoint\IController;
+use wcf\system\WCF;
+
+/**
+ * API endpoint for the deletion of all entries of the cronjob log.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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([]);
+ }
+}