From 971fbab8711fc9885d3285d9bacc654525271347 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sun, 30 Jun 2013 02:28:47 +0200 Subject: [PATCH] Improved worker process for data import --- wcfsetup/install/files/acp/js/WCF.ACP.js | 65 ++++++++++++++++--- .../files/acp/templates/dataImport.tpl | 18 +---- 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/wcfsetup/install/files/acp/js/WCF.ACP.js b/wcfsetup/install/files/acp/js/WCF.ACP.js index d484b7cfe3..35853c24c7 100644 --- a/wcfsetup/install/files/acp/js/WCF.ACP.js +++ b/wcfsetup/install/files/acp/js/WCF.ACP.js @@ -2189,17 +2189,22 @@ WCF.ACP.User.EnableHandler = { } }; +/** + * Namespace for import-related classes. + */ +WCF.ACP.Import = { }; + /** * Importer for ACP. * - * @param object callback + * @param array 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 + */ + _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 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(); } } }); diff --git a/wcfsetup/install/files/acp/templates/dataImport.tpl b/wcfsetup/install/files/acp/templates/dataImport.tpl index e8fb95482b..47d215fa95 100644 --- a/wcfsetup/install/files/acp/templates/dataImport.tpl +++ b/wcfsetup/install/files/acp/templates/dataImport.tpl @@ -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) { -- 2.20.1