Commit 919146ff authored by Liang Ding's avatar Liang Ding

🎨 修复发布文章时勾选同步社区不生效问题

#12757
parent c454b7be
...@@ -48,7 +48,7 @@ import org.json.JSONObject; ...@@ -48,7 +48,7 @@ import org.json.JSONObject;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://hacpai.com/member/armstrong">ArmstrongCN</a> * @author <a href="https://hacpai.com/member/armstrong">ArmstrongCN</a>
* @version 1.0.2.19, Mar 27, 2019 * @version 1.0.2.20, Apr 13, 2019
* @since 0.3.1 * @since 0.3.1
*/ */
@Singleton @Singleton
...@@ -95,7 +95,7 @@ public class B3ArticleSender extends AbstractEventListener<JSONObject> { ...@@ -95,7 +95,7 @@ public class B3ArticleSender extends AbstractEventListener<JSONObject> {
return; return;
} }
if (Latkes.getServePath().contains("localhost") || Strings.isIPv4(Latkes.getServerHost())) { if (StringUtils.containsIgnoreCase(Latkes.getServePath(), ("localhost")) || Strings.isIPv4(Latkes.getServerHost())) {
LOGGER.log(Level.INFO, "Solo is running on local server, ignored push article [title={0}] to Rhy", title); LOGGER.log(Level.INFO, "Solo is running on local server, ignored push article [title={0}] to Rhy", title);
return; return;
......
...@@ -51,7 +51,7 @@ import static org.b3log.solo.model.Article.*; ...@@ -51,7 +51,7 @@ import static org.b3log.solo.model.Article.*;
* Article management service. * Article management service.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.3.0.0, Feb 10, 2019 * @version 1.3.1.0, Apr 13, 2019
* @since 0.3.5 * @since 0.3.5
*/ */
@Service @Service
...@@ -299,11 +299,10 @@ public class ArticleMgmtService { ...@@ -299,11 +299,10 @@ public class ArticleMgmtService {
final String articleAbstractText = Article.getAbstractText(article); final String articleAbstractText = Article.getAbstractText(article);
article.put(ARTICLE_ABSTRACT_TEXT, articleAbstractText); article.put(ARTICLE_ABSTRACT_TEXT, articleAbstractText);
// Update final boolean postToCommunity = article.optBoolean(Common.POST_TO_COMMUNITY);
final boolean postToCommunity = article.optBoolean(Common.POST_TO_COMMUNITY, true); article.remove(Common.POST_TO_COMMUNITY);
article.remove(Common.POST_TO_COMMUNITY); // Do not persist this property
articleRepository.update(articleId, article); articleRepository.update(articleId, article);
article.put(Common.POST_TO_COMMUNITY, postToCommunity); // Restores the property article.put(Common.POST_TO_COMMUNITY, postToCommunity);
final boolean publishNewArticle = Article.ARTICLE_STATUS_C_DRAFT == oldArticle.optInt(ARTICLE_STATUS) && Article.ARTICLE_STATUS_C_PUBLISHED == article.optInt(ARTICLE_STATUS); final boolean publishNewArticle = Article.ARTICLE_STATUS_C_DRAFT == oldArticle.optInt(ARTICLE_STATUS) && Article.ARTICLE_STATUS_C_PUBLISHED == article.optInt(ARTICLE_STATUS);
final JSONObject eventData = new JSONObject(); final JSONObject eventData = new JSONObject();
...@@ -362,34 +361,12 @@ public class ArticleMgmtService { ...@@ -362,34 +361,12 @@ public class ArticleMgmtService {
try { try {
final JSONObject article = requestJSONObject.getJSONObject(Article.ARTICLE); final JSONObject article = requestJSONObject.getJSONObject(Article.ARTICLE);
final String ret = addArticleInternal(article); String ret = article.optString(Keys.OBJECT_ID);
transaction.commit(); if (StringUtils.isBlank(ret)) {
ret = Ids.genTimeMillisId();
return ret; article.put(Keys.OBJECT_ID, ret);
} catch (final Exception e) {
if (transaction.isActive()) {
transaction.rollback();
} }
throw new ServiceException(e.getMessage());
}
}
/**
* Adds the specified article for internal invocation purposes.
*
* @param article the specified article
* @return generated article id
* @throws ServiceException service exception
*/
public String addArticleInternal(final JSONObject article) throws ServiceException {
String ret = article.optString(Keys.OBJECT_ID);
if (StringUtils.isBlank(ret)) {
ret = Ids.genTimeMillisId();
article.put(Keys.OBJECT_ID, ret);
}
try {
String tagsString = article.optString(Article.ARTICLE_TAGS_REF); String tagsString = article.optString(Article.ARTICLE_TAGS_REF);
tagsString = Tag.formatTags(tagsString); tagsString = Tag.formatTags(tagsString);
if (StringUtils.isBlank(tagsString)) { if (StringUtils.isBlank(tagsString)) {
...@@ -425,27 +402,26 @@ public class ArticleMgmtService { ...@@ -425,27 +402,26 @@ public class ArticleMgmtService {
final String articleAbstractText = Article.getAbstractText(article); final String articleAbstractText = Article.getAbstractText(article);
article.put(ARTICLE_ABSTRACT_TEXT, articleAbstractText); article.put(ARTICLE_ABSTRACT_TEXT, articleAbstractText);
final boolean postToCommunity = article.optBoolean(Common.POST_TO_COMMUNITY, true); final boolean postToCommunity = article.optBoolean(Common.POST_TO_COMMUNITY);
article.remove(Common.POST_TO_COMMUNITY); // Do not persist this property article.remove(Common.POST_TO_COMMUNITY);
articleRepository.add(article); articleRepository.add(article);
transaction.commit();
article.put(Common.POST_TO_COMMUNITY, postToCommunity); // Restores the property article.put(Common.POST_TO_COMMUNITY, postToCommunity);
if (Article.ARTICLE_STATUS_C_PUBLISHED == article.optInt(ARTICLE_STATUS)) { if (Article.ARTICLE_STATUS_C_PUBLISHED == article.optInt(ARTICLE_STATUS)) {
final JSONObject eventData = new JSONObject(); final JSONObject eventData = new JSONObject();
eventData.put(Article.ARTICLE, article); eventData.put(Article.ARTICLE, article);
eventManager.fireEventAsynchronously(new Event<>(EventTypes.ADD_ARTICLE, eventData)); eventManager.fireEventAsynchronously(new Event<>(EventTypes.ADD_ARTICLE, eventData));
} }
article.remove(Common.POST_TO_COMMUNITY); return ret;
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.ERROR, "Adds an article failed", e); if (transaction.isActive()) {
transaction.rollback();
}
throw new ServiceException(e); throw new ServiceException(e.getMessage());
} }
return ret;
} }
/** /**
......
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