discourse/app/assets/javascripts/admin/models/backup.js.es6

66 lines
1.5 KiB
Plaintext
Raw Normal View History

2018-06-15 11:03:24 -04:00
import { ajax } from "discourse/lib/ajax";
import PreloadStore from "preload-store";
2016-07-04 14:15:51 -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" });
},
restore() {
2016-06-30 13:55:44 -04:00
return ajax("/admin/backups/" + this.get("filename") + "/restore", {
type: "POST",
data: { client_id: window.MessageBus.clientId }
});
}
});
Backup.reopenClass({
find() {
2018-06-15 11:03:24 -04:00
return PreloadStore.getAndRemove("backups", () =>
ajax("/admin/backups.json")
).then(backups => backups.map(backup => Backup.create(backup)));
},
start(withUploads) {
2018-06-15 11:03:24 -04:00
if (withUploads === undefined) {
withUploads = true;
}
2016-06-30 13:55:44 -04:00
return ajax("/admin/backups", {
type: "POST",
data: {
with_uploads: withUploads,
client_id: window.MessageBus.clientId
}
}).then(result => {
2018-06-15 11:03:24 -04:00
if (!result.success) {
bootbox.alert(result.message);
}
});
},
cancel() {
return ajax("/admin/backups/cancel.json", {
2018-06-15 11:03:24 -04:00
type: "DELETE"
}).then(result => {
2018-06-15 11:03:24 -04:00
if (!result.success) {
bootbox.alert(result.message);
}
});
},
rollback() {
return ajax("/admin/backups/rollback.json", {
2018-06-15 11:03:24 -04:00
type: "POST"
}).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;