Improved worker process for data import
authorAlexander Ebert <ebert@woltlab.com>
Sun, 30 Jun 2013 00:28:47 +0000 (02:28 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 30 Jun 2013 00:28:47 +0000 (02:28 +0200)
wcfsetup/install/files/acp/js/WCF.ACP.js
wcfsetup/install/files/acp/templates/dataImport.tpl

index d484b7cfe3d0aae1afec4e27d162fda9a6050f95..35853c24c7d6766e9481d9ee020ea87f6a5e73e7 100644 (file)
@@ -2189,17 +2189,22 @@ WCF.ACP.User.EnableHandler = {
        }
 };
 
+/**
+ * Namespace for import-related classes.
+ */
+WCF.ACP.Import = { };
+
 /**
  * Importer for ACP.
  * 
- * @param      object          callback
+ * @param      array<string>   objectTypes
  */
-WCF.ACP.Importer = Class.extend({
+WCF.ACP.Import.Manager = Class.extend({
        /**
-        * success callback
-        * @var object
+        * current action
+        * @var string
         */
-       _callback: null,
+       _currentAction: '',
        
        /**
         * dialog overlay
@@ -2207,6 +2212,18 @@ WCF.ACP.Importer = Class.extend({
         */
        _dialog: null,
        
+       /**
+        * current object type index
+        * @var integer
+        */
+       _index: -1,
+       
+       /**
+        * list of object types
+        * @var array<string>
+        */
+       _objectTypes: [ ],
+       
        /**
         * action proxy
         * @var WCF.Action.Proxy
@@ -2216,23 +2233,47 @@ WCF.ACP.Importer = Class.extend({
        /**
         * Initializes the WCF.ACP.Importer object.
         * 
-        * @param       object          callback
+        * @param       array<string>   objectTypes
         */
-       init: function(callback) {
-               this._callback = callback;
+       init: function(objectTypes) {
+               this._currentAction = '';
+               this._index = -1;
+               this._objectTypes = objectTypes;
                this._proxy = new WCF.Action.Proxy({
                        showLoadingOverlay: false,
                        success: $.proxy(this._success, this),
                        url: 'index.php/WorkerProxy/?t=' + SECURITY_TOKEN + SID_ARG_2ND
                });
+               
+               this._invoke();
        },
        
        /**
         * Invokes importing of an object type.
+        */
+       _invoke: function() {
+               this._index++;
+               if (this._index >= this._objectTypes.length) {
+                       this._dialog.find('.icon-spinner').removeClass('icon-spinner').addClass('icon-ok');
+                       
+                       // TODO: invoke cleanup here
+               }
+               else {
+                       this._run(
+                               WCF.Language.get('wcf.acp.dataImport.import.' + this._objectTypes[this._index]),
+                               this._objectTypes[this._index]
+                       );
+               }
+       },
+       
+       /**
+        * Executes import of given object type.
         * 
+        * @param       string          currentAction
         * @param       string          objectType
         */
-       run: function(objectType) {
+       _run: function(currentAction, objectType) {
+               this._currentAction = currentAction;
                this._proxy.setOption('data', {
                        className: 'wcf\\system\\worker\\ImportWorker',
                        parameters: {
@@ -2261,6 +2302,10 @@ WCF.ACP.Importer = Class.extend({
                        this._dialog.html(data.template);
                }
                
+               if (this._currentAction) {
+                       this._dialog.find('h1').text(this._currentAction);
+               }
+               
                // update progress
                this._dialog.find('progress').attr('value', data.progress).text(data.progress + '%').next('span').text(data.progress + '%');
                
@@ -2275,7 +2320,7 @@ WCF.ACP.Importer = Class.extend({
                        this._proxy.sendRequest();
                }
                else {
-                       this._callback(this, data);
+                       this._invoke();
                }
        }
 });
index e8fb95482b9dda8aea1035699e6a1d440d8b14d4..47d215fa95eec354d4789a2c0c3e321ca0d4a6a4 100644 (file)
@@ -8,22 +8,8 @@
                                {implode from=$importers item=importer}'wcf.acp.dataImport.import.{@$importer}': '{lang}wcf.acp.dataImport.import.{@$importer}{/lang}'{/implode}
                        });
                        
-                       var $queue = [ {implode from=$queue item=item}'{@$item}'{/implode} ];
-                       var $queueID = 0;
-                       
-                       function runProcess() {
-                               new WCF.ACP.Worker('mail', 'wcf\\system\\worker\\ImportWorker', WCF.Language.get('wcf.acp.dataImport.import.' + $queue[$queueID]), {
-                                       objectType: $queue[$queueID]
-                               }, function(worker) {
-                                       $queueID++;
-                                       if ($queueID < $queue.length) {
-                                               worker._dialog.wcfDialog('close');
-                                               runProcess();
-                                       }
-                               });
-                       }
-                       
-                       runProcess();
+                       var $queues = [ {implode from=$queue item=item}'{@$item}'{/implode} ];
+                       new WCF.ACP.Import.Manager($queues);
                {/if}
                
                $('.jsImportSection').change(function(event) {