mirror of https://github.com/halo-dev/halo
feat: 删除主题时可选是否删除配置 (#1105)
* feat: 删除主题时可选是否删除配置 * doc: add java doc for run/halo/app/repository/ThemeSettingRepository.java#deleteByThemeId Co-authored-by: Ryan Wang <i@ryanc.cc>pull/1107/head
parent
5520baf046
commit
036644bf10
|
@ -154,8 +154,9 @@ public class ThemeController {
|
||||||
@DeleteMapping("{themeId}")
|
@DeleteMapping("{themeId}")
|
||||||
@ApiOperation("Deletes a theme")
|
@ApiOperation("Deletes a theme")
|
||||||
@DisableOnCondition
|
@DisableOnCondition
|
||||||
public void deleteBy(@PathVariable("themeId") String themeId) {
|
public void deleteBy(@PathVariable("themeId") String themeId,
|
||||||
themeService.deleteTheme(themeId);
|
@RequestParam(value = "deleteSettings", defaultValue = "false") Boolean deleteSettings) {
|
||||||
|
themeService.deleteTheme(themeId, deleteSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("upload")
|
@PostMapping("upload")
|
||||||
|
|
|
@ -49,4 +49,11 @@ public interface ThemeSettingRepository extends BaseRepository<ThemeSetting, Int
|
||||||
* @param activatedThemeId activated theme id.
|
* @param activatedThemeId activated theme id.
|
||||||
*/
|
*/
|
||||||
void deleteByThemeIdIsNot(@NonNull String activatedThemeId);
|
void deleteByThemeIdIsNot(@NonNull String activatedThemeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes settings by theme id.
|
||||||
|
*
|
||||||
|
* @param themeId theme id.
|
||||||
|
*/
|
||||||
|
void deleteByThemeId(String themeId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,8 +222,9 @@ public interface ThemeService {
|
||||||
* Deletes a theme by key.
|
* Deletes a theme by key.
|
||||||
*
|
*
|
||||||
* @param themeId theme id must not be blank
|
* @param themeId theme id must not be blank
|
||||||
|
* @param deleteSettings whether all settings of the specified theme should be deleted.
|
||||||
*/
|
*/
|
||||||
void deleteTheme(@NonNull String themeId);
|
void deleteTheme(@NonNull String themeId, @NonNull Boolean deleteSettings);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches theme configuration.
|
* Fetches theme configuration.
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
@ -32,6 +33,7 @@ import run.halo.app.handler.theme.config.support.ThemeProperty;
|
||||||
import run.halo.app.model.properties.PrimaryProperties;
|
import run.halo.app.model.properties.PrimaryProperties;
|
||||||
import run.halo.app.model.support.HaloConst;
|
import run.halo.app.model.support.HaloConst;
|
||||||
import run.halo.app.model.support.ThemeFile;
|
import run.halo.app.model.support.ThemeFile;
|
||||||
|
import run.halo.app.repository.ThemeSettingRepository;
|
||||||
import run.halo.app.service.OptionService;
|
import run.halo.app.service.OptionService;
|
||||||
import run.halo.app.service.ThemeService;
|
import run.halo.app.service.ThemeService;
|
||||||
import run.halo.app.theme.ThemeFileScanner;
|
import run.halo.app.theme.ThemeFileScanner;
|
||||||
|
@ -77,6 +79,8 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
|
|
||||||
private final ApplicationEventPublisher eventPublisher;
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
|
private final ThemeSettingRepository themeSettingRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Activated theme id.
|
* Activated theme id.
|
||||||
*/
|
*/
|
||||||
|
@ -93,7 +97,8 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
AbstractStringCacheStore cacheStore,
|
AbstractStringCacheStore cacheStore,
|
||||||
ThemeConfigResolver themeConfigResolver,
|
ThemeConfigResolver themeConfigResolver,
|
||||||
RestTemplate restTemplate,
|
RestTemplate restTemplate,
|
||||||
ApplicationEventPublisher eventPublisher) {
|
ApplicationEventPublisher eventPublisher,
|
||||||
|
ThemeSettingRepository themeSettingRepository) {
|
||||||
this.optionService = optionService;
|
this.optionService = optionService;
|
||||||
this.cacheStore = cacheStore;
|
this.cacheStore = cacheStore;
|
||||||
this.themeConfigResolver = themeConfigResolver;
|
this.themeConfigResolver = themeConfigResolver;
|
||||||
|
@ -101,6 +106,7 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
|
|
||||||
themeWorkDir = Paths.get(haloProperties.getWorkDir(), THEME_FOLDER);
|
themeWorkDir = Paths.get(haloProperties.getWorkDir(), THEME_FOLDER);
|
||||||
this.eventPublisher = eventPublisher;
|
this.eventPublisher = eventPublisher;
|
||||||
|
this.themeSettingRepository = themeSettingRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -255,8 +261,9 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public void deleteTheme(@NonNull String themeId) {
|
public void deleteTheme(@NonNull String themeId, @NonNull Boolean deleteSettings) {
|
||||||
// Get the theme property
|
// Get the theme property
|
||||||
ThemeProperty themeProperty = getThemeOfNonNullBy(themeId);
|
ThemeProperty themeProperty = getThemeOfNonNullBy(themeId);
|
||||||
|
|
||||||
|
@ -268,6 +275,10 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
try {
|
try {
|
||||||
// Delete the folder
|
// Delete the folder
|
||||||
FileUtils.deleteFolder(Paths.get(themeProperty.getThemePath()));
|
FileUtils.deleteFolder(Paths.get(themeProperty.getThemePath()));
|
||||||
|
if (deleteSettings) {
|
||||||
|
// Delete theme settings
|
||||||
|
themeSettingRepository.deleteByThemeId(themeId);
|
||||||
|
}
|
||||||
// Delete theme cache
|
// Delete theme cache
|
||||||
eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
|
eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue