discourse/app/assets/javascripts/admin/addon/routes/admin-backups.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

164 lines
4.4 KiB
JavaScript
Raw Normal View History

import getURL from "discourse-common/lib/get-url";
import I18n from "I18n";
import EmberObject from "@ember/object";
import DiscourseRoute from "discourse/routes/discourse";
2016-06-30 13:55:44 -04:00
import { ajax } from "discourse/lib/ajax";
import showModal from "discourse/lib/show-modal";
import BackupStatus from "admin/models/backup-status";
import Backup from "admin/models/backup";
import PreloadStore from "discourse/lib/preload-store";
import User from "discourse/models/user";
import bootbox from "bootbox";
const LOG_CHANNEL = "/admin/backups/logs";
2014-02-12 23:35:46 -05:00
export default DiscourseRoute.extend({
activate() {
2018-01-31 06:05:06 -05:00
this.messageBus.subscribe(LOG_CHANNEL, (log) => {
if (log.message === "[STARTED]") {
User.currentProp("hideReadOnlyAlert", true);
2018-01-31 06:05:06 -05:00
this.controllerFor("adminBackups").set(
"model.isOperationRunning",
true
);
this.controllerFor("adminBackupsLogs").get("logs").clear();
} else if (log.message === "[FAILED]") {
this.controllerFor("adminBackups").set(
"model.isOperationRunning",
false
);
bootbox.alert(
I18n.t("admin.backups.operations.failed", {
operation: log.operation,
})
);
} else if (log.message === "[SUCCESS]") {
User.currentProp("hideReadOnlyAlert", false);
2018-01-31 06:05:06 -05:00
this.controllerFor("adminBackups").set(
"model.isOperationRunning",
false
);
if (log.operation === "restore") {
// redirect to homepage when the restore is done (session might be lost)
window.location = getURL("/");
2018-01-31 06:05:06 -05:00
}
} else {
this.controllerFor("adminBackupsLogs")
.get("logs")
.pushObject(EmberObject.create(log));
2014-02-12 23:35:46 -05:00
}
2018-01-31 06:05:06 -05:00
});
2014-02-12 23:35:46 -05:00
},
model() {
return PreloadStore.getAndRemove("operations_status", () =>
ajax("/admin/backups/status.json")
).then((status) =>
BackupStatus.create({
2014-02-12 23:35:46 -05:00
isOperationRunning: status.is_operation_running,
canRollback: status.can_rollback,
allowRestore: status.allow_restore,
})
);
2014-02-12 23:35:46 -05:00
},
deactivate() {
this.messageBus.unsubscribe(LOG_CHANNEL);
2014-02-12 23:35:46 -05:00
},
actions: {
showStartBackupModal() {
2016-11-15 17:09:55 -05:00
showModal("admin-start-backup", { admin: true });
2014-08-20 12:48:56 -04:00
this.controllerFor("modal").set("modalClass", "start-backup-modal");
},
startBackup(withUploads) {
2014-08-20 12:48:56 -04:00
this.transitionTo("admin.backups.logs");
Backup.start(withUploads);
2014-02-12 23:35:46 -05:00
},
destroyBackup(backup) {
2014-02-12 23:35:46 -05:00
bootbox.confirm(
I18n.t("admin.backups.operations.destroy.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
(confirmed) => {
2014-02-12 23:35:46 -05:00
if (confirmed) {
backup
.destroy()
.then(() =>
this.controllerFor("adminBackupsIndex")
.get("model")
.removeObject(backup)
);
2014-02-12 23:35:46 -05:00
}
}
);
},
startRestore(backup) {
2014-02-12 23:35:46 -05:00
bootbox.confirm(
I18n.t("admin.backups.operations.restore.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
(confirmed) => {
2014-02-12 23:35:46 -05:00
if (confirmed) {
this.transitionTo("admin.backups.logs");
backup.restore();
2014-02-12 23:35:46 -05:00
}
}
);
},
cancelOperation() {
2014-02-12 23:35:46 -05:00
bootbox.confirm(
I18n.t("admin.backups.operations.cancel.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
(confirmed) => {
2014-02-12 23:35:46 -05:00
if (confirmed) {
Backup.cancel().then(() => {
this.controllerFor("adminBackups").set(
"model.isOperationRunning",
false
);
2014-02-12 23:35:46 -05:00
});
}
}
);
},
rollback() {
2014-02-12 23:35:46 -05:00
bootbox.confirm(
I18n.t("admin.backups.operations.rollback.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
(confirmed) => {
if (confirmed) {
Backup.rollback();
}
2014-02-12 23:35:46 -05:00
}
);
},
2014-02-21 19:41:01 -05:00
uploadSuccess(filename) {
bootbox.alert(I18n.t("admin.backups.upload.success", { filename }));
2014-02-21 19:41:01 -05:00
},
uploadError(filename, message) {
2014-02-21 19:41:01 -05:00
bootbox.alert(
I18n.t("admin.backups.upload.error", { filename, message })
2014-02-21 19:41:01 -05:00
);
},
remoteUploadSuccess() {
Backup.find().then((backups) => {
this.controllerFor("adminBackupsIndex").set(
"model",
backups.map((backup) => Backup.create(backup))
);
});
},
2014-02-12 23:35:46 -05:00
},
});