From cbb2c4d7d1fea7c4cf867069d605399c00d92ac7 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Wed, 6 Nov 2024 15:05:05 +0100 Subject: [PATCH] Fix cache reset after data import ref https://www.woltlab.com/community/thread/309331-error-message-during-import-process-wcf-ajax-error-sessionexpired/ --- .../Core/Acp/Ui/DataImport/Manager.ts | 21 ++++++++---------- .../files/acp/templates/dataImport.tpl | 2 +- .../Core/Acp/Ui/DataImport/Manager.js | 22 ++++++++----------- .../lib/acp/form/DataImportForm.class.php | 9 ++++++-- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/ts/WoltLabSuite/Core/Acp/Ui/DataImport/Manager.ts b/ts/WoltLabSuite/Core/Acp/Ui/DataImport/Manager.ts index f248ad184d..51d937368f 100644 --- a/ts/WoltLabSuite/Core/Acp/Ui/DataImport/Manager.ts +++ b/ts/WoltLabSuite/Core/Acp/Ui/DataImport/Manager.ts @@ -14,31 +14,28 @@ import { AjaxResponse } from "../../../Controller/Clipboard/Data"; import { DialogCallbackSetup } from "../../../Ui/Dialog/Data"; import DomUtil from "../../../Dom/Util"; import UiDialog from "../../../Ui/Dialog"; +import { prepareRequest } from "WoltLabSuite/Core/Ajax/Backend"; export class AcpUiDataImportManager implements AjaxCallbackObject { private readonly queue: string[]; private readonly redirectUrl: string; private currentAction = ""; private index = -1; + private cacheClearEndpoint = ""; - constructor(queue: string[], redirectUrl: string) { + constructor(queue: string[], redirectUrl: string, cacheClearEndpoint: string) { this.queue = queue; this.redirectUrl = redirectUrl; + this.cacheClearEndpoint = cacheClearEndpoint; - this.invoke(); + void this.invoke(); } - private invoke(): void { + private async invoke(): Promise { this.index++; if (this.index >= this.queue.length) { - Ajax.apiOnce({ - url: "index.php?cache-clear/&t=" + Core.getXsrfToken(), - data: { - noRedirect: 1, - }, - silent: true, - success: () => this.showCompletedDialog(), - }); + await prepareRequest(this.cacheClearEndpoint).post().fetchAsResponse(); + this.showCompletedDialog(); } else { this.run(Language.get("wcf.acp.dataImport.data." + this.queue[this.index]), this.queue[this.index]); } @@ -108,7 +105,7 @@ export class AcpUiDataImportManager implements AjaxCallbackObject { parameters: data.parameters, }); } else { - this.invoke(); + void this.invoke(); } } diff --git a/wcfsetup/install/files/acp/templates/dataImport.tpl b/wcfsetup/install/files/acp/templates/dataImport.tpl index 619d1f3d98..e2831a1f88 100644 --- a/wcfsetup/install/files/acp/templates/dataImport.tpl +++ b/wcfsetup/install/files/acp/templates/dataImport.tpl @@ -10,7 +10,7 @@ }); const queue = [ {implode from=$queue item=item}'{@$item}'{/implode} ]; - new AcpUiDataImportManager(queue, '{link controller='RebuildData' encode=false}{/link}'); + new AcpUiDataImportManager(queue, '{link controller='RebuildData' encode=false}{/link}', '{$cacheClearEndpoint|encodeJS}'); }); {/if} diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/DataImport/Manager.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/DataImport/Manager.js index d3604923cd..3c49ba4abf 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/DataImport/Manager.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/DataImport/Manager.js @@ -1,4 +1,4 @@ -define(["require", "exports", "tslib", "../../../Ajax", "../../../Core", "../../../Language", "../../../Dom/Util", "../../../Ui/Dialog"], function (require, exports, tslib_1, Ajax, Core, Language, Util_1, Dialog_1) { +define(["require", "exports", "tslib", "../../../Ajax", "../../../Core", "../../../Language", "../../../Dom/Util", "../../../Ui/Dialog", "WoltLabSuite/Core/Ajax/Backend"], function (require, exports, tslib_1, Ajax, Core, Language, Util_1, Dialog_1, Backend_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AcpUiDataImportManager = void 0; @@ -12,22 +12,18 @@ define(["require", "exports", "tslib", "../../../Ajax", "../../../Core", "../../ redirectUrl; currentAction = ""; index = -1; - constructor(queue, redirectUrl) { + cacheClearEndpoint = ""; + constructor(queue, redirectUrl, cacheClearEndpoint) { this.queue = queue; this.redirectUrl = redirectUrl; - this.invoke(); + this.cacheClearEndpoint = cacheClearEndpoint; + void this.invoke(); } - invoke() { + async invoke() { this.index++; if (this.index >= this.queue.length) { - Ajax.apiOnce({ - url: "index.php?cache-clear/&t=" + Core.getXsrfToken(), - data: { - noRedirect: 1, - }, - silent: true, - success: () => this.showCompletedDialog(), - }); + await (0, Backend_1.prepareRequest)(this.cacheClearEndpoint).post().fetchAsResponse(); + this.showCompletedDialog(); } else { this.run(Language.get("wcf.acp.dataImport.data." + this.queue[this.index]), this.queue[this.index]); @@ -86,7 +82,7 @@ define(["require", "exports", "tslib", "../../../Ajax", "../../../Core", "../../ }); } else { - this.invoke(); + void this.invoke(); } } _dialogSetup() { diff --git a/wcfsetup/install/files/lib/acp/form/DataImportForm.class.php b/wcfsetup/install/files/lib/acp/form/DataImportForm.class.php index 052e8d5046..45fbee9c0b 100644 --- a/wcfsetup/install/files/lib/acp/form/DataImportForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/DataImportForm.class.php @@ -2,6 +2,7 @@ namespace wcf\acp\form; +use wcf\acp\action\CacheClearAction; use wcf\data\application\Application; use wcf\data\object\type\ObjectTypeCache; use wcf\form\AbstractForm; @@ -9,6 +10,7 @@ use wcf\system\application\ApplicationHandler; use wcf\system\exception\IllegalLinkException; use wcf\system\exception\UserInputException; use wcf\system\importer\UserImporter; +use wcf\system\request\LinkHandler; use wcf\system\WCF; use wcf\util\ArrayUtil; use wcf\util\StringUtil; @@ -136,7 +138,7 @@ class DataImportForm extends AbstractForm $collator = new \Collator(WCF::getLanguage()->getLocale()); \uksort( $this->exporters, - static fn (string $a, string $b) => $collator->compare( + static fn(string $a, string $b) => $collator->compare( WCF::getLanguage()->get('wcf.acp.dataImport.exporter.' . $a), WCF::getLanguage()->get('wcf.acp.dataImport.exporter.' . $b) ) @@ -301,7 +303,10 @@ class DataImportForm extends AbstractForm 'additionalData' => $this->additionalData, ]); - WCF::getTPL()->assign('queue', $queue); + WCF::getTPL()->assign([ + 'queue' => $queue, + 'cacheClearEndpoint' => LinkHandler::getInstance()->getControllerLink(CacheClearAction::class), + ]); } /** -- 2.20.1