Commit 24c1ffbf authored by Van's avatar Van

Merge remote-tracking branch 'origin/3.6.5-dev' into 3.6.5-dev

parents 23acec9d 9b3bea87
......@@ -51,7 +51,8 @@ import java.util.Set;
* Category console request processing.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.3.5, Jul 22, 2019
* @author <a href="https://hacpai.com/member/lzh984294471">lzh984294471</a>
* @version 1.1.3.6, Sep 1, 2019
* @since 2.0.0
*/
@RequestProcessor
......@@ -154,6 +155,7 @@ public class CategoryConsole {
* @param context the specified request context
* @throws Exception exception
*/
@SuppressWarnings("unchecked")
public void getCategory(final RequestContext context) {
final JsonRenderer renderer = new JsonRenderer();
context.setRenderer(renderer);
......@@ -169,6 +171,9 @@ public class CategoryConsole {
final StringBuilder tagBuilder = new StringBuilder();
final List<JSONObject> tags = (List<JSONObject>) result.opt(Category.CATEGORY_T_TAGS);
for (final JSONObject tag : tags) {
if (null == tag || !tag.has(Tag.TAG_TITLE)) { // 修复修改分类时空指针错误 https://github.com/b3log/solo/pull/12876
continue;
}
tagBuilder.append(tag.optString(Tag.TAG_TITLE)).append(",");
}
tagBuilder.deleteCharAt(tagBuilder.length() - 1);
......
......@@ -52,7 +52,7 @@ import static org.b3log.solo.model.Article.*;
* Article management service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.3.1.6, Aug 18, 2019
* @version 1.3.2.0, Sep 1, 2019
* @since 0.3.5
*/
@Service
......@@ -117,6 +117,12 @@ public class ArticleMgmtService {
@Inject
private CommentRepository commentRepository;
/**
* Category-tag repository.
*/
@Inject
private CategoryTagRepository categoryTagRepository;
/**
* Permalink query service.
*/
......@@ -810,19 +816,16 @@ public class ArticleMgmtService {
* @throws JSONException json exception
* @throws RepositoryException repository exception
*/
private void removeTagArticleRelations(final String articleId, final String... tagIds)
throws JSONException, RepositoryException {
private void removeTagArticleRelations(final String articleId, final String... tagIds) throws JSONException, RepositoryException {
final List<String> tagIdList = Arrays.asList(tagIds);
final List<JSONObject> tagArticleRelations = tagArticleRepository.getByArticleId(articleId);
for (int i = 0; i < tagArticleRelations.size(); i++) {
final JSONObject tagArticleRelation = tagArticleRelations.get(i);
String relationId;
if (tagIdList.isEmpty()) { // Removes all if un-specified
relationId = tagArticleRelation.getString(Keys.OBJECT_ID);
tagArticleRepository.remove(relationId);
} else {
if (tagIdList.contains(tagArticleRelation.getString(Tag.TAG + "_" + Keys.OBJECT_ID))) {
relationId = tagArticleRelation.getString(Keys.OBJECT_ID);
......@@ -833,6 +836,7 @@ public class ArticleMgmtService {
final String tagId = tagArticleRelation.optString(Tag.TAG + "_" + Keys.OBJECT_ID);
final int articleCount = tagArticleRepository.getArticleCount(tagId);
if (1 > articleCount) {
categoryTagRepository.removeByTagId(tagId);
tagRepository.remove(tagId);
}
}
......
......@@ -43,7 +43,8 @@ import java.util.List;
* Category query service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.1.3, Jan 15, 2019
* @author <a href="https://hacpai.com/member/lzh984294471">lzh984294471</a>
* @version 1.0.1.4, Sep 1, 2019
* @since 2.0.0
*/
@Service
......@@ -115,7 +116,9 @@ public class CategoryQueryService {
for (final JSONObject relation : relations) {
final String tagId = relation.optString(Tag.TAG + "_" + Keys.OBJECT_ID);
final JSONObject tag = tagRepository.get(tagId);
if (null == tag) { // 修复修改分类时空指针错误 https://github.com/b3log/solo/pull/12876
continue;
}
ret.add(tag);
}
} catch (final RepositoryException e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment