Commit 3c73204 1 parent 0b4b606 commit 3c73204 Copy full SHA for 3c73204
File tree 1 file changed +29
-1
lines changed
1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -114,7 +114,12 @@ class UpdateCommand extends Command {
114
114
return ;
115
115
}
116
116
117
- return this . ui . listr ( tasks , context ) ;
117
+ return this . ui . listr ( tasks , context ) . catch ( error =>
118
+ this . rollbackFromFail ( error , {
119
+ argv,
120
+ version : context . vesion
121
+ } )
122
+ ) ;
118
123
} ) ;
119
124
} ) ;
120
125
}
@@ -196,6 +201,24 @@ class UpdateCommand extends Command {
196
201
} ) ;
197
202
}
198
203
204
+ rollbackFromFail ( error , ctx ) {
205
+ const oldVer = this . system . getInstance ( ) . cliConfig . get ( 'previous-version' ) ;
206
+ const newVer = ctx . version ;
207
+ this . ui . error ( error ) ;
208
+ const question = `Unable to upgrade Ghost from v${ oldVer } to v${ newVer } - Would you like to revert back to v${ oldVer } ?` ;
209
+ const promise = ctx . argv [ 'auto-rollback' ] ? Promise . resolve ( true ) : this . ui . confirm ( question , true ) ;
210
+
211
+ return promise . then ( answer => {
212
+ if ( ! answer ) {
213
+ return Promise . resolve ( ) ;
214
+ }
215
+
216
+ return this . run ( {
217
+ rollback : true
218
+ } ) ;
219
+ } ) ;
220
+ }
221
+
199
222
link ( context ) {
200
223
const symlinkSync = require ( 'symlink-or-copy' ) . sync ;
201
224
@@ -233,6 +256,11 @@ UpdateCommand.options = {
233
256
describe : 'Limit update to Ghost 1.x releases' ,
234
257
type : 'boolean' ,
235
258
default : false
259
+ } ,
260
+ 'auto-rollback' : {
261
+ description : '[--no-auto-rollback] Enable/Disable automatically rolling back Ghost if updating fails' ,
262
+ type : 'boolean' ,
263
+ default : false
236
264
}
237
265
} ;
238
266
UpdateCommand . checkVersion = true ;
You can’t perform that action at this time.
0 commit comments