Fix cache reset after data import
authorMarcel Werk <burntime@woltlab.com>
Wed, 6 Nov 2024 14:05:05 +0000 (15:05 +0100)
committerMarcel Werk <burntime@woltlab.com>
Wed, 6 Nov 2024 14:46:17 +0000 (15:46 +0100)
ref https://www.woltlab.com/community/thread/309331-error-message-during-import-process-wcf-ajax-error-sessionexpired/

ts/WoltLabSuite/Core/Acp/Ui/DataImport/Manager.ts
wcfsetup/install/files/acp/templates/dataImport.tpl
wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/DataImport/Manager.js
wcfsetup/install/files/lib/acp/form/DataImportForm.class.php

index f248ad184d1215e11c04b9a4dadc45b27e9cd914..51d937368f2325cbec345262508c6cd9351a063c 100644 (file)
@@ -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<void> {
     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();
     }
   }
 
index 619d1f3d98e926a90f60acd5c486d9c6089dd60a..e2831a1f8829e655d268f4c471fedadf56dbf131 100644 (file)
@@ -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}');
                });
        </script>
 {/if}
index d3604923cd1ae3f0c9192cfb21d476fd7d9de9e6..3c49ba4abf0212832f79acdb2b5b23248ad76c90 100644 (file)
@@ -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() {
index 052e8d50464dc34ff4c323584e95ecb082ed67e9..45fbee9c0ba5bc44c238115c58fb88e8c2b1c27d 100644 (file)
@@ -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),
+        ]);
     }
 
     /**