nextcloud /
server
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | /* |
||
| 2 | * Copyright (c) 2014 |
||
| 3 | * |
||
| 4 | * This file is licensed under the Affero General Public License version 3 |
||
| 5 | * or later. |
||
| 6 | * |
||
| 7 | * See the COPYING-README file. |
||
| 8 | * |
||
| 9 | */ |
||
| 10 | |||
| 11 | (function() { |
||
| 12 | OC.Update = { |
||
| 13 | _started : false, |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Start the upgrade process. |
||
| 17 | * |
||
| 18 | * @param $el progress list element |
||
| 19 | */ |
||
| 20 | start: function($el, options) { |
||
| 21 | if (this._started) { |
||
| 22 | return; |
||
| 23 | } |
||
| 24 | |||
| 25 | var hasWarnings = false; |
||
| 26 | |||
| 27 | this.$el = $el; |
||
| 28 | |||
| 29 | this._started = true; |
||
| 30 | |||
| 31 | $(window).on('beforeunload.inprogress', function () { |
||
| 32 | return t('core', 'The upgrade is in progress, leaving this page might interrupt the process in some environments.'); |
||
| 33 | }); |
||
| 34 | |||
| 35 | this.addMessage(t( |
||
| 36 | 'core', |
||
| 37 | 'Updating {productName} to version {version}, this may take a while.', { |
||
| 38 | productName: options.productName || 'ownCloud', |
||
| 39 | version: options.version |
||
| 40 | }), |
||
| 41 | 'bold' |
||
| 42 | ).append('<br />'); // FIXME: these should be ul/li with CSS paddings! |
||
| 43 | |||
| 44 | var updateEventSource = new OC.EventSource(OC.webroot+'/core/ajax/update.php'); |
||
| 45 | updateEventSource.listen('success', function(message) { |
||
| 46 | $('<span>').append(message).append('<br />').appendTo($el); |
||
| 47 | }); |
||
| 48 | updateEventSource.listen('notice', function(message) { |
||
| 49 | $('<span>').addClass('error').append(message).append('<br />').appendTo($el); |
||
| 50 | hasWarnings = true; |
||
| 51 | }); |
||
| 52 | updateEventSource.listen('error', function(message) { |
||
| 53 | message = message || t('core', 'An error occurred.'); |
||
| 54 | $(window).off('beforeunload.inprogress'); |
||
| 55 | $('<span>').addClass('error').append(message).append('<br />').appendTo($el); |
||
| 56 | message = t('core', 'Please reload the page.'); |
||
| 57 | $('<span>').addClass('error').append('<a href=".">'+message+'</a><br />').appendTo($el); |
||
| 58 | updateEventSource.close(); |
||
| 59 | }); |
||
| 60 | updateEventSource.listen('failure', function(message) { |
||
| 61 | $(window).off('beforeunload.inprogress'); |
||
| 62 | $('<span>').addClass('error').append(message).append('<br />').appendTo($el); |
||
| 63 | var span = $('<span>') |
||
| 64 | .addClass('bold'); |
||
| 65 | if(message === 'Exception: Updates between multiple major versions and downgrades are unsupported.') { |
||
| 66 | span.append(t('core', 'The update was unsuccessful. For more information <a href="{url}">check our forum post</a> covering this issue.', {'url': 'https://forum.owncloud.org/viewtopic.php?f=17&t=32087'})); |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 67 | } else { |
||
| 68 | span.append(t('core', 'The update was unsuccessful. ' + |
||
| 69 | 'Please report this issue to the ' + |
||
| 70 | '<a href="https://github.com/nextcloud/server/issues" target="_blank">Nextcloud community</a>.')); |
||
| 71 | } |
||
| 72 | span.appendTo($el); |
||
| 73 | }); |
||
| 74 | updateEventSource.listen('done', function() { |
||
| 75 | $(window).off('beforeunload.inprogress'); |
||
| 76 | |||
| 77 | if (hasWarnings) { |
||
| 78 | $('<span>').addClass('bold') |
||
| 79 | .append('<br />') |
||
| 80 | .append(t('core', 'The update was successful. There were warnings.')) |
||
| 81 | .appendTo($el); |
||
| 82 | var message = t('core', 'Please reload the page.'); |
||
| 83 | $('<span>').append('<br />').append(message).append('<br />').appendTo($el); |
||
| 84 | } else { |
||
| 85 | // FIXME: use product name |
||
| 86 | $('<span>').addClass('bold') |
||
| 87 | .append('<br />') |
||
| 88 | .append(t('core', 'The update was successful. Redirecting you to Nextcloud now.')) |
||
| 89 | .appendTo($el); |
||
| 90 | setTimeout(function () { |
||
| 91 | OC.redirect(OC.webroot + '/'); |
||
| 92 | }, 3000); |
||
| 93 | } |
||
| 94 | }); |
||
| 95 | }, |
||
| 96 | |||
| 97 | addMessage: function(message, className) { |
||
| 98 | var $span = $('<span>'); |
||
| 99 | $span.addClass(className).append(message).append('<br />').appendTo(this.$el); |
||
| 100 | return $span; |
||
| 101 | } |
||
| 102 | }; |
||
| 103 | |||
| 104 | })(); |
||
| 105 | |||
| 106 | $(document).ready(function() { |
||
| 107 | $('.updateButton').on('click', function() { |
||
| 108 | var $updateEl = $('.update'); |
||
| 109 | var $progressEl = $('.updateProgress'); |
||
| 110 | $progressEl.removeClass('hidden'); |
||
| 111 | $('.updateOverview').addClass('hidden'); |
||
| 112 | OC.Update.start($progressEl, { |
||
| 113 | productName: $updateEl.attr('data-productname'), |
||
| 114 | version: $updateEl.attr('data-version'), |
||
| 115 | }); |
||
| 116 | return false; |
||
| 117 | }); |
||
| 118 | }); |
||
| 119 |