Skip to content

Commit

Permalink
feat: support import user. (halo-dev#1283)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby authored Feb 24, 2021
1 parent ad25cff commit 80d0aba
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,4 @@ public void migrateHalo(@RequestPart("file") MultipartFile file) {
}
migrateService.migrate(file, MigrateType.HALO);
}

// @PostMapping("wordpress")
// @ApiOperation("Migrate from WordPress")
// public void migrateWordPress(@RequestPart("file") MultipartFile file) {
// migrateService.migrate(file, MigrateType.WORDPRESS);
// }
//
// @PostMapping("cnblogs")
// @ApiOperation("Migrate from cnblogs")
// public void migrateCnBlogs(@RequestPart("file") MultipartFile file) {
// migrateService.migrate(file, MigrateType.CNBLOGS);
// }
}
12 changes: 1 addition & 11 deletions src/main/java/run/halo/app/model/enums/MigrateType.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,7 @@ public enum MigrateType implements ValueEnum<Integer> {
/**
* Halo
*/
HALO(0),

/**
* WordPress
*/
WORDPRESS(1),

/**
* cnblogs.com
*/
CNBLOGS(2);
HALO(0);

private final Integer value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import run.halo.app.model.entity.SheetMeta;
import run.halo.app.model.entity.Tag;
import run.halo.app.model.entity.ThemeSetting;
import run.halo.app.model.entity.User;
import run.halo.app.model.params.PostMarkdownParam;
import run.halo.app.model.support.HaloConst;
import run.halo.app.model.vo.PostMarkdownVO;
Expand Down Expand Up @@ -515,6 +516,14 @@ public void importData(MultipartFile file) throws IOException {
themeSettingService.createInBatch(themeSettings);

eventPublisher.publishEvent(new ThemeUpdatedEvent(this));

List<User> users = Arrays.asList(mapper
.readValue(mapper.writeValueAsString(data.get("user")),
User[].class));

if (users.size() > 0) {
userService.create(users.get(0));
}
}

@Override
Expand Down

0 comments on commit 80d0aba

Please sign in to comment.