2016-06-30 13:55:44 -04:00
|
|
|
import { ajax } from 'discourse/lib/ajax';
|
2015-08-27 14:02:13 -04:00
|
|
|
const Backup = Discourse.Model.extend({
|
|
|
|
|
|
|
|
destroy() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/backups/" + this.get("filename"), { type: "DELETE" });
|
2015-08-27 14:02:13 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
restore() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/backups/" + this.get("filename") + "/restore", {
|
2015-08-27 14:02:13 -04:00
|
|
|
type: "POST",
|
|
|
|
data: { client_id: window.MessageBus.clientId }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Backup.reopenClass({
|
|
|
|
|
|
|
|
find() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return PreloadStore.getAndRemove("backups", () => ajax("/admin/backups.json"))
|
2015-08-27 14:02:13 -04:00
|
|
|
.then(backups => backups.map(backup => Backup.create(backup)));
|
|
|
|
},
|
|
|
|
|
|
|
|
start(withUploads) {
|
|
|
|
if (withUploads === undefined) { withUploads = true; }
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/backups", {
|
2015-08-27 14:02:13 -04:00
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
with_uploads: withUploads,
|
|
|
|
client_id: window.MessageBus.clientId
|
|
|
|
}
|
|
|
|
}).then(result => {
|
|
|
|
if (!result.success) { bootbox.alert(result.message); }
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/backups/cancel.json")
|
2015-08-27 14:02:13 -04:00
|
|
|
.then(result => {
|
|
|
|
if (!result.success) { bootbox.alert(result.message); }
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
rollback() {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax("/admin/backups/rollback.json")
|
2015-08-27 14:02:13 -04:00
|
|
|
.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;
|