mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: don't break the message bus when restoring a backup
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
/**
|
||||
Data model for representing a backup
|
||||
|
||||
@class Backup
|
||||
@extends Discourse.Model
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.Backup = Discourse.Model.extend({
|
||||
|
||||
/**
|
||||
Destroys the current backup
|
||||
|
||||
@method destroy
|
||||
@returns {Promise} a promise that resolves when the backup has been destroyed
|
||||
**/
|
||||
destroy: function() {
|
||||
return Discourse.ajax("/admin/backups/" + this.get("filename"), { type: "DELETE" });
|
||||
},
|
||||
|
||||
/**
|
||||
Starts the restoration of the current backup
|
||||
|
||||
@method restore
|
||||
@returns {Promise} a promise that resolves when the backup has started being restored
|
||||
**/
|
||||
restore: function() {
|
||||
return Discourse.ajax("/admin/backups/" + this.get("filename") + "/restore", { type: "POST" });
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Discourse.Backup.reopenClass({
|
||||
|
||||
/**
|
||||
Finds a list of backups
|
||||
|
||||
@method find
|
||||
@returns {Promise} a promise that resolves to the array of {Discourse.Backup} backup
|
||||
**/
|
||||
find: function() {
|
||||
return PreloadStore.getAndRemove("backups", function() {
|
||||
return Discourse.ajax("/admin/backups.json");
|
||||
}).then(function(backups) {
|
||||
return backups.map(function (backup) { return Discourse.Backup.create(backup); });
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
Starts a backup
|
||||
|
||||
@method start
|
||||
@returns {Promise} a promise that resolves when the backup has started
|
||||
**/
|
||||
start: function (withUploads) {
|
||||
if (withUploads === undefined) { withUploads = true; }
|
||||
return Discourse.ajax("/admin/backups", { type: "POST", data: { with_uploads: withUploads } }).then(function(result) {
|
||||
if (!result.success) { bootbox.alert(result.message); }
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
Cancels a backup
|
||||
|
||||
@method cancel
|
||||
@returns {Promise} a promise that resolves when the backup has been cancelled
|
||||
**/
|
||||
cancel: function() {
|
||||
return Discourse.ajax("/admin/backups/cancel.json").then(function(result) {
|
||||
if (!result.success) { bootbox.alert(result.message); }
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
Rollbacks the database to the previous working state
|
||||
|
||||
@method rollback
|
||||
@returns {Promise} a promise that resolves when the rollback is done
|
||||
**/
|
||||
rollback: function() {
|
||||
return Discourse.ajax("/admin/backups/rollback.json").then(function(result) {
|
||||
if (!result.success) {
|
||||
bootbox.alert(result.message);
|
||||
} else {
|
||||
// redirect to homepage (session might be lost)
|
||||
window.location.pathname = Discourse.getURL("/");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
56
app/assets/javascripts/admin/models/backup.js.es6
Normal file
56
app/assets/javascripts/admin/models/backup.js.es6
Normal file
@@ -0,0 +1,56 @@
|
||||
const Backup = Discourse.Model.extend({
|
||||
|
||||
destroy() {
|
||||
return Discourse.ajax("/admin/backups/" + this.get("filename"), { type: "DELETE" });
|
||||
},
|
||||
|
||||
restore() {
|
||||
return Discourse.ajax("/admin/backups/" + this.get("filename") + "/restore", {
|
||||
type: "POST",
|
||||
data: { client_id: window.MessageBus.clientId }
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Backup.reopenClass({
|
||||
|
||||
find() {
|
||||
return PreloadStore.getAndRemove("backups", () => Discourse.ajax("/admin/backups.json"))
|
||||
.then(backups => backups.map(backup => Backup.create(backup)));
|
||||
},
|
||||
|
||||
start(withUploads) {
|
||||
if (withUploads === undefined) { withUploads = true; }
|
||||
return Discourse.ajax("/admin/backups", {
|
||||
type: "POST",
|
||||
data: {
|
||||
with_uploads: withUploads,
|
||||
client_id: window.MessageBus.clientId
|
||||
}
|
||||
}).then(result => {
|
||||
if (!result.success) { bootbox.alert(result.message); }
|
||||
});
|
||||
},
|
||||
|
||||
cancel() {
|
||||
return Discourse.ajax("/admin/backups/cancel.json")
|
||||
.then(result => {
|
||||
if (!result.success) { bootbox.alert(result.message); }
|
||||
});
|
||||
},
|
||||
|
||||
rollback() {
|
||||
return Discourse.ajax("/admin/backups/rollback.json")
|
||||
.then(result => {
|
||||
if (!result.success) {
|
||||
bootbox.alert(result.message);
|
||||
} else {
|
||||
// redirect to homepage (session might be lost)
|
||||
window.location.pathname = Discourse.getURL("/");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export default Backup;
|
||||
Reference in New Issue
Block a user