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

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

#12757
parent c454b7be
......@@ -48,7 +48,7 @@ import org.json.JSONObject;
*
* @author <a href="http://88250.b3log.org">Liang Ding</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
*/
@Singleton
......@@ -95,7 +95,7 @@ public class B3ArticleSender extends AbstractEventListener<JSONObject> {
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);
return;
......
......@@ -51,7 +51,7 @@ import static org.b3log.solo.model.Article.*;
* Article management service.
*
* @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
*/
@Service
......@@ -299,11 +299,10 @@ public class ArticleMgmtService {
final String articleAbstractText = Article.getAbstractText(article);
article.put(ARTICLE_ABSTRACT_TEXT, articleAbstractText);
// Update
final boolean postToCommunity = article.optBoolean(Common.POST_TO_COMMUNITY, true);
article.remove(Common.POST_TO_COMMUNITY); // Do not persist this property
final boolean postToCommunity = article.optBoolean(Common.POST_TO_COMMUNITY);
article.remove(Common.POST_TO_COMMUNITY);
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 JSONObject eventData = new JSONObject();
......@@ -362,34 +361,12 @@ public class ArticleMgmtService {
try {
final JSONObject article = requestJSONObject.getJSONObject(Article.ARTICLE);
final String ret = addArticleInternal(article);
transaction.commit();
return 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);
tagsString = Tag.formatTags(tagsString);
if (StringUtils.isBlank(tagsString)) {
......@@ -425,27 +402,26 @@ public class ArticleMgmtService {
final String articleAbstractText = Article.getAbstractText(article);
article.put(ARTICLE_ABSTRACT_TEXT, articleAbstractText);
final boolean postToCommunity = article.optBoolean(Common.POST_TO_COMMUNITY, true);
article.remove(Common.POST_TO_COMMUNITY); // Do not persist this property
final boolean postToCommunity = article.optBoolean(Common.POST_TO_COMMUNITY);
article.remove(Common.POST_TO_COMMUNITY);
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)) {
final JSONObject eventData = new JSONObject();
eventData.put(Article.ARTICLE, article);
eventManager.fireEventAsynchronously(new Event<>(EventTypes.ADD_ARTICLE, eventData));
}
article.remove(Common.POST_TO_COMMUNITY);
return ret;
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Adds an article failed", e);
throw new ServiceException(e);
if (transaction.isActive()) {
transaction.rollback();
}
return ret;
throw new ServiceException(e.getMessage());
}
}
/**
......
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