mirror of https://github.com/halo-dev/halo
refactor: installation data. (#600)
parent
136b1fb3b9
commit
949a3da3de
|
@ -17,23 +17,22 @@ import run.halo.app.event.logger.LogEvent;
|
|||
import run.halo.app.exception.BadRequestException;
|
||||
import run.halo.app.model.entity.BaseComment;
|
||||
import run.halo.app.model.entity.Category;
|
||||
import run.halo.app.model.entity.Post;
|
||||
import run.halo.app.model.entity.PostComment;
|
||||
import run.halo.app.model.entity.User;
|
||||
import run.halo.app.model.enums.LogType;
|
||||
import run.halo.app.model.enums.PostStatus;
|
||||
import run.halo.app.model.params.*;
|
||||
import run.halo.app.model.properties.BlogProperties;
|
||||
import run.halo.app.model.properties.OtherProperties;
|
||||
import run.halo.app.model.properties.PrimaryProperties;
|
||||
import run.halo.app.model.properties.PropertyEnum;
|
||||
import run.halo.app.model.support.BaseResponse;
|
||||
import run.halo.app.model.support.CreateCheck;
|
||||
import run.halo.app.model.vo.PostDetailVO;
|
||||
import run.halo.app.service.*;
|
||||
import run.halo.app.utils.ValidationUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Installation controller.
|
||||
|
@ -52,6 +51,8 @@ public class InstallController {
|
|||
|
||||
private final PostService postService;
|
||||
|
||||
private final SheetService sheetService;
|
||||
|
||||
private final PostCommentService postCommentService;
|
||||
|
||||
private final OptionService optionService;
|
||||
|
@ -63,6 +64,7 @@ public class InstallController {
|
|||
public InstallController(UserService userService,
|
||||
CategoryService categoryService,
|
||||
PostService postService,
|
||||
SheetService sheetService,
|
||||
PostCommentService postCommentService,
|
||||
OptionService optionService,
|
||||
MenuService menuService,
|
||||
|
@ -70,6 +72,7 @@ public class InstallController {
|
|||
this.userService = userService;
|
||||
this.categoryService = categoryService;
|
||||
this.postService = postService;
|
||||
this.sheetService = sheetService;
|
||||
this.postCommentService = postCommentService;
|
||||
this.optionService = optionService;
|
||||
this.menuService = menuService;
|
||||
|
@ -101,7 +104,10 @@ public class InstallController {
|
|||
Category category = createDefaultCategoryIfAbsent();
|
||||
|
||||
// Create default post
|
||||
Post post = createDefaultPostIfAbsent(category);
|
||||
PostDetailVO post = createDefaultPostIfAbsent(category);
|
||||
|
||||
// Create default sheet
|
||||
createDefaultSheet();
|
||||
|
||||
// Create default postComment
|
||||
createDefaultComment(post);
|
||||
|
@ -133,30 +139,42 @@ public class InstallController {
|
|||
|
||||
MenuParam menuArchive = new MenuParam();
|
||||
|
||||
menuArchive.setName("归档");
|
||||
menuArchive.setName("文章归档");
|
||||
menuArchive.setUrl("/archives");
|
||||
menuArchive.setPriority(2);
|
||||
menuService.create(menuArchive.convertTo());
|
||||
|
||||
MenuParam menuCategory = new MenuParam();
|
||||
menuCategory.setName("默认分类");
|
||||
menuCategory.setUrl("/categories/default");
|
||||
menuCategory.setPriority(3);
|
||||
menuService.create(menuCategory.convertTo());
|
||||
|
||||
MenuParam menuSheet = new MenuParam();
|
||||
menuSheet.setName("关于页面");
|
||||
menuSheet.setUrl("/s/about");
|
||||
menuSheet.setPriority(4);
|
||||
menuService.create(menuSheet.convertTo());
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private BaseComment createDefaultComment(@Nullable Post post) {
|
||||
private BaseComment createDefaultComment(@Nullable PostDetailVO post) {
|
||||
if (post == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PostCommentParam commentParam = new PostCommentParam();
|
||||
commentParam.setAuthor("Halo Bot");
|
||||
commentParam.setAuthorUrl("https://halo.run");
|
||||
commentParam.setContent("欢迎使用 Halo,这是你的第一条评论。");
|
||||
commentParam.setEmail("halo@halo.run");
|
||||
commentParam.setPostId(post.getId());
|
||||
return postCommentService.create(commentParam.convertTo());
|
||||
PostComment comment = new PostComment();
|
||||
comment.setAuthor("Halo");
|
||||
comment.setAuthorUrl("https://halo.run");
|
||||
comment.setContent("欢迎使用 Halo,这是你的第一条评论,头像来自 [Gravatar](https://cn.gravatar.com),你也可以通过注册 [Gravatar](https://cn.gravatar.com) 来显示自己的头像。");
|
||||
comment.setEmail("hi@halo.run");
|
||||
comment.setPostId(post.getId());
|
||||
return postCommentService.create(comment);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Post createDefaultPostIfAbsent(@Nullable Category category) {
|
||||
private PostDetailVO createDefaultPostIfAbsent(@Nullable Category category) {
|
||||
long publishedCount = postService.countByStatus(PostStatus.PUBLISHED);
|
||||
if (publishedCount > 0) {
|
||||
return null;
|
||||
|
@ -166,16 +184,42 @@ public class InstallController {
|
|||
postParam.setSlug("hello-halo");
|
||||
postParam.setTitle("Hello Halo");
|
||||
postParam.setStatus(PostStatus.PUBLISHED);
|
||||
postParam.setOriginalContent("## Hello Halo!\n" +
|
||||
postParam.setOriginalContent("## Hello Halo\n" +
|
||||
"\n" +
|
||||
"感谢使用 [Halo](https://github.com/halo-dev/halo) 进行创作,请删除该文章开始吧!");
|
||||
"如果你看到了这一篇文章,那么证明你已经安装成功了,感谢使用 [Halo](https://halo.run) 进行创作,希望能够使用愉快。\n" +
|
||||
"\n" +
|
||||
"## 相关链接\n" +
|
||||
"\n" +
|
||||
"- 官网:[https://halo.run](https://halo.run)\n" +
|
||||
"- 社区:[https://bbs.halo.run](https://bbs.halo.run)\n" +
|
||||
"- 主题仓库:[https://halo.run/s/themes](https://halo.run/s/themes)\n" +
|
||||
"- 开源地址:[https://github.com/halo-dev/halo](https://github.com/halo-dev/halo)\n" +
|
||||
"\n" +
|
||||
"在使用过程中,有任何问题都可以通过以上链接找寻答案,或者联系我们。\n" +
|
||||
"\n" +
|
||||
"> 这是一篇自动生成的文章,请删除这篇文章之后开始你的创作吧!\n" +
|
||||
"\n");
|
||||
|
||||
Set<Integer> categoryIds = new HashSet<>();
|
||||
if (category != null) {
|
||||
Set<Integer> categoryIds = new HashSet<>();
|
||||
categoryIds.add(category.getId());
|
||||
postParam.setCategoryIds(categoryIds);
|
||||
}
|
||||
return postService.createOrUpdateBy(postParam.convertTo());
|
||||
return postService.createBy(postParam.convertTo(), Collections.emptySet(), categoryIds, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private void createDefaultSheet() {
|
||||
SheetParam sheetParam = new SheetParam();
|
||||
sheetParam.setSlug("about");
|
||||
sheetParam.setTitle("关于页面");
|
||||
sheetParam.setStatus(PostStatus.PUBLISHED);
|
||||
sheetParam.setOriginalContent("## 关于页面\n" +
|
||||
"\n" +
|
||||
"这是一个自定义页面,你可以在后台的 `页面` -> `所有页面` -> `自定义页面` 找到它,你可以用于新建关于页面、留言板页面等等。发挥你自己的想象力!\n" +
|
||||
"\n" +
|
||||
"> 这是一篇自动生成的页面,你可以在后台删除它。");
|
||||
sheetService.createBy(sheetParam.convertTo(), false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -186,9 +230,9 @@ public class InstallController {
|
|||
}
|
||||
|
||||
CategoryParam category = new CategoryParam();
|
||||
category.setName("未分类");
|
||||
category.setName("默认分类");
|
||||
category.setSlug("default");
|
||||
category.setDescription("未分类");
|
||||
category.setDescription("这是你的默认分类,如不需要,删除即可。");
|
||||
ValidationUtils.validate(category);
|
||||
return categoryService.create(category.convertTo());
|
||||
}
|
||||
|
@ -220,6 +264,7 @@ public class InstallController {
|
|||
properties.put(BlogProperties.BLOG_URL, StringUtils.isBlank(installParam.getUrl()) ?
|
||||
optionService.getBlogBaseUrl() : installParam.getUrl());
|
||||
properties.put(PrimaryProperties.BIRTHDAY, String.valueOf(System.currentTimeMillis()));
|
||||
properties.put(OtherProperties.GLOBAL_ABSOLUTE_PATH_ENABLED, Boolean.FALSE.toString());
|
||||
|
||||
// Create properties
|
||||
optionService.saveProperties(properties);
|
||||
|
|
Loading…
Reference in New Issue