mirror of https://github.com/halo-dev/halo
Complete install method.
parent
34e13f35c0
commit
3193ed9f77
|
@ -13,11 +13,13 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import run.halo.app.cache.lock.CacheLock;
|
import run.halo.app.cache.lock.CacheLock;
|
||||||
import run.halo.app.event.logger.LogEvent;
|
import run.halo.app.event.logger.LogEvent;
|
||||||
import run.halo.app.exception.BadRequestException;
|
import run.halo.app.exception.BadRequestException;
|
||||||
import run.halo.app.model.entity.*;
|
import run.halo.app.model.entity.Category;
|
||||||
|
import run.halo.app.model.entity.Post;
|
||||||
|
import run.halo.app.model.entity.User;
|
||||||
import run.halo.app.model.enums.AttachmentType;
|
import run.halo.app.model.enums.AttachmentType;
|
||||||
import run.halo.app.model.enums.LogType;
|
import run.halo.app.model.enums.LogType;
|
||||||
import run.halo.app.model.params.CategoryParam;
|
import run.halo.app.model.enums.PostStatus;
|
||||||
import run.halo.app.model.params.InstallParam;
|
import run.halo.app.model.params.*;
|
||||||
import run.halo.app.model.properties.*;
|
import run.halo.app.model.properties.*;
|
||||||
import run.halo.app.model.support.BaseResponse;
|
import run.halo.app.model.support.BaseResponse;
|
||||||
import run.halo.app.service.*;
|
import run.halo.app.service.*;
|
||||||
|
@ -25,7 +27,9 @@ import run.halo.app.utils.ValidationUtils;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static run.halo.app.model.support.HaloConst.DEFAULT_THEME_ID;
|
import static run.halo.app.model.support.HaloConst.DEFAULT_THEME_ID;
|
||||||
|
|
||||||
|
@ -83,7 +87,6 @@ public class InstallController {
|
||||||
boolean isInstalled = optionService.getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false);
|
boolean isInstalled = optionService.getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false);
|
||||||
|
|
||||||
if (isInstalled) {
|
if (isInstalled) {
|
||||||
// TODO i18n
|
|
||||||
throw new BadRequestException("该博客已初始化,不能再次安装!");
|
throw new BadRequestException("该博客已初始化,不能再次安装!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,59 +103,71 @@ public class InstallController {
|
||||||
Post post = createDefaultPost(category);
|
Post post = createDefaultPost(category);
|
||||||
|
|
||||||
// Create default postComment
|
// Create default postComment
|
||||||
PostComment postComment = createDefaultComment();
|
createDefaultComment(post);
|
||||||
|
|
||||||
// Create default menu
|
// Create default menu
|
||||||
createDefaultMenu();
|
createDefaultMenu();
|
||||||
|
|
||||||
// TODO Handle option cache
|
// TODO Handle option cache
|
||||||
|
|
||||||
// TODO i18n
|
|
||||||
eventPublisher.publishEvent(
|
eventPublisher.publishEvent(
|
||||||
new LogEvent(this, user.getId().toString(), LogType.BLOG_INITIALIZED, "博客已成功初始化")
|
new LogEvent(this, user.getId().toString(), LogType.BLOG_INITIALIZED, "博客已成功初始化")
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO i18n
|
|
||||||
return BaseResponse.ok("安装完成!");
|
return BaseResponse.ok("安装完成!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createDefaultMenu() {
|
private void createDefaultMenu() {
|
||||||
Menu menuIndex = new Menu();
|
MenuParam menuIndex = new MenuParam();
|
||||||
// TODO i18n
|
|
||||||
menuIndex.setName("首页");
|
menuIndex.setName("首页");
|
||||||
menuIndex.setUrl("/");
|
menuIndex.setUrl("/");
|
||||||
menuIndex.setPriority(1);
|
menuIndex.setPriority(1);
|
||||||
menuService.create(menuIndex);
|
|
||||||
|
|
||||||
Menu menuArchive = new Menu();
|
menuService.create(menuIndex.convertTo());
|
||||||
// TODO i18n
|
|
||||||
|
MenuParam menuArchive = new MenuParam();
|
||||||
|
|
||||||
menuArchive.setName("归档");
|
menuArchive.setName("归档");
|
||||||
menuArchive.setUrl("/archives");
|
menuArchive.setUrl("/archives");
|
||||||
menuArchive.setPriority(2);
|
menuArchive.setPriority(2);
|
||||||
menuService.create(menuArchive);
|
menuService.create(menuArchive.convertTo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private PostComment createDefaultComment() {
|
private void createDefaultComment(Post post) {
|
||||||
// TODO Create default comment
|
PostCommentParam commentParam = new PostCommentParam();
|
||||||
return null;
|
commentParam.setAuthor("Halo Bot");
|
||||||
|
commentParam.setAuthorUrl("https://github.com/halo-dev/halo");
|
||||||
|
commentParam.setContent("欢迎使用 Halo,这是你的第一条评论。");
|
||||||
|
commentParam.setEmail("i@ryanc.cc");
|
||||||
|
commentParam.setPostId(post.getId());
|
||||||
|
postCommentService.create(commentParam.convertTo());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Post createDefaultPost(Category category) {
|
private Post createDefaultPost(Category category) {
|
||||||
// TODO Create default post
|
PostParam postParam = new PostParam();
|
||||||
return null;
|
postParam.setUrl("hello-halo");
|
||||||
|
postParam.setTitle("Hello Halo");
|
||||||
|
postParam.setStatus(PostStatus.PUBLISHED);
|
||||||
|
postParam.setOriginalContent("## Hello Halo!\n" +
|
||||||
|
"\n" +
|
||||||
|
"感谢使用 [Halo](https://github.com/halo-dev/halo) 进行创作,请删除该文章开始吧!");
|
||||||
|
Set<Integer> categoryIds = new HashSet<>();
|
||||||
|
categoryIds.add(category.getId());
|
||||||
|
postParam.setCategoryIds(categoryIds);
|
||||||
|
return postService.create(postParam.convertTo());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private Category createDefaultCategory() {
|
private Category createDefaultCategory() {
|
||||||
CategoryParam category = new CategoryParam();
|
CategoryParam category = new CategoryParam();
|
||||||
|
|
||||||
category.setName("未分类");
|
category.setName("未分类");
|
||||||
category.setSlugName("default");
|
category.setSlugName("default");
|
||||||
category.setDescription("未分类");
|
category.setDescription("未分类");
|
||||||
|
|
||||||
ValidationUtils.validate(category);
|
ValidationUtils.validate(category);
|
||||||
|
|
||||||
return categoryService.create(category.convertTo());
|
return categoryService.create(category.convertTo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue