2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
2018-06-15 11:03:24 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2019-02-20 09:15:38 -05:00
|
|
|
import { extractError } from "discourse/lib/ajax-error";
|
2019-11-08 14:13:35 -05:00
|
|
|
import EmberObject from "@ember/object";
|
2016-07-04 14:15:51 -04:00
|
|
|
|
2019-11-08 14:13:35 -05:00
|
|
|
const Backup = EmberObject.extend({
|
2015-08-27 14:02:13 -04:00
|
|
|
destroy() {
|
2019-05-27 04:15:39 -04:00
|
|
|
return ajax("/admin/backups/" + this.filename, { type: "DELETE" });
|
2015-08-27 14:02:13 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
restore() {
|
2019-05-27 04:15:39 -04:00
|
|
|
return ajax("/admin/backups/" + this.filename + "/restore", {
|
2015-08-27 14:02:13 -04:00
|
|
|
type: "POST",
|
|
|
|
data: { client_id: window.MessageBus.clientId }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Backup.reopenClass({
|
|
|
|
find() {
|
2019-02-20 09:15:38 -05:00
|
|
|
return ajax("/admin/backups.json")
|
|
|
|
.then(backups => backups.map(backup => Backup.create(backup)))
|
|
|
|
.catch(error => {
|
|
|
|
bootbox.alert(
|
|
|
|
I18n.t("admin.backups.backup_storage_error", {
|
|
|
|
error_message: extractError(error)
|
|
|
|
})
|
|
|
|
);
|
|
|
|
return [];
|
|
|
|
});
|
2015-08-27 14:02:13 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
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", {
|
2015-08-27 14:02:13 -04:00
|
|
|
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);
|
|
|
|
}
|
2015-08-27 14:02:13 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
cancel() {
|
2017-03-22 22:29:35 -04:00
|
|
|
return ajax("/admin/backups/cancel.json", {
|
2018-06-15 11:03:24 -04:00
|
|
|
type: "DELETE"
|
2017-03-22 22:29:35 -04:00
|
|
|
}).then(result => {
|
2018-06-15 11:03:24 -04:00
|
|
|
if (!result.success) {
|
|
|
|
bootbox.alert(result.message);
|
|
|
|
}
|
2017-03-22 22:29:35 -04:00
|
|
|
});
|
2015-08-27 14:02:13 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
rollback() {
|
2017-03-22 22:29:35 -04:00
|
|
|
return ajax("/admin/backups/rollback.json", {
|
2018-06-15 11:03:24 -04:00
|
|
|
type: "POST"
|
2017-03-22 22:29:35 -04:00
|
|
|
}).then(result => {
|
2015-08-27 14:02:13 -04:00
|
|
|
if (!result.success) {
|
|
|
|
bootbox.alert(result.message);
|
|
|
|
} else {
|
|
|
|
// redirect to homepage (session might be lost)
|
2019-09-16 08:27:12 -04:00
|
|
|
window.location = Discourse.getURL("/");
|
2015-08-27 14:02:13 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default Backup;
|