2024-05-10 09:09:14 -04:00
/ * *
* SPDX - FileCopyrightText : 2016 - 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX - FileCopyrightText : 2014 ownCloud Inc .
* SPDX - License - Identifier : AGPL - 3.0 - or - later
2014-05-26 12:43:26 -04:00
* /
( function ( ) {
OC . Update = {
_started : false ,
2021-03-22 11:31:50 -04:00
options : { } ,
2014-05-26 12:43:26 -04:00
/ * *
2016-08-04 06:48:25 -04:00
* Start the update process .
2014-05-26 12:43:26 -04:00
*
* @ param $el progress list element
* @ param options
* /
2015-01-14 05:31:42 -05:00
start : function ( $el , options ) {
2014-05-26 12:43:26 -04:00
if ( this . _started ) {
return
}
2021-03-22 11:31:50 -04:00
this . options = options
2015-07-07 07:38:24 -04:00
let hasWarnings = false
2014-05-26 12:43:26 -04:00
this . $el = $el
this . _started = true
2015-10-13 11:34:13 -04:00
2016-03-30 17:38:26 -04:00
const self = this
2015-10-13 11:34:13 -04:00
$ ( window ) . on ( 'beforeunload.inprogress' , function ( ) {
2016-08-04 06:48:25 -04:00
return t ( 'core' , 'The update is in progress, leaving this page might interrupt the process in some environments.' )
2015-10-13 11:34:13 -04:00
} )
2016-03-30 17:38:26 -04:00
$ ( '#update-progress-title' ) . html ( t (
2014-05-26 12:43:26 -04:00
'core' ,
2016-08-04 06:48:25 -04:00
'Update to {version}' ,
{
2015-01-14 05:31:42 -05:00
version : options . version ,
2016-03-30 17:38:26 -04:00
} ,
) )
2014-05-26 12:43:26 -04:00
2018-10-09 01:44:26 -04:00
const updateEventSource = new OC . EventSource ( OC . getRootPath ( ) + '/core/ajax/update.php' )
2014-05-26 12:43:26 -04:00
updateEventSource . listen ( 'success' , function ( message ) {
2016-03-30 17:38:26 -04:00
self . setMessage ( message )
2014-05-26 12:43:26 -04:00
} )
2015-02-17 06:00:39 -05:00
updateEventSource . listen ( 'notice' , function ( message ) {
2016-03-30 17:38:26 -04:00
self . setPermanentMessage ( message )
2015-07-07 07:38:24 -04:00
hasWarnings = true
2015-02-17 06:00:39 -05:00
} )
2014-05-26 12:43:26 -04:00
updateEventSource . listen ( 'error' , function ( message ) {
2016-03-30 17:38:26 -04:00
$ ( '#update-progress-message' ) . hide ( )
$ ( '#update-progress-icon' )
. addClass ( 'icon-error-white' )
. removeClass ( 'icon-loading-dark' )
2015-10-14 02:17:52 -04:00
message = message || t ( 'core' , 'An error occurred.' )
2015-10-14 04:04:20 -04:00
$ ( window ) . off ( 'beforeunload.inprogress' )
2016-03-30 17:38:26 -04:00
self . setErrorMessage ( message )
2014-05-26 12:43:26 -04:00
message = t ( 'core' , 'Please reload the page.' )
2018-08-01 12:54:48 -04:00
$ ( '<p>' ) . append ( '<a href=".">' + message + '</a>' ) . appendTo ( $el )
2014-05-26 12:43:26 -04:00
updateEventSource . close ( )
} )
updateEventSource . listen ( 'failure' , function ( message ) {
2015-10-14 04:04:20 -04:00
$ ( window ) . off ( 'beforeunload.inprogress' )
2016-03-30 17:38:26 -04:00
$ ( '#update-progress-message' ) . hide ( )
$ ( '#update-progress-icon' )
. addClass ( 'icon-error-white' )
. removeClass ( 'icon-loading-dark' )
self . setErrorMessage ( message )
2018-08-03 07:30:49 -04:00
const updateUnsuccessful = $ ( '<p>' )
2016-02-08 03:19:16 -05:00
if ( message === 'Exception: Updates between multiple major versions and downgrades are unsupported.' ) {
2018-08-03 07:30:49 -04:00
updateUnsuccessful . append ( t ( 'core' , 'The update was unsuccessful. For more information <a href="{url}">check our forum post</a> covering this issue.' , { url : 'https://help.nextcloud.com/t/updates-between-multiple-major-versions-are-unsupported/7094' } ) )
2021-03-22 11:31:50 -04:00
} else if ( OC . Update . options . productName === 'Nextcloud' ) {
2018-08-03 07:30:49 -04:00
updateUnsuccessful . append ( t ( 'core' , 'The update was unsuccessful. '
2016-02-08 03:19:16 -05:00
+ 'Please report this issue to the '
2016-06-14 11:02:55 -04:00
+ '<a href="https://github.com/nextcloud/server/issues" target="_blank">Nextcloud community</a>.' ) )
2016-02-08 03:19:16 -05:00
}
2018-08-03 07:30:49 -04:00
updateUnsuccessful . appendTo ( $el )
2014-05-26 12:43:26 -04:00
} )
2014-05-28 05:29:22 -04:00
updateEventSource . listen ( 'done' , function ( ) {
2015-10-13 11:34:13 -04:00
$ ( window ) . off ( 'beforeunload.inprogress' )
2016-03-30 17:38:26 -04:00
$ ( '#update-progress-message' ) . hide ( )
$ ( '#update-progress-icon' )
. addClass ( 'icon-checkmark-white' )
2021-03-22 11:31:50 -04:00
. removeClass ( 'icon-loading-dark' )
2016-03-30 17:38:26 -04:00
2015-07-07 07:38:24 -04:00
if ( hasWarnings ) {
2022-09-12 03:16:09 -04:00
$el . find ( '.update-show-detailed' ) . before ( $ ( '<input type="button" class="primary" value="' + t ( 'core' , 'Continue to {productName}' , OC . Update . options ) + '">' ) . on ( 'click' , function ( ) {
2016-08-04 06:48:25 -04:00
window . location . reload ( )
} ) )
2015-07-07 07:38:24 -04:00
} else {
2016-08-04 06:48:25 -04:00
$el . find ( '.update-show-detailed' ) . before ( $ ( '<p id="redirect-countdown"></p>' ) )
2017-02-25 14:16:22 -05:00
2017-03-14 16:36:17 -04:00
for ( let i = 0 ; i <= 4 ; i ++ ) {
self . updateCountdown ( i , 4 )
2017-02-25 14:16:22 -05:00
}
2015-07-07 07:38:24 -04:00
setTimeout ( function ( ) {
2018-08-09 09:19:58 -04:00
OC . redirect ( window . location . href )
2015-07-07 07:38:24 -04:00
} , 3000 )
}
2014-05-26 12:43:26 -04:00
} )
} ,
2017-03-14 16:36:17 -04:00
updateCountdown : function ( i , total ) {
2017-02-25 14:16:22 -05:00
setTimeout ( function ( ) {
2021-03-22 11:31:50 -04:00
$ ( '#redirect-countdown' ) . text ( n ( 'core' , 'The update was successful. Redirecting you to {productName} in %n second.' , 'The update was successful. Redirecting you to {productName} in %n seconds.' , i , OC . Update . options ) )
2017-03-14 16:36:17 -04:00
} , ( total - i ) * 1000 )
2017-02-25 14:16:22 -05:00
} ,
2016-03-30 17:38:26 -04:00
setMessage : function ( message ) {
$ ( '#update-progress-message' ) . html ( message )
2016-03-31 08:27:01 -04:00
$ ( '#update-progress-detailed' )
2018-08-03 07:30:49 -04:00
. append ( '<p>' + message + '</p>' )
2016-03-30 17:38:26 -04:00
} ,
setPermanentMessage : function ( message ) {
$ ( '#update-progress-message' ) . html ( message )
$ ( '#update-progress-message-warnings' )
. show ( )
2016-03-31 08:27:01 -04:00
. append ( $ ( '<ul>' ) . append ( message ) )
$ ( '#update-progress-detailed' )
2018-08-03 07:30:49 -04:00
. append ( '<p>' + message + '</p>' )
2016-03-30 17:38:26 -04:00
} ,
2016-08-04 06:48:25 -04:00
2016-03-30 17:38:26 -04:00
setErrorMessage : function ( message ) {
$ ( '#update-progress-message-error' )
. show ( )
. html ( message )
2016-03-31 08:27:01 -04:00
$ ( '#update-progress-detailed' )
2018-08-03 07:30:49 -04:00
. append ( '<p>' + message + '</p>' )
2025-10-01 10:03:40 -04:00
} ,
2014-05-26 12:43:26 -04:00
}
} ) ( )
2022-01-19 11:12:43 -05:00
window . addEventListener ( 'DOMContentLoaded' , function ( ) {
$ ( '.updateButton' ) . on ( 'click' , function ( ) {
const $updateEl = $ ( '.update' )
const $progressEl = $ ( '.update-progress' )
$progressEl . removeClass ( 'hidden' )
$ ( '.updateOverview' ) . addClass ( 'hidden' )
$ ( '#update-progress-message-error' ) . hide ( )
$ ( '#update-progress-message-warnings' ) . hide ( )
OC . Update . start ( $progressEl , {
productName : $updateEl . attr ( 'data-productname' ) ,
version : $updateEl . attr ( 'data-version' ) ,
} )
return false
2016-03-31 08:27:01 -04:00
} )
2022-01-18 12:37:45 -05:00
2022-01-19 11:12:43 -05:00
$ ( '.update-show-detailed' ) . on ( 'click' , function ( ) {
$ ( '#update-progress-detailed' ) . toggleClass ( 'hidden' )
return false
} )
2013-07-10 18:00:01 -04:00
} )