Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IEQEFCR
halo
提交
92503e38
H
halo
项目概览
IEQEFCR
/
halo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
halo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
92503e38
编写于
2月 05, 2021
作者:
RYAN0UP
提交者:
GitHub
2月 05, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: #1255. (#1256)
* fix: #1255. * fix: #1255.
上级
7b88fcab
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
8 deletion
+33
-8
src/main/java/run/halo/app/listener/freemarker/FreemarkerConfigAwareListener.java
...pp/listener/freemarker/FreemarkerConfigAwareListener.java
+12
-1
src/main/java/run/halo/app/model/support/HaloConst.java
src/main/java/run/halo/app/model/support/HaloConst.java
+5
-0
src/main/java/run/halo/app/repository/ThemeRepositoryImpl.java
...ain/java/run/halo/app/repository/ThemeRepositoryImpl.java
+9
-2
src/main/java/run/halo/app/service/impl/OptionServiceImpl.java
...ain/java/run/halo/app/service/impl/OptionServiceImpl.java
+7
-5
未找到文件。
src/main/java/run/halo/app/listener/freemarker/FreemarkerConfigAwareListener.java
浏览文件 @
92503e38
package
run.halo.app.listener.freemarker
;
import
static
run
.
halo
.
app
.
model
.
support
.
HaloConst
.
OPTIONS_CACHE_KEY
;
import
freemarker.template.Configuration
;
import
freemarker.template.TemplateModelException
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -8,6 +10,7 @@ import org.springframework.context.event.EventListener;
import
org.springframework.core.Ordered
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
import
run.halo.app.cache.AbstractStringCacheStore
;
import
run.halo.app.event.options.OptionUpdatedEvent
;
import
run.halo.app.event.theme.ThemeActivatedEvent
;
import
run.halo.app.event.theme.ThemeUpdatedEvent
;
...
...
@@ -41,16 +44,20 @@ public class FreemarkerConfigAwareListener {
private
final
UserService
userService
;
private
final
AbstractStringCacheStore
cacheStore
;
public
FreemarkerConfigAwareListener
(
OptionService
optionService
,
Configuration
configuration
,
ThemeService
themeService
,
ThemeSettingService
themeSettingService
,
UserService
userService
)
{
UserService
userService
,
AbstractStringCacheStore
cacheStore
)
{
this
.
optionService
=
optionService
;
this
.
configuration
=
configuration
;
this
.
themeService
=
themeService
;
this
.
themeSettingService
=
themeSettingService
;
this
.
userService
=
userService
;
this
.
cacheStore
=
cacheStore
;
}
@EventListener
...
...
@@ -90,6 +97,10 @@ public class FreemarkerConfigAwareListener {
public
void
onOptionUpdate
(
OptionUpdatedEvent
event
)
throws
TemplateModelException
{
log
.
debug
(
"Received option updated event"
);
// refresh options cache
optionService
.
flush
();
cacheStore
.
delete
(
OPTIONS_CACHE_KEY
);
loadOptionsConfig
();
loadThemeConfig
();
}
...
...
src/main/java/run/halo/app/model/support/HaloConst.java
浏览文件 @
92503e38
...
...
@@ -155,6 +155,11 @@ public class HaloConst {
*/
public
static
String
DATABASE_PRODUCT_NAME
=
null
;
/**
* Options cache key.
*/
public
static
String
OPTIONS_CACHE_KEY
=
"options"
;
static
{
// Set version
HALO_VERSION
=
Optional
.
ofNullable
(
HaloConst
.
class
.
getPackage
().
getImplementationVersion
())
...
...
src/main/java/run/halo/app/repository/ThemeRepositoryImpl.java
浏览文件 @
92503e38
...
...
@@ -13,10 +13,12 @@ import java.util.Objects;
import
java.util.Optional
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.lang.NonNull
;
import
org.springframework.stereotype.Repository
;
import
org.springframework.util.Assert
;
import
run.halo.app.config.properties.HaloProperties
;
import
run.halo.app.event.options.OptionUpdatedEvent
;
import
run.halo.app.exception.AlreadyExistsException
;
import
run.halo.app.exception.NotFoundException
;
import
run.halo.app.exception.ServiceException
;
...
...
@@ -41,10 +43,14 @@ public class ThemeRepositoryImpl implements ThemeRepository {
private
final
HaloProperties
properties
;
private
final
ApplicationEventPublisher
eventPublisher
;
public
ThemeRepositoryImpl
(
OptionRepository
optionRepository
,
HaloProperties
properties
)
{
HaloProperties
properties
,
ApplicationEventPublisher
eventPublisher
)
{
this
.
optionRepository
=
optionRepository
;
this
.
properties
=
properties
;
this
.
eventPublisher
=
eventPublisher
;
}
@Override
...
...
@@ -74,7 +80,6 @@ public class ThemeRepositoryImpl implements ThemeRepository {
@Override
public
void
setActivatedTheme
(
@NonNull
String
themeId
)
{
Assert
.
hasText
(
themeId
,
"Theme id must not be blank"
);
final
var
newThemeOption
=
optionRepository
.
findByKey
(
PrimaryProperties
.
THEME
.
getValue
())
.
map
(
themeOption
->
{
// set theme id
...
...
@@ -83,6 +88,8 @@ public class ThemeRepositoryImpl implements ThemeRepository {
})
.
orElseGet
(()
->
new
Option
(
PrimaryProperties
.
THEME
.
getValue
(),
themeId
));
optionRepository
.
save
(
newThemeOption
);
eventPublisher
.
publishEvent
(
new
OptionUpdatedEvent
(
this
));
}
@Override
...
...
src/main/java/run/halo/app/service/impl/OptionServiceImpl.java
浏览文件 @
92503e38
...
...
@@ -136,7 +136,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer>
if
(!
CollectionUtils
.
isEmpty
(
optionsToUpdate
)
||
!
CollectionUtils
.
isEmpty
(
optionsToCreate
))
{
// If there is something changed
publishOptionUpdatedEvent
(
);
eventPublisher
.
publishEvent
(
new
OptionUpdatedEvent
(
this
)
);
}
}
...
...
@@ -156,7 +156,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer>
public
void
save
(
OptionParam
optionParam
)
{
Option
option
=
optionParam
.
convertTo
();
create
(
option
);
publishOptionUpdatedEvent
(
);
eventPublisher
.
publishEvent
(
new
OptionUpdatedEvent
(
this
)
);
}
@Override
...
...
@@ -164,7 +164,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer>
Option
optionToUpdate
=
getById
(
optionId
);
optionParam
.
update
(
optionToUpdate
);
update
(
optionToUpdate
);
publishOptionUpdatedEvent
(
);
eventPublisher
.
publishEvent
(
new
OptionUpdatedEvent
(
this
)
);
}
@Override
...
...
@@ -271,7 +271,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer>
@Override
public
Option
removePermanently
(
Integer
id
)
{
Option
deletedOption
=
removeById
(
id
);
publishOptionUpdatedEvent
(
);
eventPublisher
.
publishEvent
(
new
OptionUpdatedEvent
(
this
)
);
return
deletedOption
;
}
...
...
@@ -629,7 +629,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer>
replaced
.
add
(
option
);
});
List
<
Option
>
updated
=
updateInBatch
(
replaced
);
publishOptionUpdatedEvent
(
);
eventPublisher
.
publishEvent
(
new
OptionUpdatedEvent
(
this
)
);
return
updated
.
stream
().
map
(
this
::
convertToDto
).
collect
(
Collectors
.
toList
());
}
...
...
@@ -640,10 +640,12 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer>
return
new
OptionSimpleDTO
().
convertFrom
(
option
);
}
@Deprecated
private
void
cleanCache
()
{
cacheStore
.
delete
(
OPTIONS_KEY
);
}
@Deprecated
private
void
publishOptionUpdatedEvent
()
{
flush
();
cleanCache
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录