2015-11-21 09:27:06 +08:00
|
|
|
import Backup from "admin/models/backup";
|
|
|
|
import BackupStatus from "admin/models/backup-status";
|
2019-10-22 21:46:10 +08:00
|
|
|
import DiscourseRoute from "discourse/routes/discourse";
|
2019-10-30 03:23:50 +08:00
|
|
|
import EmberObject from "@ember/object";
|
2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2020-05-07 03:28:06 +08:00
|
|
|
import PreloadStore from "discourse/lib/preload-store";
|
2019-11-13 00:38:51 +08:00
|
|
|
import User from "discourse/models/user";
|
2016-07-01 01:55:44 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2020-08-27 00:57:13 +08:00
|
|
|
import bootbox from "bootbox";
|
2021-01-20 13:04:21 +08:00
|
|
|
import { extractError } from "discourse/lib/ajax-error";
|
2020-06-04 00:45:26 +08:00
|
|
|
import getURL from "discourse-common/lib/get-url";
|
2015-03-11 03:01:15 +08:00
|
|
|
import showModal from "discourse/lib/show-modal";
|
|
|
|
|
2015-03-13 00:12:23 +08:00
|
|
|
const LOG_CHANNEL = "/admin/backups/logs";
|
2014-02-13 12:35:46 +08:00
|
|
|
|
2019-10-22 21:46:10 +08:00
|
|
|
export default DiscourseRoute.extend({
|
2015-03-11 03:01:15 +08:00
|
|
|
activate() {
|
2018-01-31 19:05:06 +08:00
|
|
|
this.messageBus.subscribe(LOG_CHANNEL, (log) => {
|
|
|
|
if (log.message === "[STARTED]") {
|
2019-11-13 00:38:51 +08:00
|
|
|
User.currentProp("hideReadOnlyAlert", true);
|
2018-01-31 19:05:06 +08: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]") {
|
2019-11-13 00:38:51 +08:00
|
|
|
User.currentProp("hideReadOnlyAlert", false);
|
2018-01-31 19:05:06 +08:00
|
|
|
this.controllerFor("adminBackups").set(
|
|
|
|
"model.isOperationRunning",
|
|
|
|
false
|
|
|
|
);
|
|
|
|
if (log.operation === "restore") {
|
|
|
|
// redirect to homepage when the restore is done (session might be lost)
|
2020-06-04 00:45:26 +08:00
|
|
|
window.location = getURL("/");
|
2018-01-31 19:05:06 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.controllerFor("adminBackupsLogs")
|
|
|
|
.get("logs")
|
2019-10-30 03:23:50 +08:00
|
|
|
.pushObject(EmberObject.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
|
|
|
},
|
|
|
|
|
2015-03-11 03:01:15 +08:00
|
|
|
model() {
|
2019-01-24 00:40:24 +08:00
|
|
|
return PreloadStore.getAndRemove("operations_status", () =>
|
|
|
|
ajax("/admin/backups/status.json")
|
|
|
|
).then((status) =>
|
|
|
|
BackupStatus.create({
|
2014-02-13 12:35:46 +08:00
|
|
|
isOperationRunning: status.is_operation_running,
|
2014-08-29 05:02:26 +08:00
|
|
|
canRollback: status.can_rollback,
|
|
|
|
allowRestore: status.allow_restore,
|
2019-01-24 00:40:24 +08:00
|
|
|
})
|
|
|
|
);
|
2014-02-13 12:35:46 +08:00
|
|
|
},
|
|
|
|
|
2015-03-11 03:01:15 +08:00
|
|
|
deactivate() {
|
2015-03-13 00:12:23 +08:00
|
|
|
this.messageBus.unsubscribe(LOG_CHANNEL);
|
2014-02-13 12:35:46 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2018-09-20 02:00:03 +08:00
|
|
|
showStartBackupModal() {
|
2016-11-16 06:09:55 +08:00
|
|
|
showModal("admin-start-backup", { admin: true });
|
2014-08-21 00:48:56 +08:00
|
|
|
this.controllerFor("modal").set("modalClass", "start-backup-modal");
|
|
|
|
},
|
|
|
|
|
2018-09-20 02:00:03 +08:00
|
|
|
startBackup(withUploads) {
|
2014-08-21 00:48:56 +08:00
|
|
|
this.transitionTo("admin.backups.logs");
|
2021-01-20 13:04:21 +08:00
|
|
|
Backup.start(withUploads).then((result) => {
|
|
|
|
if (!result.success) {
|
|
|
|
bootbox.alert(result.message);
|
|
|
|
}
|
|
|
|
});
|
2014-02-13 12:35:46 +08:00
|
|
|
},
|
|
|
|
|
2015-03-11 03:01:15 +08:00
|
|
|
destroyBackup(backup) {
|
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"),
|
2019-01-24 00:40:24 +08:00
|
|
|
(confirmed) => {
|
2014-02-13 12:35:46 +08:00
|
|
|
if (confirmed) {
|
2019-01-24 00:40:24 +08:00
|
|
|
backup
|
|
|
|
.destroy()
|
|
|
|
.then(() =>
|
|
|
|
this.controllerFor("adminBackupsIndex")
|
2017-12-22 04:21:28 +08:00
|
|
|
.get("model")
|
2019-01-24 00:40:24 +08:00
|
|
|
.removeObject(backup)
|
|
|
|
);
|
2014-02-13 12:35:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-03-11 03:01:15 +08:00
|
|
|
startRestore(backup) {
|
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"),
|
2019-01-24 00:40:24 +08:00
|
|
|
(confirmed) => {
|
2014-02-13 12:35:46 +08:00
|
|
|
if (confirmed) {
|
2019-01-24 00:40:24 +08:00
|
|
|
this.transitionTo("admin.backups.logs");
|
2018-09-20 02:00:03 +08:00
|
|
|
backup.restore();
|
2014-02-13 12:35:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-03-11 03:01:15 +08:00
|
|
|
cancelOperation() {
|
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"),
|
2019-01-24 00:40:24 +08:00
|
|
|
(confirmed) => {
|
2014-02-13 12:35:46 +08:00
|
|
|
if (confirmed) {
|
2019-01-24 00:40:24 +08:00
|
|
|
Backup.cancel().then(() => {
|
|
|
|
this.controllerFor("adminBackups").set(
|
|
|
|
"model.isOperationRunning",
|
|
|
|
false
|
|
|
|
);
|
2014-02-13 12:35:46 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-03-11 03:01:15 +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"),
|
2019-01-24 00:40:24 +08:00
|
|
|
(confirmed) => {
|
2015-11-21 09:27:06 +08:00
|
|
|
if (confirmed) {
|
2021-01-20 13:04:21 +08:00
|
|
|
Backup.rollback().then((result) => {
|
|
|
|
if (!result.success) {
|
|
|
|
bootbox.alert(result.message);
|
|
|
|
} else {
|
|
|
|
// redirect to homepage (session might be lost)
|
|
|
|
window.location = getURL("/");
|
|
|
|
}
|
|
|
|
});
|
2015-11-21 09:27:06 +08:00
|
|
|
}
|
2014-02-13 12:35:46 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
2014-02-22 08:41:01 +08:00
|
|
|
|
2015-03-11 03:01:15 +08:00
|
|
|
uploadSuccess(filename) {
|
2019-01-24 00:40:24 +08:00
|
|
|
bootbox.alert(I18n.t("admin.backups.upload.success", { filename }));
|
2014-02-22 08:41:01 +08:00
|
|
|
},
|
|
|
|
|
2015-03-11 03:01:15 +08:00
|
|
|
uploadError(filename, message) {
|
2014-02-22 08:41:01 +08:00
|
|
|
bootbox.alert(
|
2019-01-24 00:40:24 +08:00
|
|
|
I18n.t("admin.backups.upload.error", { filename, message })
|
2014-02-22 08:41:01 +08:00
|
|
|
);
|
2018-10-15 09:43:31 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
remoteUploadSuccess() {
|
2021-01-20 13:04:21 +08:00
|
|
|
Backup.find()
|
|
|
|
.then((backups) => backups.map((backup) => Backup.create(backup)))
|
|
|
|
.then((backups) => {
|
|
|
|
this.controllerFor("adminBackupsIndex").set(
|
|
|
|
"model",
|
|
|
|
backups.map((backup) => Backup.create(backup))
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
bootbox.alert(
|
|
|
|
I18n.t("admin.backups.backup_storage_error", {
|
|
|
|
error_message: extractError(error),
|
|
|
|
})
|
|
|
|
);
|
|
|
|
return [];
|
|
|
|
});
|
2014-03-19 09:21:10 +08:00
|
|
|
},
|
2014-02-13 12:35:46 +08:00
|
|
|
},
|
|
|
|
});
|