mirror of https://github.com/halo-dev/halo
🎨 新增自动备份的开关
parent
81c2cf01bb
commit
6b4a89e38e
|
@ -3,6 +3,7 @@ package cc.ryanc.halo.config;
|
|||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.dto.Theme;
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.model.enums.TrueFalseEnum;
|
||||
import cc.ryanc.halo.service.OptionsService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
|
@ -47,9 +48,7 @@ public class StartupConfig implements ApplicationListener<ApplicationStartedEven
|
|||
this.loadOptions();
|
||||
this.loadThemes();
|
||||
this.loadOwo();
|
||||
//启动定时任务
|
||||
CronUtil.start();
|
||||
log.info("The scheduled task starts successfully!");
|
||||
this.autoBackup();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,6 +86,18 @@ public class StartupConfig implements ApplicationListener<ApplicationStartedEven
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动定时备份
|
||||
*/
|
||||
private void autoBackup() {
|
||||
String autoBackup = optionsService.findOneOption(BlogPropertiesEnum.AUTO_BACKUP.getProp());
|
||||
if (StrUtil.isNotEmpty(autoBackup) && StrUtil.equals(autoBackup, TrueFalseEnum.TRUE.getDesc())) {
|
||||
//启动定时任务
|
||||
CronUtil.start();
|
||||
log.info("The scheduled task starts successfully!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载OwO表情
|
||||
*/
|
||||
|
|
|
@ -143,7 +143,12 @@ public enum BlogPropertiesEnum {
|
|||
/**
|
||||
* 默认缩略图地址
|
||||
*/
|
||||
DEFAULT_THUMBNAIL("/static/images/thumbnail/thumbnail.png");
|
||||
DEFAULT_THUMBNAIL("/static/images/thumbnail/thumbnail.png"),
|
||||
|
||||
/**
|
||||
* 自动备份
|
||||
*/
|
||||
AUTO_BACKUP("auto_backup");
|
||||
|
||||
private String prop;
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import cc.ryanc.halo.model.dto.HaloConst;
|
|||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.*;
|
||||
import cc.ryanc.halo.service.MailService;
|
||||
import cc.ryanc.halo.service.OptionsService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||
|
@ -14,15 +15,15 @@ import cn.hutool.core.date.DateUtil;
|
|||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import cn.hutool.cron.CronUtil;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.TemplateModelException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.File;
|
||||
|
@ -53,6 +54,11 @@ public class BackupController {
|
|||
@Autowired
|
||||
private LocaleMessageUtil localeMessageUtil;
|
||||
|
||||
@Autowired
|
||||
private OptionsService optionsService;
|
||||
|
||||
@Autowired
|
||||
private Configuration configuration;
|
||||
|
||||
/**
|
||||
* 渲染备份页面
|
||||
|
@ -191,6 +197,33 @@ public class BackupController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份设置
|
||||
*
|
||||
* @param autoBackup autoBackup
|
||||
* @return 重定向到/admin/backup
|
||||
*/
|
||||
@PostMapping(value = "backupOption")
|
||||
public String backupOption(@RequestParam("auto_backup") String autoBackup) throws TemplateModelException {
|
||||
if (StrUtil.equals(autoBackup, TrueFalseEnum.TRUE.getDesc())) {
|
||||
if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.AUTO_BACKUP.getProp()), TrueFalseEnum.FALSE.getDesc())) {
|
||||
optionsService.saveOption("auto_backup", TrueFalseEnum.TRUE.getDesc());
|
||||
CronUtil.start();
|
||||
log.info("The scheduled task starts successfully!");
|
||||
}
|
||||
} else {
|
||||
if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.AUTO_BACKUP.getProp()), TrueFalseEnum.TRUE.getDesc())) {
|
||||
optionsService.saveOption("auto_backup", TrueFalseEnum.FALSE.getDesc());
|
||||
CronUtil.stop();
|
||||
log.info("The scheduled task stops successfully!");
|
||||
}
|
||||
}
|
||||
configuration.setSharedVariable("options", optionsService.findAllOptions());
|
||||
HaloConst.OPTIONS.clear();
|
||||
HaloConst.OPTIONS = optionsService.findAllOptions();
|
||||
return "redirect:/admin/backup";
|
||||
}
|
||||
|
||||
/**
|
||||
* 将备份发送到邮箱
|
||||
*
|
||||
|
|
|
@ -121,6 +121,8 @@ admin.backup.btn.download = 下载
|
|||
admin.backup.btn.send-to-email = 发送到邮箱
|
||||
admin.backup.btn.delete = 删除
|
||||
admin.backup.btn.backup = 备份
|
||||
admin.backup.text.setting = 备份设置
|
||||
admin.backup.form.auto-backup = 自动备份:
|
||||
|
||||
# 分类管理页面
|
||||
admin.categories.title = 分类目录
|
||||
|
|
|
@ -121,6 +121,8 @@ admin.backup.btn.download = Download
|
|||
admin.backup.btn.send-to-email = Send to Email
|
||||
admin.backup.btn.delete = Delete
|
||||
admin.backup.btn.backup = Backup
|
||||
admin.backup.text.setting = Backup Setting
|
||||
admin.backup.form.auto-backup = Auto Backup:
|
||||
|
||||
# categories page
|
||||
admin.categories.title = Categories
|
||||
|
|
|
@ -121,6 +121,8 @@ admin.backup.btn.download = 下载
|
|||
admin.backup.btn.send-to-email = 发送到邮箱
|
||||
admin.backup.btn.delete = 删除
|
||||
admin.backup.btn.backup = 备份
|
||||
admin.backup.text.setting = 备份设置
|
||||
admin.backup.form.auto-backup = 自动备份:
|
||||
|
||||
# 分类管理页面
|
||||
admin.categories.title = 分类目录
|
||||
|
|
|
@ -8,10 +8,21 @@
|
|||
<#include "module/_sidebar.ftl">
|
||||
<div class="content-wrapper">
|
||||
<style type="text/css" rel="stylesheet">
|
||||
#btnBackupOption{margin-left:4px;padding:3px 6px;position:relative;top:-4px;border:1px solid #ccc;border-radius:2px;background:#fff;text-shadow:none;font-weight:600;font-size:12px;line-height:normal;color:#3c8dbc;cursor:pointer;transition:all .2s ease-in-out}
|
||||
#btnBackupOption:hover{background:#3c8dbc;color:#fff}
|
||||
.resourceType,.databaseType,.postType{list-style:none;float:left;margin:0;padding-bottom:10px}
|
||||
.form-horizontal .control-label{
|
||||
text-align: left;
|
||||
}
|
||||
.control-radio{
|
||||
padding-top: 7px;
|
||||
}
|
||||
</style>
|
||||
<section class="content-header">
|
||||
<h1 style="display: inline-block;"><@spring.message code='admin.backup.title' /></h1>
|
||||
<a id="btnBackupOption" href="#">
|
||||
<@spring.message code='admin.backup.text.setting' />
|
||||
</a>
|
||||
<ol class="breadcrumb">
|
||||
<li>
|
||||
<a href="/admin"><i class="fa fa-dashboard"></i> <@spring.message code='admin.index.bread.index' /></a>
|
||||
|
@ -22,6 +33,39 @@
|
|||
</section>
|
||||
<section class="content container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-xs-12" id="backupOptionsPanel" style="display: none">
|
||||
<div class="box box-primary">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title"><@spring.message code='admin.backup.text.setting' /></h3>
|
||||
</div>
|
||||
<form class="form-horizontal" id="backupOption" method="post" action="/admin/backup/backupOption">
|
||||
<div class="box-body">
|
||||
<div class="col-sm-6 col-xs-6">
|
||||
<div class="form-group">
|
||||
<label for="autoBackup" class="col-sm-4 control-label"><@spring.message code='admin.backup.form.auto-backup' /></label>
|
||||
<div class="col-sm-8 control-radio">
|
||||
<div class="pretty p-default p-round">
|
||||
<input type="radio" name="auto_backup" id="autoBackup" value="true" ${((options.auto_backup?if_exists)=='true')?string('checked','')}>
|
||||
<div class="state p-primary">
|
||||
<label><@spring.message code='common.radio.enable' /></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pretty p-default p-round">
|
||||
<input type="radio" name="auto_backup" id="autoBackup" value="false" ${((options.auto_backup?default('false'))=='false')?string('checked','')}>
|
||||
<div class="state p-primary">
|
||||
<label><@spring.message code='common.radio.disable' /></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
<button type="submit" class="btn btn-primary pull-right" ><@spring.message code='common.btn.save' /></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12">
|
||||
<ul style="list-style: none;padding-left: 0">
|
||||
<li class="resourceType">
|
||||
|
@ -225,6 +269,10 @@
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
$('#btnBackupOption').click(function () {
|
||||
$('#backupOptionsPanel').slideToggle(400);
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
<#include "module/_footer.ftl">
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
</ol>
|
||||
</section>
|
||||
<section class="content container-fluid">
|
||||
<!-- Small boxes (Stat box) -->
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-xs-12" id="widgetOptionsPanel" style="display: none">
|
||||
<div class="box box-primary">
|
||||
|
|
Loading…
Reference in New Issue