2018-06-15 11:03:24 -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 "preload-store";
|
2015-03-10 15:01:15 -04:00
|
|
|
|
2015-03-12 12:12:23 -04:00
|
|
|
const LOG_CHANNEL = "/admin/backups/logs";
|
2014-02-12 23:35:46 -05:00
|
|
|
|
2015-03-12 12:12:23 -04:00
|
|
|
export default Discourse.Route.extend({
|
2015-03-10 15:01:15 -04:00
|
|
|
activate() {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.messageBus.subscribe(LOG_CHANNEL, log => {
|
2018-01-31 06:05:06 -05:00
|
|
|
if (log.message === "[STARTED]") {
|
2018-09-19 14:00:03 -04:00
|
|
|
Discourse.User.currentProp("hideReadOnlyAlert", true);
|
2018-06-15 11:03:24 -04:00
|
|
|
this.controllerFor("adminBackups").set(
|
|
|
|
"model.isOperationRunning",
|
|
|
|
true
|
|
|
|
);
|
|
|
|
this.controllerFor("adminBackupsLogs")
|
|
|
|
.get("logs")
|
|
|
|
.clear();
|
2018-01-31 06:05:06 -05:00
|
|
|
} else if (log.message === "[FAILED]") {
|
2018-06-15 11:03:24 -04:00
|
|
|
this.controllerFor("adminBackups").set(
|
|
|
|
"model.isOperationRunning",
|
|
|
|
false
|
|
|
|
);
|
|
|
|
bootbox.alert(
|
|
|
|
I18n.t("admin.backups.operations.failed", {
|
|
|
|
operation: log.operation
|
|
|
|
})
|
|
|
|
);
|
2018-01-31 06:05:06 -05:00
|
|
|
} else if (log.message === "[SUCCESS]") {
|
|
|
|
Discourse.User.currentProp("hideReadOnlyAlert", false);
|
2018-06-15 11:03:24 -04:00
|
|
|
this.controllerFor("adminBackups").set(
|
|
|
|
"model.isOperationRunning",
|
|
|
|
false
|
|
|
|
);
|
2018-01-31 06:05:06 -05: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 11:03:24 -04:00
|
|
|
this.controllerFor("adminBackupsLogs")
|
|
|
|
.get("logs")
|
2019-01-11 11:54:23 -05:00
|
|
|
.pushObject(Ember.Object.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
|
|
|
},
|
|
|
|
|
2015-03-10 15:01:15 -04:00
|
|
|
model() {
|
2019-01-23 11:40:24 -05:00
|
|
|
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,
|
2014-08-28 17:02:26 -04:00
|
|
|
canRollback: status.can_rollback,
|
|
|
|
allowRestore: status.allow_restore
|
2019-01-23 11:40:24 -05:00
|
|
|
})
|
|
|
|
);
|
2014-02-12 23:35:46 -05:00
|
|
|
},
|
|
|
|
|
2015-03-10 15:01:15 -04:00
|
|
|
deactivate() {
|
2015-03-12 12:12:23 -04:00
|
|
|
this.messageBus.unsubscribe(LOG_CHANNEL);
|
2014-02-12 23:35:46 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
2018-09-19 14:00:03 -04:00
|
|
|
showStartBackupModal() {
|
2018-06-15 11:03:24 -04:00
|
|
|
showModal("admin-start-backup", { admin: true });
|
|
|
|
this.controllerFor("modal").set("modalClass", "start-backup-modal");
|
2014-08-20 12:48:56 -04:00
|
|
|
},
|
|
|
|
|
2018-09-19 14:00:03 -04:00
|
|
|
startBackup(withUploads) {
|
2014-08-20 12:48:56 -04:00
|
|
|
this.transitionTo("admin.backups.logs");
|
2018-09-19 14:00:03 -04:00
|
|
|
Backup.start(withUploads);
|
2014-02-12 23:35:46 -05:00
|
|
|
},
|
|
|
|
|
2015-03-10 15:01:15 -04: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"),
|
2019-01-23 11:40:24 -05:00
|
|
|
confirmed => {
|
2014-02-12 23:35:46 -05:00
|
|
|
if (confirmed) {
|
2019-01-23 11:40:24 -05:00
|
|
|
backup.destroy().then(() =>
|
|
|
|
this.controllerFor("adminBackupsIndex")
|
2018-06-15 11:03:24 -04:00
|
|
|
.get("model")
|
2019-01-23 11:40:24 -05:00
|
|
|
.removeObject(backup)
|
|
|
|
);
|
2014-02-12 23:35:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-03-10 15:01:15 -04: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"),
|
2019-01-23 11:40:24 -05:00
|
|
|
confirmed => {
|
2014-02-12 23:35:46 -05:00
|
|
|
if (confirmed) {
|
2019-01-23 11:40:24 -05:00
|
|
|
this.transitionTo("admin.backups.logs");
|
2018-09-19 14:00:03 -04:00
|
|
|
backup.restore();
|
2014-02-12 23:35:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-03-10 15:01:15 -04: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"),
|
2019-01-23 11:40:24 -05:00
|
|
|
confirmed => {
|
2014-02-12 23:35:46 -05:00
|
|
|
if (confirmed) {
|
2019-01-23 11:40:24 -05:00
|
|
|
Backup.cancel().then(() => {
|
|
|
|
this.controllerFor("adminBackups").set(
|
|
|
|
"model.isOperationRunning",
|
|
|
|
false
|
|
|
|
);
|
2014-02-12 23:35:46 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2015-03-10 15:01:15 -04: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"),
|
2019-01-23 11:40:24 -05:00
|
|
|
confirmed => {
|
2018-06-15 11:03:24 -04:00
|
|
|
if (confirmed) {
|
|
|
|
Backup.rollback();
|
|
|
|
}
|
2014-02-12 23:35:46 -05:00
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
2014-02-21 19:41:01 -05:00
|
|
|
|
2015-03-10 15:01:15 -04:00
|
|
|
uploadSuccess(filename) {
|
2019-01-23 11:40:24 -05:00
|
|
|
bootbox.alert(I18n.t("admin.backups.upload.success", { filename }));
|
2014-02-21 19:41:01 -05:00
|
|
|
},
|
|
|
|
|
2015-03-10 15:01:15 -04:00
|
|
|
uploadError(filename, message) {
|
2018-06-15 11:03:24 -04:00
|
|
|
bootbox.alert(
|
2019-01-23 11:40:24 -05:00
|
|
|
I18n.t("admin.backups.upload.error", { filename, message })
|
2018-06-15 11:03:24 -04:00
|
|
|
);
|
2018-10-14 21:43:31 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
remoteUploadSuccess() {
|
|
|
|
Backup.find().then(backups => {
|
|
|
|
this.controllerFor("adminBackupsIndex").set(
|
|
|
|
"model",
|
|
|
|
backups.map(backup => Backup.create(backup))
|
|
|
|
);
|
|
|
|
});
|
2014-03-18 21:21:10 -04:00
|
|
|
}
|
2014-02-12 23:35:46 -05:00
|
|
|
}
|
|
|
|
});
|