Skip to content

Commit

Permalink
Migrate cronjob log clear to modern code
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntimeX committed Nov 15, 2024
1 parent 0eefa53 commit 93b1681
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 85 deletions.
22 changes: 22 additions & 0 deletions ts/WoltLabSuite/Core/Api/Cronjobs/Logs/ClearLogs.ts
Original file line number Diff line number Diff line change
@@ -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 <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([]);
}
57 changes: 0 additions & 57 deletions wcfsetup/install/files/acp/js/WCF.ACP.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $('<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.
*/
Expand Down
22 changes: 16 additions & 6 deletions wcfsetup/install/files/acp/templates/cronjobLogList.tpl
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
{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>

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wcfsetup/install/files/lib/bootstrap/com.woltlab.wcf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace wcf\data\cronjob\log;

use wcf\data\AbstractDatabaseObjectAction;
use wcf\system\WCF;

/**
* Executes cronjob log-related actions.
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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([]);
}
}

0 comments on commit 93b1681

Please sign in to comment.