2020-05-13 16:23:41 -04:00
|
|
|
import I18n from "I18n";
|
2019-10-30 16:28:29 -04:00
|
|
|
import { alias, equal } from "@ember/object/computed";
|
2020-03-06 11:41:41 -05:00
|
|
|
import Controller, { inject as controller } from "@ember/controller";
|
2016-06-30 13:55:44 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2020-01-16 12:56:53 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-01-23 11:40:24 -05:00
|
|
|
import { setting, i18n } from "discourse/lib/computed";
|
2020-08-26 12:57:13 -04:00
|
|
|
import bootbox from "bootbox";
|
2016-10-20 13:26:41 -04:00
|
|
|
|
2019-10-23 13:06:54 -04:00
|
|
|
export default Controller.extend({
|
2020-03-06 11:41:41 -05:00
|
|
|
adminBackups: controller(),
|
2019-10-30 16:28:29 -04:00
|
|
|
status: alias("adminBackups.model"),
|
2019-01-23 11:40:24 -05:00
|
|
|
uploadLabel: i18n("admin.backups.upload.label"),
|
|
|
|
backupLocation: setting("backup_location"),
|
2019-10-30 16:28:29 -04:00
|
|
|
localBackupStorage: equal("backupLocation", "local"),
|
2014-02-12 23:35:46 -05:00
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("status.allowRestore", "status.isOperationRunning")
|
2019-01-23 11:40:24 -05:00
|
|
|
restoreTitle(allowRestore, isOperationRunning) {
|
|
|
|
if (!allowRestore) {
|
2015-03-26 13:05:27 -04:00
|
|
|
return "admin.backups.operations.restore.is_disabled";
|
2019-01-23 11:40:24 -05:00
|
|
|
} else if (isOperationRunning) {
|
2015-03-26 13:05:27 -04:00
|
|
|
return "admin.backups.operations.is_running";
|
2014-02-12 23:35:46 -05:00
|
|
|
} else {
|
2015-03-26 13:05:27 -04:00
|
|
|
return "admin.backups.operations.restore.title";
|
2014-02-12 23:35:46 -05:00
|
|
|
}
|
2019-01-23 11:40:24 -05:00
|
|
|
},
|
2014-02-12 23:35:46 -05:00
|
|
|
|
|
|
|
actions: {
|
2015-03-26 13:05:27 -04:00
|
|
|
toggleReadOnlyMode() {
|
2014-09-11 15:25:30 -04:00
|
|
|
if (!this.site.get("isReadOnly")) {
|
2014-02-12 23:35:46 -05:00
|
|
|
bootbox.confirm(
|
|
|
|
I18n.t("admin.backups.read_only.enable.confirm"),
|
|
|
|
I18n.t("no_value"),
|
|
|
|
I18n.t("yes_value"),
|
2019-01-23 11:40:24 -05:00
|
|
|
(confirmed) => {
|
2014-02-13 10:56:23 -05:00
|
|
|
if (confirmed) {
|
2019-07-26 05:20:11 -04:00
|
|
|
this.set("currentUser.hideReadOnlyAlert", true);
|
2019-01-23 11:40:24 -05:00
|
|
|
this._toggleReadOnlyMode(true);
|
2014-02-13 10:56:23 -05:00
|
|
|
}
|
2014-02-12 23:35:46 -05:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this._toggleReadOnlyMode(false);
|
|
|
|
}
|
2016-11-11 16:31:08 -05:00
|
|
|
},
|
2014-02-12 23:35:46 -05:00
|
|
|
|
2016-11-11 16:31:08 -05:00
|
|
|
download(backup) {
|
2019-01-23 11:40:24 -05:00
|
|
|
const link = backup.get("filename");
|
|
|
|
ajax(`/admin/backups/${link}`, { type: "PUT" }).then(() =>
|
|
|
|
bootbox.alert(I18n.t("admin.backups.operations.download.alert"))
|
|
|
|
);
|
2016-11-11 16:31:08 -05:00
|
|
|
},
|
2014-02-12 23:35:46 -05:00
|
|
|
},
|
|
|
|
|
2015-03-26 13:05:27 -04:00
|
|
|
_toggleReadOnlyMode(enable) {
|
2016-06-30 13:55:44 -04:00
|
|
|
ajax("/admin/backups/readonly", {
|
2014-02-12 23:35:46 -05:00
|
|
|
type: "PUT",
|
2019-01-23 11:40:24 -05:00
|
|
|
data: { enable },
|
|
|
|
}).then(() => this.site.set("isReadOnly", enable));
|
2014-03-18 21:21:10 -04:00
|
|
|
},
|
2014-02-12 23:35:46 -05:00
|
|
|
});
|