From c559db0de66fd3041b20c0eec32de42e9c564702 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 21 Feb 2015 22:59:09 +1100 Subject: [PATCH] Extract the updater JS to its own file, add helper to find missing dependencies --- modules/system/assets/js/updates/updates.js | 110 ++++++++++++++++++ modules/system/classes/PluginManager.php | 27 ++++- modules/system/controllers/Updates.php | 1 + .../system/controllers/updates/_execute.htm | 77 +----------- 4 files changed, 138 insertions(+), 77 deletions(-) create mode 100644 modules/system/assets/js/updates/updates.js diff --git a/modules/system/assets/js/updates/updates.js b/modules/system/assets/js/updates/updates.js new file mode 100644 index 000000000..c2402bf49 --- /dev/null +++ b/modules/system/assets/js/updates/updates.js @@ -0,0 +1,110 @@ +/* + * Updates class + * + * Dependences: + * - Waterfall plugin (waterfall.js) + */ + ++function ($) { "use strict"; + + var UpdateProcess = function () { + + // Init + this.init() + } + + UpdateProcess.prototype.init = function() { + var self = this + this.activeStep = null + this.updateSteps = null + } + + UpdateProcess.prototype.execute = function(steps) { + this.updateSteps = steps + this.runUpdate() + } + + UpdateProcess.prototype.runUpdate = function(fromStep) { + $.waterfall.apply(this, this.buildEventChain(this.updateSteps, fromStep)) + .fail(function(reason){ + var + template = $('#executeFailed').html(), + html = Mustache.to_html(template, { reason: reason }) + + $('#executeActivity').hide() + $('#executeStatus').html(html) + }) + } + + UpdateProcess.prototype.retryUpdate = function() { + $('#executeActivity').show() + $('#executeStatus').html('') + + this.runUpdate(this.activeStep) + } + + UpdateProcess.prototype.buildEventChain = function(steps, fromStep) { + var self = this, + eventChain = [], + skipStep = fromStep ? true : false + + $.each(steps, function(index, step){ + + if (step == fromStep) + skipStep = false + + if (skipStep) + return true // Continue + + eventChain.push(function(){ + var deferred = $.Deferred() + + self.activeStep = step + self.setLoadingBar(true, step.label) + + $.request('onExecuteStep', { + data: step, + success: function(data){ + setTimeout(function() { deferred.resolve() }, 600) + + if (step.code == 'completeUpdate' || step.code == 'completeInstall') + this.success(data) + else + self.setLoadingBar(false) + }, + error: function(data){ + self.setLoadingBar(false) + deferred.reject(data.responseText) + } + }) + + return deferred + }) + }) + + return eventChain + } + + UpdateProcess.prototype.setLoadingBar = function(state, message) { + var loadingBar = $('#executeLoadingBar'), + messageDiv = $('#executeMessage') + + if (state) + loadingBar.removeClass('bar-loaded') + else + loadingBar.addClass('bar-loaded') + + if (message) + messageDiv.text(message) + } + + if ($.oc === undefined) + $.oc = {} + + $.oc.updateProcess = new UpdateProcess; + + // $(document).ready(function(){ + // new $oc.updateProcess + // }) + +}(window.jQuery); \ No newline at end of file diff --git a/modules/system/classes/PluginManager.php b/modules/system/classes/PluginManager.php index 31f027385..cd248d3d2 100644 --- a/modules/system/classes/PluginManager.php +++ b/modules/system/classes/PluginManager.php @@ -511,7 +511,32 @@ class PluginManager // // Dependencies // - + + /** + * Scans the system plugins to locate any dependencies + * that are not currently installed. + */ + public function findMissingDependencies() + { + $missing = []; + + foreach ($this->plugins as $id => $plugin) { + if (!$required = $this->getDependencies($plugin)) { + continue; + } + + foreach ($required as $require) { + if ($this->hasPlugin($require)) { + continue; + } + + $missing[] = $require; + } + } + + return $missing; + } + /** * Cross checks all plugins and their dependancies, if not met plugins * are disabled and vice versa. diff --git a/modules/system/controllers/Updates.php b/modules/system/controllers/Updates.php index 6b504cc72..934f10e9c 100644 --- a/modules/system/controllers/Updates.php +++ b/modules/system/controllers/Updates.php @@ -36,6 +36,7 @@ class Updates extends Controller { parent::__construct(); + $this->addJs('/modules/system/assets/js/updates/updates.js', 'core'); $this->addCss('/modules/system/assets/css/updates.css', 'core'); BackendMenu::setContext('October.System', 'system', 'updates'); diff --git a/modules/system/controllers/updates/_execute.htm b/modules/system/controllers/updates/_execute.htm index e5770bfcf..38d0185c0 100644 --- a/modules/system/controllers/updates/_execute.htm +++ b/modules/system/controllers/updates/_execute.htm @@ -49,85 +49,10 @@