Fix the initialization of birthday (#1701)

* fix: The initial value of birthday in PrimaryProperties file is 0, and the initial number of days for blog creation is 19053
pull/1703/head
lan-yonghui 2022-03-04 18:14:38 +08:00 committed by GitHub
parent c9f7bd1abb
commit 5a5e88d157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 14 deletions

View File

@ -43,6 +43,7 @@ import run.halo.app.service.PostCommentService;
import run.halo.app.service.PostService;
import run.halo.app.service.SheetService;
import run.halo.app.service.UserService;
import run.halo.app.utils.DateUtils;
import run.halo.app.utils.ValidationUtils;
/**
@ -296,6 +297,7 @@ public class InstallController {
StringUtils.isBlank(installParam.getUrl()) ? optionService.getBlogBaseUrl() :
installParam.getUrl());
properties.put(OtherProperties.GLOBAL_ABSOLUTE_PATH_ENABLED, Boolean.FALSE.toString());
properties.put(PrimaryProperties.BIRTHDAY, String.valueOf(DateUtils.now().getTime()));
// Create properties
optionService.saveProperties(properties);

View File

@ -1,8 +1,6 @@
package run.halo.app.service.impl;
import com.qiniu.common.Zone;
import com.qiniu.storage.Region;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
@ -10,7 +8,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import javax.persistence.criteria.Predicate;
import lombok.extern.slf4j.Slf4j;
@ -28,28 +25,22 @@ import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import run.halo.app.cache.AbstractStringCacheStore;
import run.halo.app.event.options.OptionUpdatedEvent;
import run.halo.app.exception.MissingPropertyException;
import run.halo.app.model.dto.OptionDTO;
import run.halo.app.model.dto.OptionSimpleDTO;
import run.halo.app.model.entity.Option;
import run.halo.app.model.enums.PostPermalinkType;
import run.halo.app.model.enums.SheetPermalinkType;
import run.halo.app.model.enums.ValueEnum;
import run.halo.app.model.params.OptionParam;
import run.halo.app.model.params.OptionQuery;
import run.halo.app.model.properties.BlogProperties;
import run.halo.app.model.properties.CommentProperties;
import run.halo.app.model.properties.OtherProperties;
import run.halo.app.model.properties.PermalinkProperties;
import run.halo.app.model.properties.PostProperties;
import run.halo.app.model.properties.PrimaryProperties;
import run.halo.app.model.properties.PropertyEnum;
import run.halo.app.model.properties.QiniuOssProperties;
import run.halo.app.model.properties.SeoProperties;
import run.halo.app.repository.OptionRepository;
import run.halo.app.service.OptionService;
import run.halo.app.service.base.AbstractCrudService;
import run.halo.app.utils.DateUtils;
import run.halo.app.utils.ServiceUtils;
import run.halo.app.utils.ValidationUtils;
@ -373,11 +364,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer>
@Override
public long getBirthday() {
return getByProperty(PrimaryProperties.BIRTHDAY, Long.class).orElseGet(() -> {
long currentTime = DateUtils.now().getTime();
saveProperty(PrimaryProperties.BIRTHDAY, String.valueOf(currentTime));
return currentTime;
});
return Long.parseLong(getByPropertyOrDefault(PrimaryProperties.BIRTHDAY, String.class));
}
@Override

View File

@ -7,7 +7,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static run.halo.app.service.OptionService.OPTIONS_KEY;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@ -16,7 +20,10 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
import run.halo.app.cache.AbstractStringCacheStore;
import run.halo.app.model.properties.PrimaryProperties;
import run.halo.app.security.service.OneTimeTokenService;
import run.halo.app.utils.DateUtils;
@SpringBootTest(webEnvironment = RANDOM_PORT)
@ActiveProfiles("test")
@ -31,6 +38,20 @@ class OneTimeTokenTest {
@Autowired
OneTimeTokenService oneTimeTokenService;
@Autowired
AbstractStringCacheStore cacheStore;
Map<String, Object> map = new HashMap<>();
{
map.put(PrimaryProperties.BIRTHDAY.getValue(), String.valueOf(DateUtils.now().getTime()));
}
@BeforeEach
void setUp() {
cacheStore.putAny(OPTIONS_KEY, map);
}
@Test
void provideNonExistOneTimeTokenTest() throws Exception {
mvc.perform(get(REQUEST_URI + "?ott={ott}", "one-time-token-value"))