|
| 1 | +var Step = require( "step" ), |
| 2 | + rimraf = require( "rimraf" ), |
| 3 | + pluginsDb = require( "./pluginsdb" ), |
| 4 | + wordpress = require( "./wordpress" ), |
| 5 | + service = require( "./service" ); |
| 6 | + |
| 7 | +Step( |
| 8 | + function() { |
| 9 | + console.log( "The WordPress restore script is for restoring the WordPress site.\n" + |
| 10 | + "It will clear out the WordPress Database and restore the local repositories.\n" + |
| 11 | + "You must have an existing Plugins Database for this to be useful.\n" ); |
| 12 | + console.log( "Are you sure you want to continue? (y/n)" ); |
| 13 | + process.stdin.resume(); |
| 14 | + process.stdin.setEncoding( "utf8" ); |
| 15 | + process.stdin.on( "data", this ); |
| 16 | + }, |
| 17 | + |
| 18 | + function( response ) { |
| 19 | + process.stdin.destroy(); |
| 20 | + if ( response.trim().toLowerCase() !== "y" ) { |
| 21 | + console.log( "Aborting restore." ); |
| 22 | + process.exit(); |
| 23 | + } |
| 24 | + this(); |
| 25 | + }, |
| 26 | + |
| 27 | + function() { |
| 28 | + pluginsDb.getAllRepos( this.parallel() ); |
| 29 | + wordpress._reset( this.parallel() ); |
| 30 | + rimraf( "last-action", this.parallel() ); |
| 31 | + }, |
| 32 | + |
| 33 | + function( error, repos ) { |
| 34 | + if ( error ) { |
| 35 | + throw error; |
| 36 | + } |
| 37 | + |
| 38 | + var group = this.group(); |
| 39 | + repos.forEach(function( repo ) { |
| 40 | + service.getRepoById( repo ).restore( group() ); |
| 41 | + }); |
| 42 | + }, |
| 43 | + |
| 44 | + function( error ) { |
| 45 | + if ( error ) { |
| 46 | + console.log( "ERROR", "Restore failed." ); |
| 47 | + console.log( error.stack ); |
| 48 | + return; |
| 49 | + } |
| 50 | + |
| 51 | + console.log( "SUCCESS", "Restore complete." ); |
| 52 | + console.log( "Please run wp-update.js to start processing actions." ); |
| 53 | + } |
| 54 | +); |
0 commit comments