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

166 lines
4.4 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08: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 "preload-store";
const LOG_CHANNEL = "/admin/backups/logs";
2014-02-13 12:35:46 +08:00
export default Discourse.Route.extend({
activate() {
2018-06-15 23:03:24 +08:00
this.messageBus.subscribe(LOG_CHANNEL, log => {
2018-01-31 19:05:06 +08:00
if (log.message === "[STARTED]") {
Discourse.User.currentProp("hideReadOnlyAlert", true);
2018-06-15 23:03:24 +08:00
this.controllerFor("adminBackups").set(
"model.isOperationRunning",
true
);
this.controllerFor("adminBackupsLogs")
.get("logs")
.clear();
2018-01-31 19:05:06 +08:00
} else if (log.message === "[FAILED]") {
2018-06-15 23:03:24 +08:00
this.controllerFor("adminBackups").set(
"model.isOperationRunning",
false
);
bootbox.alert(
I18n.t("admin.backups.operations.failed", {
operation: log.operation
})
);
2018-01-31 19:05:06 +08:00
} else if (log.message === "[SUCCESS]") {
Discourse.User.currentProp("hideReadOnlyAlert", false);
2018-06-15 23:03:24 +08:00
this.controllerFor("adminBackups").set(
"model.isOperationRunning",
false
);
2018-01-31 19:05:06 +08:00
if (log.operation === "restore") {
// redirect to homepage when the restore is done (session might be lost)
window.location.pathname = Discourse.getURL("/");
}
} else {
2018-06-15 23:03:24 +08:00
this.controllerFor("adminBackupsLogs")
.get("logs")
.pushObject(Em.Object.create(log));
2014-02-13 12:35:46 +08:00
}
2018-01-31 19:05:06 +08:00
});
2014-02-13 12:35:46 +08:00
},
model() {
2014-02-13 12:35:46 +08:00
return PreloadStore.getAndRemove("operations_status", function() {
2016-07-01 01:55:44 +08:00
return ajax("/admin/backups/status.json");
}).then(status => {
return BackupStatus.create({
2014-02-13 12:35:46 +08:00
isOperationRunning: status.is_operation_running,
canRollback: status.can_rollback,
allowRestore: status.allow_restore
2014-02-13 12:35:46 +08:00
});
});
},
deactivate() {
this.messageBus.unsubscribe(LOG_CHANNEL);
2014-02-13 12:35:46 +08:00
},
actions: {
showStartBackupModal() {
2018-06-15 23:03:24 +08:00
showModal("admin-start-backup", { admin: true });
this.controllerFor("modal").set("modalClass", "start-backup-modal");
2014-08-21 00:48:56 +08:00
},
startBackup(withUploads) {
2014-08-21 00:48:56 +08:00
this.transitionTo("admin.backups.logs");
Backup.start(withUploads);
2014-02-13 12:35:46 +08:00
},
destroyBackup(backup) {
const self = this;
2014-02-13 12:35:46 +08:00
bootbox.confirm(
I18n.t("admin.backups.operations.destroy.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
function(confirmed) {
if (confirmed) {
backup.destroy().then(function() {
2018-06-15 23:03:24 +08:00
self
.controllerFor("adminBackupsIndex")
.get("model")
.removeObject(backup);
2014-02-13 12:35:46 +08:00
});
}
}
);
},
startRestore(backup) {
const self = this;
2014-02-13 12:35:46 +08:00
bootbox.confirm(
I18n.t("admin.backups.operations.restore.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
function(confirmed) {
if (confirmed) {
self.transitionTo("admin.backups.logs");
backup.restore();
2014-02-13 12:35:46 +08:00
}
}
);
},
cancelOperation() {
const self = this;
2014-02-13 12:35:46 +08:00
bootbox.confirm(
I18n.t("admin.backups.operations.cancel.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
function(confirmed) {
if (confirmed) {
Backup.cancel().then(function() {
2018-06-15 23:03:24 +08:00
self
.controllerFor("adminBackups")
.set("model.isOperationRunning", false);
2014-02-13 12:35:46 +08:00
});
}
}
);
},
rollback() {
2014-02-13 12:35:46 +08:00
bootbox.confirm(
I18n.t("admin.backups.operations.rollback.confirm"),
I18n.t("no_value"),
I18n.t("yes_value"),
function(confirmed) {
2018-06-15 23:03:24 +08:00
if (confirmed) {
Backup.rollback();
}
2014-02-13 12:35:46 +08:00
}
);
},
2014-02-22 08:41:01 +08:00
uploadSuccess(filename) {
2018-06-15 23:03:24 +08:00
bootbox.alert(
I18n.t("admin.backups.upload.success", { filename: filename })
);
2014-02-22 08:41:01 +08:00
},
uploadError(filename, message) {
2018-06-15 23:03:24 +08:00
bootbox.alert(
I18n.t("admin.backups.upload.error", {
filename: filename,
message: message
})
);
},
remoteUploadSuccess() {
Backup.find().then(backups => {
this.controllerFor("adminBackupsIndex").set(
"model",
backups.map(backup => Backup.create(backup))
);
});
}
2014-02-13 12:35:46 +08:00
}
});