2018-06-15 23:03:24 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2016-07-05 02:15:51 +08:00
|
|
|
|
2015-08-28 02:02:13 +08:00
|
|
|
const Backup = Discourse.Model.extend({
|
|
|
|
destroy() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/backups/" + this.get("filename"), { type: "DELETE" });
|
2015-08-28 02:02:13 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
restore() {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/backups/" + this.get("filename") + "/restore", {
|
2015-08-28 02:02:13 +08:00
|
|
|
type: "POST",
|
|
|
|
data: { client_id: window.MessageBus.clientId }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Backup.reopenClass({
|
|
|
|
find() {
|
2018-10-15 09:43:31 +08:00
|
|
|
return ajax("/admin/backups.json").then(backups =>
|
|
|
|
backups.map(backup => Backup.create(backup))
|
|
|
|
);
|
2015-08-28 02:02:13 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
start(withUploads) {
|
2018-06-15 23:03:24 +08:00
|
|
|
if (withUploads === undefined) {
|
|
|
|
withUploads = true;
|
|
|
|
}
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/backups", {
|
2015-08-28 02:02:13 +08:00
|
|
|
type: "POST",
|
|
|
|
data: {
|
|
|
|
with_uploads: withUploads,
|
|
|
|
client_id: window.MessageBus.clientId
|
|
|
|
}
|
|
|
|
}).then(result => {
|
2018-06-15 23:03:24 +08:00
|
|
|
if (!result.success) {
|
|
|
|
bootbox.alert(result.message);
|
|
|
|
}
|
2015-08-28 02:02:13 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel() {
|
2017-03-23 10:29:35 +08:00
|
|
|
return ajax("/admin/backups/cancel.json", {
|
2018-06-15 23:03:24 +08:00
|
|
|
type: "DELETE"
|
2017-03-23 10:29:35 +08:00
|
|
|
}).then(result => {
|
2018-06-15 23:03:24 +08:00
|
|
|
if (!result.success) {
|
|
|
|
bootbox.alert(result.message);
|
|
|
|
}
|
2017-03-23 10:29:35 +08:00
|
|
|
});
|
2015-08-28 02:02:13 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
rollback() {
|
2017-03-23 10:29:35 +08:00
|
|
|
return ajax("/admin/backups/rollback.json", {
|
2018-06-15 23:03:24 +08:00
|
|
|
type: "POST"
|
2017-03-23 10:29:35 +08:00
|
|
|
}).then(result => {
|
2015-08-28 02:02:13 +08:00
|
|
|
if (!result.success) {
|
|
|
|
bootbox.alert(result.message);
|
|
|
|
} else {
|
|
|
|
// redirect to homepage (session might be lost)
|
|
|
|
window.location.pathname = Discourse.getURL("/");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default Backup;
|