mirror of https://github.com/halo-dev/halo
Fix the problem where the activated field was not set correctly for a theme property (#1632)
Signed-off-by: John Niang <johnniang@fastmail.com>pull/1635/head
parent
bd87d17329
commit
2249ef1103
|
@ -61,7 +61,9 @@ public class ThemeRepositoryImpl
|
|||
|
||||
@Override
|
||||
public String getActivatedThemeId() {
|
||||
return getActivatedThemeProperty().getId();
|
||||
return this.optionRepository.findByKey(THEME.getValue())
|
||||
.map(Option::getValue)
|
||||
.orElse(DEFAULT_THEME_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,13 +74,11 @@ public class ThemeRepositoryImpl
|
|||
synchronized (this) {
|
||||
if (this.currentTheme == null) {
|
||||
// get current theme id
|
||||
String currentThemeId = this.optionRepository.findByKey(THEME.getValue())
|
||||
.map(Option::getValue)
|
||||
.orElse(DEFAULT_THEME_ID);
|
||||
String currentThemeId = getActivatedThemeId();
|
||||
|
||||
// fetch current theme
|
||||
this.currentTheme =
|
||||
this.fetchThemeByThemeId(currentThemeId).orElseGet(() -> {
|
||||
this.fetchThemePropertyByThemeId(currentThemeId).orElseGet(() -> {
|
||||
if (!StringUtils.equalsIgnoreCase(currentThemeId, DEFAULT_THEME_ID)) {
|
||||
fallbackTheme.set(true);
|
||||
return this.getThemeByThemeId(DEFAULT_THEME_ID);
|
||||
|
@ -98,7 +98,7 @@ public class ThemeRepositoryImpl
|
|||
|
||||
@Override
|
||||
public Optional<ThemeProperty> fetchThemePropertyByThemeId(String themeId) {
|
||||
return ThemePropertyScanner.INSTANCE.scan(getThemeRootPath(), null)
|
||||
return listAll()
|
||||
.stream()
|
||||
.filter(property -> Objects.equals(themeId, property.getId()))
|
||||
.findFirst();
|
||||
|
@ -127,7 +127,7 @@ public class ThemeRepositoryImpl
|
|||
@Override
|
||||
public ThemeProperty attemptToAdd(ThemeProperty newProperty) {
|
||||
// 1. check existence
|
||||
final var alreadyExist = fetchThemeByThemeId(newProperty.getId()).isPresent();
|
||||
final var alreadyExist = fetchThemePropertyByThemeId(newProperty.getId()).isPresent();
|
||||
if (alreadyExist) {
|
||||
throw new AlreadyExistsException("当前安装的主题已存在");
|
||||
}
|
||||
|
@ -206,15 +206,8 @@ public class ThemeRepositoryImpl
|
|||
|
||||
@NonNull
|
||||
protected ThemeProperty getThemeByThemeId(String themeId) {
|
||||
return fetchThemeByThemeId(themeId).orElseThrow(
|
||||
return fetchThemePropertyByThemeId(themeId).orElseThrow(
|
||||
() -> new ThemeNotFoundException("Failed to find theme with id: " + themeId));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected Optional<ThemeProperty> fetchThemeByThemeId(String themeId) {
|
||||
return ThemePropertyScanner.INSTANCE.scan(getThemeRootPath(), null)
|
||||
.stream()
|
||||
.filter(property -> Objects.equals(themeId, property.getId()))
|
||||
.findFirst();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,13 +60,13 @@ class ThemeRepositoryImplTest {
|
|||
|
||||
given(optionRepository.findByKey(THEME.getValue())).willReturn(Optional.empty());
|
||||
doReturn(Optional.of(expectedTheme)).when(themeRepository)
|
||||
.fetchThemeByThemeId(HaloConst.DEFAULT_THEME_ID);
|
||||
.fetchThemePropertyByThemeId(HaloConst.DEFAULT_THEME_ID);
|
||||
|
||||
ThemeProperty resultTheme = themeRepository.getActivatedThemeProperty();
|
||||
assertEquals(expectedTheme, resultTheme);
|
||||
|
||||
verify(optionRepository, times(1)).findByKey(any());
|
||||
verify(themeRepository, times(1)).fetchThemeByThemeId(any());
|
||||
verify(themeRepository, times(1)).fetchThemePropertyByThemeId(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -77,7 +77,7 @@ class ThemeRepositoryImplTest {
|
|||
|
||||
given(optionRepository.findByKey(THEME.getValue())).willReturn(Optional.empty());
|
||||
doReturn(Optional.of(expectedTheme)).when(themeRepository)
|
||||
.fetchThemeByThemeId(HaloConst.DEFAULT_THEME_ID);
|
||||
.fetchThemePropertyByThemeId(HaloConst.DEFAULT_THEME_ID);
|
||||
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||
// define tasks
|
||||
|
@ -96,7 +96,7 @@ class ThemeRepositoryImplTest {
|
|||
});
|
||||
|
||||
verify(optionRepository, times(1)).findByKey(any());
|
||||
verify(themeRepository, times(1)).fetchThemeByThemeId(any());
|
||||
verify(themeRepository, times(1)).fetchThemePropertyByThemeId(any());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue