mirror of https://github.com/halo-dev/halo
Fix errors caused by ThemeService
parent
ca73a30c78
commit
7060cc8046
|
@ -5,8 +5,8 @@ import cc.ryanc.halo.model.enums.BlogProperties;
|
||||||
import cc.ryanc.halo.model.support.HaloConst;
|
import cc.ryanc.halo.model.support.HaloConst;
|
||||||
import cc.ryanc.halo.model.support.Theme;
|
import cc.ryanc.halo.model.support.Theme;
|
||||||
import cc.ryanc.halo.service.OptionService;
|
import cc.ryanc.halo.service.OptionService;
|
||||||
|
import cc.ryanc.halo.service.ThemeService;
|
||||||
import cc.ryanc.halo.utils.HaloUtils;
|
import cc.ryanc.halo.utils.HaloUtils;
|
||||||
import cc.ryanc.halo.utils.ThemeUtils;
|
|
||||||
import cc.ryanc.halo.web.controller.content.base.BaseContentController;
|
import cc.ryanc.halo.web.controller.content.base.BaseContentController;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
@ -53,6 +53,9 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
||||||
@Autowired
|
@Autowired
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ThemeService themeService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(ApplicationStartedEvent event) {
|
public void onApplicationEvent(ApplicationStartedEvent event) {
|
||||||
// save halo version to database
|
// save halo version to database
|
||||||
|
@ -66,7 +69,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
||||||
* Cache themes to map
|
* Cache themes to map
|
||||||
*/
|
*/
|
||||||
private void cacheThemes() {
|
private void cacheThemes() {
|
||||||
final List<Theme> themes = ThemeUtils.getThemes();
|
final List<Theme> themes = themeService.getThemes();
|
||||||
if (null != themes) {
|
if (null != themes) {
|
||||||
HaloConst.THEMES = themes;
|
HaloConst.THEMES = themes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package cc.ryanc.halo.web.controller.admin.base;
|
package cc.ryanc.halo.web.controller.admin.base;
|
||||||
|
|
||||||
import cc.ryanc.halo.service.OptionService;
|
import cc.ryanc.halo.service.OptionService;
|
||||||
import cc.ryanc.halo.utils.ThemeUtils;
|
import cc.ryanc.halo.service.ThemeService;
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
import freemarker.template.TemplateModelException;
|
import freemarker.template.TemplateModelException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -22,13 +22,16 @@ public abstract class BaseController {
|
||||||
@Autowired
|
@Autowired
|
||||||
public OptionService optionService;
|
public OptionService optionService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ThemeService themeService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear all caches
|
* Clear all caches
|
||||||
*/
|
*/
|
||||||
public void refreshCache() {
|
public void refreshCache() {
|
||||||
try {
|
try {
|
||||||
THEMES.clear();
|
THEMES.clear();
|
||||||
THEMES = ThemeUtils.getThemes();
|
THEMES = themeService.getThemes();
|
||||||
configuration.setSharedVariable("options", optionService.listOptions());
|
configuration.setSharedVariable("options", optionService.listOptions());
|
||||||
} catch (TemplateModelException e) {
|
} catch (TemplateModelException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -3,10 +3,10 @@ package cc.ryanc.halo.web.controller.core;
|
||||||
import cc.ryanc.halo.logging.Logger;
|
import cc.ryanc.halo.logging.Logger;
|
||||||
import cc.ryanc.halo.model.entity.User;
|
import cc.ryanc.halo.model.entity.User;
|
||||||
import cc.ryanc.halo.model.support.HaloConst;
|
import cc.ryanc.halo.model.support.HaloConst;
|
||||||
import cc.ryanc.halo.utils.ThemeUtils;
|
import cc.ryanc.halo.service.ThemeService;
|
||||||
import cc.ryanc.halo.web.controller.content.base.BaseContentController;
|
import cc.ryanc.halo.web.controller.content.base.BaseContentController;
|
||||||
import cn.hutool.core.text.StrBuilder;
|
import cn.hutool.core.text.StrBuilder;
|
||||||
import cn.hutool.json.JSONObject;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.web.servlet.error.ErrorController;
|
import org.springframework.boot.web.servlet.error.ErrorController;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
@ -35,6 +35,9 @@ public class CommonController implements ErrorController {
|
||||||
|
|
||||||
private final Logger log = Logger.getLogger(getClass());
|
private final Logger log = Logger.getLogger(getClass());
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ThemeService themeService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle error
|
* Handle error
|
||||||
*
|
*
|
||||||
|
@ -101,7 +104,7 @@ public class CommonController implements ErrorController {
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/404")
|
@GetMapping(value = "/404")
|
||||||
public String contentNotFround() throws FileNotFoundException {
|
public String contentNotFround() throws FileNotFoundException {
|
||||||
if (!ThemeUtils.isTemplateExist(NOT_FROUND_TEMPLATE)) {
|
if (!themeService.isTemplateExist(NOT_FROUND_TEMPLATE)) {
|
||||||
return "common/error/404";
|
return "common/error/404";
|
||||||
}
|
}
|
||||||
StrBuilder path = new StrBuilder("themes/");
|
StrBuilder path = new StrBuilder("themes/");
|
||||||
|
@ -117,7 +120,7 @@ public class CommonController implements ErrorController {
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/500")
|
@GetMapping(value = "/500")
|
||||||
public String contentInternalError() throws FileNotFoundException {
|
public String contentInternalError() throws FileNotFoundException {
|
||||||
if (!ThemeUtils.isTemplateExist(INTERNAL_ERROR_TEMPLATE)) {
|
if (!themeService.isTemplateExist(INTERNAL_ERROR_TEMPLATE)) {
|
||||||
return "common/error/500";
|
return "common/error/500";
|
||||||
}
|
}
|
||||||
StrBuilder path = new StrBuilder("themes/");
|
StrBuilder path = new StrBuilder("themes/");
|
||||||
|
|
Loading…
Reference in New Issue