Commit c72aac50 authored by Liang Ding's avatar Liang Ding

Fix #12040

parent a37c0763
<?xml version="1.0" encoding="UTF-8"?>
<!--
Description: Solo POM.
Version: 2.6.1.7, Oct 25, 2015
Version: 2.7.1.7, Nov 5, 2015
Author: Liang Ding
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
......@@ -12,7 +12,7 @@
<artifactId>solo</artifactId>
<packaging>war</packaging>
<name>Solo</name>
<version>1.1.0</version>
<version>1.2.0</version>
<description>
A Java blogging system, feel free to create your or your team own blog.
</description>
......
......@@ -47,6 +47,7 @@ import org.b3log.solo.repository.PreferenceRepository;
import org.b3log.solo.repository.impl.PreferenceRepositoryImpl;
import org.b3log.solo.service.PreferenceMgmtService;
import org.b3log.solo.service.StatisticMgmtService;
import org.b3log.solo.service.UpgradeService;
import org.b3log.solo.util.Skins;
import org.json.JSONObject;
......@@ -54,7 +55,7 @@ import org.json.JSONObject;
* Solo Servlet listener.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.5.0.9, Oct 31, 2015
* @version 1.6.0.9, Nov 5, 2015
* @since 0.3.1
*/
public final class SoloServletListener extends AbstractServletListener {
......@@ -62,7 +63,7 @@ public final class SoloServletListener extends AbstractServletListener {
/**
* Solo version.
*/
public static final String VERSION = "1.1.0";
public static final String VERSION = "1.2.0";
/**
* Logger.
......@@ -114,6 +115,10 @@ public final class SoloServletListener extends AbstractServletListener {
beanManager = Lifecycle.getBeanManager();
Stopwatchs.start("Context Initialized");
// Upgrade check (https://github.com/b3log/solo/issues/12040)
final UpgradeService upgradeService = beanManager.getReference(UpgradeService.class);
upgradeService.upgrade();
// Set default skin, loads from preference later
Skins.setDirectoryForTemplateLoading(Preference.Default.DEFAULT_SKIN_DIR_NAME);
......
......@@ -15,7 +15,6 @@
*/
package org.b3log.solo.api.symphony;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
......@@ -54,12 +53,11 @@ import org.b3log.solo.util.Comments;
import org.b3log.solo.util.QueryResults;
import org.json.JSONObject;
/**
* Comment receiver (from B3log Symphony).
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.8, Jul 10, 2014
* @version 1.1.0.9, Nov 5, 2015
* @since 0.5.5
*/
@RequestProcessor
......@@ -134,8 +132,7 @@ public class CommentReceiver {
* </pre>
* </p>
*
* @param request the specified http servlet request, for example,
* <pre>
* @param request the specified http servlet request, for example, <pre>
* {
* "comment": {
* "userB3Key": "",
......@@ -157,7 +154,7 @@ public class CommentReceiver {
*/
@RequestProcessing(value = "/apis/symphony/comment", method = HTTPRequestMethod.PUT)
public void addComment(final HttpServletRequest request, final HttpServletResponse response, final HTTPRequestContext context)
throws Exception {
throws Exception {
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
......@@ -210,8 +207,8 @@ public class CommentReceiver {
String commentContent = symphonyCmt.getString(Comment.COMMENT_CONTENT);
commentContent += "<p class='cmtFromSym'><i>该评论同步自 <a href='" + SoloServletListener.B3LOG_SYMPHONY_SERVE_PATH
+ "/article/" + symphonyCmt.optString("commentSymphonyArticleId") + "#" + commentId
+ "' target='_blank'>黑客派</a></i></p>";
+ "/article/" + symphonyCmt.optString("commentSymphonyArticleId") + "#" + commentId
+ "' target='_blank'>黑客派</a></i></p>";
final String originalCommentId = symphonyCmt.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID);
// Step 1: Add comment
final JSONObject comment = new JSONObject();
......@@ -238,14 +235,14 @@ public class CommentReceiver {
comment.put(Comment.COMMENT_ORIGINAL_COMMENT_ID, "");
comment.put(Comment.COMMENT_ORIGINAL_COMMENT_NAME, "");
LOGGER.log(Level.WARN, "Not found orginal comment[id={0}] of reply[name={1}, content={2}]",
new String[] {originalCommentId, commentName, commentContent});
new String[]{originalCommentId, commentName, commentContent});
}
} else {
comment.put(Comment.COMMENT_ORIGINAL_COMMENT_ID, "");
comment.put(Comment.COMMENT_ORIGINAL_COMMENT_NAME, "");
}
CommentMgmtService.setCommentThumbnailURL(comment);
commentMgmtService.setCommentThumbnailURL(comment);
ret.put(Comment.COMMENT_THUMBNAIL_URL, comment.getString(Comment.COMMENT_THUMBNAIL_URL));
// Sets comment on article....
comment.put(Comment.COMMENT_ON_ID, articleId);
......
......@@ -44,6 +44,7 @@ import org.b3log.solo.model.*;
import org.b3log.solo.repository.ArticleRepository;
import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.repository.PageRepository;
import org.b3log.solo.repository.UserRepository;
import org.b3log.solo.util.Comments;
import org.b3log.solo.util.Thumbnails;
import org.json.JSONException;
......@@ -53,7 +54,7 @@ import org.json.JSONObject;
* Comment management service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.6, Oct 1, 2015
* @version 1.1.0.7, Nov 5, 2015
* @since 0.3.5
*/
@Service
......@@ -82,6 +83,12 @@ public class CommentMgmtService {
@Inject
private ArticleRepository articleRepository;
/**
* User repository.
*/
@Inject
private UserRepository userRepository;
/**
* Statistic management service.
*/
......@@ -709,15 +716,31 @@ public class CommentMgmtService {
* Sets commenter thumbnail URL for the specified comment.
*
* <p>
* Try to set thumbnail URL using Gravatar service.
* Try to set thumbnail URL using:
* <ol>
* <li>User avatar</li>
* <li>Gravatar service</li>
* <ol>
* </p>
*
* @param comment the specified comment
* @throws Exception exception
*/
public static void setCommentThumbnailURL(final JSONObject comment) throws Exception {
public void setCommentThumbnailURL(final JSONObject comment) throws Exception {
final String commentEmail = comment.getString(Comment.COMMENT_EMAIL);
// 1. user avatar
final JSONObject user = userRepository.getByEmail(commentEmail);
if (null != user) {
final String avatar = user.optString(UserExt.USER_AVATAR);
if (!Strings.isEmptyOrNull(avatar)) {
comment.put(Comment.COMMENT_THUMBNAIL_URL, avatar);
return;
}
}
// 2. Gravatar
String thumbnailURL = Thumbnails.getGravatarURL(commentEmail.toLowerCase(), "60");
final URL gravatarURL = new URL(thumbnailURL);
......
......@@ -41,6 +41,7 @@ import org.b3log.solo.model.Page;
import org.b3log.solo.repository.ArticleRepository;
import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.repository.PageRepository;
import org.b3log.solo.util.Thumbnails;
import org.json.JSONArray;
import org.json.JSONObject;
......@@ -49,7 +50,7 @@ import org.json.JSONObject;
* Comment query service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.5, Feb 28, 2014
* @version 1.0.0.6, Nov 5, 2015
* @since 0.3.5
*/
@Service
......@@ -242,6 +243,10 @@ public class CommentQueryService {
comment.put(Comment.COMMENT_NAME, StringEscapeUtils.escapeHtml(comment.getString(Comment.COMMENT_NAME)));
comment.put(Comment.COMMENT_URL, StringEscapeUtils.escapeHtml(comment.getString(Comment.COMMENT_URL)));
comment.put(Common.IS_REPLY, false); // Assumes this comment is not a reply
final String email = comment.optString(Comment.COMMENT_EMAIL);
comment.put(Comment.COMMENT_THUMBNAIL_URL, Thumbnails.getGravatarURL(email, "60"));
if (!Strings.isEmptyOrNull(comment.optString(Comment.COMMENT_ORIGINAL_COMMENT_ID))) {
// This comment is a reply
......
......@@ -13,48 +13,47 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.processor;
package org.b3log.solo.service;
import java.io.IOException;
import java.sql.Connection;
import java.sql.Statement;
import javax.inject.Inject;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.mail.MailService;
import org.b3log.latke.mail.MailServiceFactory;
import org.b3log.latke.model.User;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.jdbc.util.Connections;
import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.service.ServiceException;
import org.b3log.latke.servlet.HTTPRequestContext;
import org.b3log.latke.servlet.HTTPRequestMethod;
import org.b3log.latke.servlet.annotation.RequestProcessing;
import org.b3log.latke.servlet.annotation.RequestProcessor;
import org.b3log.latke.servlet.renderer.TextHTMLRenderer;
import org.b3log.latke.service.annotation.Service;
import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.*;
import org.b3log.solo.repository.*;
import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Thumbnails;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Upgrader.
* Upgrade service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="mailto:dongxu.wang@acm.org">Dongxu Wang</a>
* @version 1.5.1.14, Oct 17, 2015
* @since 0.3.1
* @version 1.0.0.0, Nov 5, 2015
* @since 1.2.0
*/
@RequestProcessor
public class UpgradeProcessor {
@Service
public class UpgradeService {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(UpgradeProcessor.class.getName());
private static final Logger LOGGER = Logger.getLogger(UpgradeService.class.getName());
/**
* Article repository.
......@@ -104,7 +103,7 @@ public class UpgradeProcessor {
/**
* Old version.
*/
private static final String FROM_VER = "1.0.0";
private static final String FROM_VER = "1.1.0";
/**
* New version.
......@@ -113,27 +112,17 @@ public class UpgradeProcessor {
/**
* Checks upgrade.
*
* @param context the specified context
*/
@RequestProcessing(value = "/upgrade/checker.do", method = HTTPRequestMethod.GET)
public void upgrade(final HTTPRequestContext context) {
final TextHTMLRenderer renderer = new TextHTMLRenderer();
context.setRenderer(renderer);
public void upgrade() {
try {
final JSONObject preference = preferenceRepository.get(Preference.PREFERENCE);
if (null == preference) {
LOGGER.log(Level.INFO, "Not init yet");
renderer.setContent("Not init yet");
return;
}
renderer.setContent("Upgrade successfully ;-)");
final String currentVer = preference.getString(Preference.VERSION);
if (SoloServletListener.VERSION.equals(currentVer)) {
......@@ -141,7 +130,7 @@ public class UpgradeProcessor {
}
if (FROM_VER.equals(currentVer)) {
upgrade();
perform();
return;
}
......@@ -154,11 +143,9 @@ public class UpgradeProcessor {
sent = true;
}
renderer.setContent(langPropsService.get("skipVersionAlert"));
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
renderer.setContent(
LOGGER.log(Level.ERROR,
"Upgrade failed [" + e.getMessage() + "], please contact the Solo developers or reports this "
+ "issue directly (<a href='https://github.com/b3log/solo/issues/new'>"
+ "https://github.com/b3log/solo/issues/new</a>) ");
......@@ -166,20 +153,29 @@ public class UpgradeProcessor {
}
/**
* Upgrades.
* Performs upgrade.
*
* @throws Exception upgrade fails
*/
private void upgrade() throws Exception {
private void perform() throws Exception {
LOGGER.log(Level.INFO, "Upgrading from version [{0}] to version [{1}]....", FROM_VER, TO_VER);
Transaction transaction = null;
try {
final Connection connection = Connections.getConnection();
final Statement statement = connection.createStatement();
final String tablePrefix = Latkes.getLocalProperty("jdbc.tablePrefix") + "_";
statement.execute("ALTER TABLE `" + tablePrefix + "user` ADD COLUMN `userAvatar` varchar(255)");
statement.close();
connection.commit();
connection.close();
transaction = userRepository.beginTransaction();
upgradeUsers();
// Upgrades preference model
final JSONObject preference = preferenceRepository.get(Preference.PREFERENCE);
......@@ -221,7 +217,7 @@ public class UpgradeProcessor {
userRepository.update(user.optString(Keys.OBJECT_ID), user);
LOGGER.log(Level.INFO, "Updated user[name={0}]");
LOGGER.log(Level.INFO, "Updated user[email={0}]", email);
}
}
......
......@@ -16,12 +16,12 @@
#
# Description: B3log configurations.
# Version: 1.2.0.0, May 19, 2015
# Version: 1.2.0.0, Nov 5, 2015
# Author: Liang Ding
#
rhythm.servePath=http://rhythm.b3log.org:80
symphony.servePath=http://hacpai.com:80
gravatar=http://gravatar.duoshuo.com/avatar/
gravatar=https://secure.gravatar.com/avatar/
faviconAPI=http://api.byi.pw/favicon?url=
\ No newline at end of file
......@@ -16,7 +16,7 @@
#
# Description: Solo logging configurations.
# Version: 1.1.0.3, Oct 31, 2015
# Version: 1.1.0.4, Nov 5, 2015
# Author: Liang Ding
#
......@@ -34,3 +34,4 @@ log4j.logger.org.b3log.latke.util.freemarker.Templates=ERROR
log4j.logger.org.eclipse.jetty=WARN
log4j.logger.freemarker=WARN
log4j.logger.com.mchange=WARN
......@@ -20,12 +20,12 @@
Description: Web deployment descriptor on GAE. See
http://code.google.com/intl/en/appengine/docs/java/config/appconfig.html
for more details.
Version: 1.4.5.6, Oct 1, 2015
Version: 1.5.5.6, Nov 5, 2015
Author: Liang Ding
-->
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>solo-demo</application>
<version>110</version>
<version>120</version>
<sessions-enabled>true</sessions-enabled>
......
......@@ -18,17 +18,11 @@
-->
<!--
Description: Cron job configurations.
Version: 1.0.1.4, Feb 11, 2015
Version: 1.0.1.5, Nov 5, 2015
Author: Liang Ding
-->
<cronentries>
<cron>
<url>/upgrade/checker.do</url>
<description>Upgrade checker, see issue 257 (http://code.google.com/p/b3log-solo/issues/detail?id=257).</description>
<schedule>every 60 minutes</schedule>
</cron>
<cron>
<url>/console/stat/onlineVisitorRefresh</url>
<description>Online Visitor Refresher</description>
......@@ -40,12 +34,5 @@
<description>Sync user to http://hacpai.com</description>
<schedule>every 24 hours</schedule>
</cron>
<!-- http://code.google.com/p/b3log-solo/issues/detail?id=308#c4
<cron>
<url>/article-random-double-gen.do?cnt=10</url>
<description>Regenerate article random double.</description>
<schedule>every 1 hours</schedule>
</cron>
-->
</cronentries>
This diff is collapsed.
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