From e10a7b8fe6f7e057771f7df4f626bd1948e4d6fb Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 20 Mar 2021 13:37:38 +0100 Subject: [PATCH] Move cronjob execution to `BootstrapFrontend` and use `Ajax` module --- .../templates/headIncludeJavaScript.tpl | 15 +-------------- ts/WoltLabSuite/Core/BootstrapFrontend.ts | 13 +++++++++++++ .../js/WoltLabSuite/Core/BootstrapFrontend.js | 13 ++++++++++++- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/com.woltlab.wcf/templates/headIncludeJavaScript.tpl b/com.woltlab.wcf/templates/headIncludeJavaScript.tpl index 814fef7aae..ae8b25ec12 100644 --- a/com.woltlab.wcf/templates/headIncludeJavaScript.tpl +++ b/com.woltlab.wcf/templates/headIncludeJavaScript.tpl @@ -151,6 +151,7 @@ window.addEventListener('pageshow', function(event) { force: {if $forceBackgroundQueuePerform|isset}true{else}false{/if} }, enableUserPopover: {if $__wcf->getSession()->getPermission('user.profile.canViewUserProfile')}true{else}false{/if}, + executeCronjobs: {if $executeCronjobs}true{else}false{/if}, styleChanger: {if $__wcf->getStyleHandler()->showStyleChanger()}true{else}false{/if} }); @@ -225,20 +226,6 @@ window.addEventListener('pageshow', function(event) { {event name='javascriptInit'} - {if $executeCronjobs} - new WCF.Action.Proxy({ - autoSend: true, - data: { - className: 'wcf\\data\\cronjob\\CronjobAction', - actionName: 'executeCronjobs' - }, - showLoadingOverlay: false, - failure: function() { - return false; - } - }); - {/if} - {if ENABLE_POLLING && $__wcf->user->userID} require(['WoltLabSuite/Core/Notification/Handler'], function(NotificationHandler) { NotificationHandler.setup({ diff --git a/ts/WoltLabSuite/Core/BootstrapFrontend.ts b/ts/WoltLabSuite/Core/BootstrapFrontend.ts index 07c2e563ef..658626f7e1 100644 --- a/ts/WoltLabSuite/Core/BootstrapFrontend.ts +++ b/ts/WoltLabSuite/Core/BootstrapFrontend.ts @@ -14,6 +14,7 @@ import * as ControllerPopover from "./Controller/Popover"; import * as UiUserIgnore from "./Ui/User/Ignore"; import * as UiPageHeaderMenu from "./Ui/Page/Header/Menu"; import * as UiMessageUserConsent from "./Ui/Message/UserConsent"; +import * as Ajax from "./Ajax"; interface BoostrapOptions { backgroundQueue: { @@ -21,6 +22,7 @@ interface BoostrapOptions { force: boolean; }; enableUserPopover: boolean; + executeCronjobs: boolean; styleChanger: boolean; } @@ -61,6 +63,17 @@ export function setup(options: BoostrapOptions): void { _initUserPopover(); } + if (options.executeCronjobs) { + Ajax.apiOnce({ + data: { + className: "wcf\\data\\cronjob\\CronjobAction", + actionName: "executeCronjobs", + }, + failure: () => false, + silent: true, + }); + } + BackgroundQueue.setUrl(options.backgroundQueue.url); if (Math.random() < 0.1 || options.backgroundQueue.force) { // invoke the queue roughly every 10th request or on demand diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/BootstrapFrontend.js b/wcfsetup/install/files/js/WoltLabSuite/Core/BootstrapFrontend.js index 2c370e1970..381c737dc7 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/BootstrapFrontend.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/BootstrapFrontend.js @@ -6,7 +6,7 @@ * @license GNU Lesser General Public License * @module WoltLabSuite/Core/BootstrapFrontend */ -define(["require", "exports", "tslib", "./BackgroundQueue", "./Bootstrap", "./Controller/Style/Changer", "./Controller/Popover", "./Ui/User/Ignore", "./Ui/Page/Header/Menu", "./Ui/Message/UserConsent"], function (require, exports, tslib_1, BackgroundQueue, Bootstrap, ControllerStyleChanger, ControllerPopover, UiUserIgnore, UiPageHeaderMenu, UiMessageUserConsent) { +define(["require", "exports", "tslib", "./BackgroundQueue", "./Bootstrap", "./Controller/Style/Changer", "./Controller/Popover", "./Ui/User/Ignore", "./Ui/Page/Header/Menu", "./Ui/Message/UserConsent", "./Ajax"], function (require, exports, tslib_1, BackgroundQueue, Bootstrap, ControllerStyleChanger, ControllerPopover, UiUserIgnore, UiPageHeaderMenu, UiMessageUserConsent, Ajax) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setup = void 0; @@ -17,6 +17,7 @@ define(["require", "exports", "tslib", "./BackgroundQueue", "./Bootstrap", "./Co UiUserIgnore = tslib_1.__importStar(UiUserIgnore); UiPageHeaderMenu = tslib_1.__importStar(UiPageHeaderMenu); UiMessageUserConsent = tslib_1.__importStar(UiMessageUserConsent); + Ajax = tslib_1.__importStar(Ajax); /** * Initializes user profile popover. */ @@ -48,6 +49,16 @@ define(["require", "exports", "tslib", "./BackgroundQueue", "./Bootstrap", "./Co if (options.enableUserPopover) { _initUserPopover(); } + if (options.executeCronjobs) { + Ajax.apiOnce({ + data: { + className: "wcf\\data\\cronjob\\CronjobAction", + actionName: "executeCronjobs", + }, + failure: () => false, + silent: true, + }); + } BackgroundQueue.setUrl(options.backgroundQueue.url); if (Math.random() < 0.1 || options.backgroundQueue.force) { // invoke the queue roughly every 10th request or on demand -- 2.20.1