Commit 1e9e17b2 authored by Liang Ding's avatar Liang Ding

跨版本升级提示文案修改

1. 跨版本升级提示文案修改
2. 源文件加入 DX 为作者,修改文件版本号
parent 92e78f1e
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.processor;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.b3log.latke.Keys;
import org.b3log.latke.annotation.RequestProcessing;
import org.b3log.latke.annotation.RequestProcessor;
import org.b3log.latke.mail.MailService;
import org.b3log.latke.mail.MailServiceFactory;
import org.b3log.latke.repository.*;
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.renderer.TextHTMLRenderer;
import org.b3log.latke.taskqueue.TaskQueueService;
import org.b3log.latke.taskqueue.TaskQueueServiceFactory;
import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.*;
import org.b3log.solo.repository.*;
import org.b3log.solo.repository.impl.*;
import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Upgrader.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.1.1.2, Aug 16, 2012
* @since 0.3.1
*/
@RequestProcessor
public final class UpgradeProcessor {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(UpgradeProcessor.class.getName());
/**
* Article repository.
*/
private ArticleRepository articleRepository = ArticleRepositoryImpl.getInstance();
/**
* Page repository.
*/
private PageRepository pageRepository = PageRepositoryImpl.getInstance();
/**
* User repository.
*/
private UserRepository userRepository = UserRepositoryImpl.getInstance();
/**
* Preference repository.
*/
private PreferenceRepository preferenceRepository = PreferenceRepositoryImpl.getInstance();
/**
* Task queue service.
*/
private TaskQueueService taskQueueService = TaskQueueServiceFactory.getTaskQueueService();
/**
* Step for article updating.
*/
private static final int STEP = 50;
/**
* Preference Query Service.
*/
private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance();
/**
* Mail Service.
*/
private static final MailService MAIL_SVC = MailServiceFactory.getMailService();
/**
* Whether the email has been sent.
*/
private boolean sent = false;
/**
* Language service.
*/
private static LangPropsService langPropsService = LangPropsService.getInstance();
/**
* 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);
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 version = preference.getString(Preference.VERSION);
if (SoloServletListener.VERSION.equals(version)) {
return;
}
if ("0.4.6".equals(version)) {
v046ToV050();
} else {
LOGGER.log(Level.WARNING, "Attempt to skip more than one version to upgrade. Expected: 0.4.6; Actually: {0}", version);
if(!sent){
notifyUserByEmail();
sent = true;
}
renderer.setContent(langPropsService.get("skipVersionAlert"));
}
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
renderer.setContent("Upgrade failed [" + e.getMessage() + "], please contact the B3log Solo developers or reports this "
+ "issue directly (https://github.com/b3log/b3log-solo/issues/new) ");
}
}
/**
* Upgrades from version 046 to version 050.
*
* @throws Exception upgrade fails
*/
private void v046ToV050() throws Exception {
LOGGER.info("Upgrading from version 046 to version 050....");
articleRepository.setCacheEnabled(false);
Transaction transaction = null;
try {
transaction = userRepository.beginTransaction();
// Upgrades preference model
final JSONObject preference = preferenceRepository.get(Preference.PREFERENCE);
preference.put(Preference.VERSION, "0.5.0");
preferenceRepository.update(Preference.PREFERENCE, preference);
LOGGER.log(Level.FINEST, "Updated preference");
transaction.commit();
} catch (final Exception e) {
if (transaction.isActive()) {
transaction.rollback();
}
LOGGER.log(Level.SEVERE, "Upgrade failed.", e);
throw new Exception("Upgrade failed from version 046 to version 050");
} finally {
articleRepository.setCacheEnabled(true);
}
LOGGER.info("Upgraded from version 046 to version 050 successfully :-)");
}
/**
* Upgrades articles.
*
* @throws Exception exception
*/
private void upgradeArticles() throws Exception {
LOGGER.log(Level.INFO, "Adds a property [articleEditorType] to each of articles");
final JSONArray articles = articleRepository.get(new Query()).getJSONArray(Keys.RESULTS);
if (articles.length() <= 0) {
LOGGER.log(Level.FINEST, "No articles");
return;
}
Transaction transaction = null;
try {
for (int i = 0; i < articles.length(); i++) {
if (0 == i % STEP || !transaction.isActive()) {
transaction = userRepository.beginTransaction();
}
final JSONObject article = articles.getJSONObject(i);
final String articleId = article.optString(Keys.OBJECT_ID);
LOGGER.log(Level.INFO, "Found an article[id={0}]", articleId);
article.put(Article.ARTICLE_EDITOR_TYPE, "tinyMCE");
articleRepository.update(article.getString(Keys.OBJECT_ID), article);
if (0 == i % STEP) {
transaction.commit();
LOGGER.log(Level.FINEST, "Updated some articles");
}
}
if (transaction.isActive()) {
transaction.commit();
}
LOGGER.log(Level.FINEST, "Updated all articles");
} catch (final Exception e) {
if (transaction.isActive()) {
transaction.rollback();
}
throw e;
}
}
/**
* Send an email to the user who upgrades B3log Solo with a discontinuous version.
*
* @throws ServiceException ServiceException
* @throws JSONException JSONException
* @throws IOException IOException
*/
private void notifyUserByEmail() throws ServiceException, JSONException, IOException {
final String adminEmail = preferenceQueryService.getPreference().getString(Preference.ADMIN_EMAIL);
final MailService.Message message = new MailService.Message();
message.setFrom(adminEmail);
message.addRecipient(adminEmail);
message.setSubject(langPropsService.get("skipVersionMailSubject"));
message.setHtmlBody(langPropsService.get("skipVersionMailBody"));
MAIL_SVC.send(message);
LOGGER.info("Send an email to the user who upgrades B3log Solo with a discontinuous version.");
}
}
/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.processor;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.b3log.latke.Keys;
import org.b3log.latke.annotation.RequestProcessing;
import org.b3log.latke.annotation.RequestProcessor;
import org.b3log.latke.mail.MailService;
import org.b3log.latke.mail.MailServiceFactory;
import org.b3log.latke.repository.*;
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.renderer.TextHTMLRenderer;
import org.b3log.latke.taskqueue.TaskQueueService;
import org.b3log.latke.taskqueue.TaskQueueServiceFactory;
import org.b3log.solo.SoloServletListener;
import org.b3log.solo.model.*;
import org.b3log.solo.repository.*;
import org.b3log.solo.repository.impl.*;
import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Upgrader.
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @author <a href="mailto:dongxv.vang@gmail.com">Dongxu Wang</a>
* @version 1.1.1.3, Aug 30, 2012
* @since 0.3.1
*/
@RequestProcessor
public final class UpgradeProcessor {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(UpgradeProcessor.class.getName());
/**
* Article repository.
*/
private ArticleRepository articleRepository = ArticleRepositoryImpl.getInstance();
/**
* Page repository.
*/
private PageRepository pageRepository = PageRepositoryImpl.getInstance();
/**
* User repository.
*/
private UserRepository userRepository = UserRepositoryImpl.getInstance();
/**
* Preference repository.
*/
private PreferenceRepository preferenceRepository = PreferenceRepositoryImpl.getInstance();
/**
* Task queue service.
*/
private TaskQueueService taskQueueService = TaskQueueServiceFactory.getTaskQueueService();
/**
* Step for article updating.
*/
private static final int STEP = 50;
/**
* Preference Query Service.
*/
private PreferenceQueryService preferenceQueryService = PreferenceQueryService.getInstance();
/**
* Mail Service.
*/
private static final MailService MAIL_SVC = MailServiceFactory.getMailService();
/**
* Whether the email has been sent.
*/
private boolean sent = false;
/**
* Language service.
*/
private static LangPropsService langPropsService = LangPropsService.getInstance();
/**
* 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);
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 version = preference.getString(Preference.VERSION);
if (SoloServletListener.VERSION.equals(version)) {
return;
}
if ("0.4.6".equals(version)) {
v046ToV050();
} else {
LOGGER.log(Level.WARNING, "Attempt to skip more than one version to upgrade. Expected: 0.4.6; Actually: {0}", version);
if(!sent){
notifyUserByEmail();
sent = true;
}
renderer.setContent(langPropsService.get("skipVersionAlert"));
}
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
renderer.setContent("Upgrade failed [" + e.getMessage() + "], please contact the B3log Solo developers or reports this "
+ "issue directly (https://github.com/b3log/b3log-solo/issues/new) ");
}
}
/**
* Upgrades from version 046 to version 050.
*
* @throws Exception upgrade fails
*/
private void v046ToV050() throws Exception {
LOGGER.info("Upgrading from version 046 to version 050....");
articleRepository.setCacheEnabled(false);
Transaction transaction = null;
try {
transaction = userRepository.beginTransaction();
// Upgrades preference model
final JSONObject preference = preferenceRepository.get(Preference.PREFERENCE);
preference.put(Preference.VERSION, "0.5.0");
preferenceRepository.update(Preference.PREFERENCE, preference);
LOGGER.log(Level.FINEST, "Updated preference");
transaction.commit();
} catch (final Exception e) {
if (transaction.isActive()) {
transaction.rollback();
}
LOGGER.log(Level.SEVERE, "Upgrade failed.", e);
throw new Exception("Upgrade failed from version 046 to version 050");
} finally {
articleRepository.setCacheEnabled(true);
}
LOGGER.info("Upgraded from version 046 to version 050 successfully :-)");
}
/**
* Upgrades articles.
*
* @throws Exception exception
*/
private void upgradeArticles() throws Exception {
LOGGER.log(Level.INFO, "Adds a property [articleEditorType] to each of articles");
final JSONArray articles = articleRepository.get(new Query()).getJSONArray(Keys.RESULTS);
if (articles.length() <= 0) {
LOGGER.log(Level.FINEST, "No articles");
return;
}
Transaction transaction = null;
try {
for (int i = 0; i < articles.length(); i++) {
if (0 == i % STEP || !transaction.isActive()) {
transaction = userRepository.beginTransaction();
}
final JSONObject article = articles.getJSONObject(i);
final String articleId = article.optString(Keys.OBJECT_ID);
LOGGER.log(Level.INFO, "Found an article[id={0}]", articleId);
article.put(Article.ARTICLE_EDITOR_TYPE, "tinyMCE");
articleRepository.update(article.getString(Keys.OBJECT_ID), article);
if (0 == i % STEP) {
transaction.commit();
LOGGER.log(Level.FINEST, "Updated some articles");
}
}
if (transaction.isActive()) {
transaction.commit();
}
LOGGER.log(Level.FINEST, "Updated all articles");
} catch (final Exception e) {
if (transaction.isActive()) {
transaction.rollback();
}
throw e;
}
}
/**
* Send an email to the user who upgrades B3log Solo with a discontinuous version.
*
* @throws ServiceException ServiceException
* @throws JSONException JSONException
* @throws IOException IOException
*/
private void notifyUserByEmail() throws ServiceException, JSONException, IOException {
final String adminEmail = preferenceQueryService.getPreference().getString(Preference.ADMIN_EMAIL);
final MailService.Message message = new MailService.Message();
message.setFrom(adminEmail);
message.addRecipient(adminEmail);
message.setSubject(langPropsService.get("skipVersionMailSubject"));
message.setHtmlBody(langPropsService.get("skipVersionMailBody"));
MAIL_SVC.send(message);
LOGGER.info("Send an email to the user who upgrades B3log Solo with a discontinuous version.");
}
}
......@@ -16,9 +16,10 @@
#
# Description: B3log Solo language configurations(en_US).
# Version: 2.0.9.4, Aug 14, 2012
# Version: 2.0.9.5, Aug 30, 2012
# Author: Liang Ding
# Author: Liyuan Li
# Author: Dongxu Wang
#
staticErrorLabel=staticServePath Error, https://github.com/b3log/b3log-solo/wiki/Deploy_gae
......@@ -334,6 +335,7 @@ confirmInitLabel=Are You Sure?
b3logLabel=<span style="color: orange;">B</span><span style="color: blue;"><sup>3</sup></span><span style="color: green;">L</span><span style="color: red;">O</span><span style="color: blue;">G</span>
mobileLabel=Mobile Theme
# Send an email to the user who upgrades B3log Solo with a discontinuous version #
skipVersionMailSubject=[no-reply]Better not to skip more than one version to upgrade b3log
skipVersionMailBody=Hey, sorry for any inconvenience caused. If your B3log Solo is too old to upgrade, developers in <a href="https://github.com/b3log/b3log-solo/wiki" target="_blank">B3log</a> are more than welcome to help, thank you.<p><a href="http://b3log.org" target="_blank">B3log</a>
skipVersionMailSubject=[no-reply]Better not to skip more than one version to upgrade B3log Solo
skipVersionMailBody=Hey, sorry for any inconvenience caused. If your B3log Solo is too old to upgrade, \
developers in <a href="http://b3log.org" target="_blank">B3log</a> are more than welcome to help, thank you.
skipVersionAlert=Your B3log Solo is too old to upgrade, please contact the B3log Solo's developers.
......@@ -16,9 +16,10 @@
#
# Description: B3log Solo default language configurations(zh_CN).
# Version: 2.1.0.0, Aug 14, 2012
# Version: 2.1.0.1, Aug 30, 2012
# Author: Liang Ding
# Author: Liyuan Li
# Author: Dongxu Wang
#
staticErrorLabel=staticServePath \u914d\u7f6e\u9519\u8bef\uff0c\u8bf7\u67e5\u770b https://github.com/b3log/b3log-solo/wiki/Deploy_gae
......@@ -334,6 +335,7 @@ confirmInitLabel=\u786e\u5b9a\u8fdb\u884c\u521d\u59cb\u5316\u5417\uff1f
b3logLabel=<span style="color: orange;">B</span><span style="color: blue;"><sup>3</sup></span><span style="color: green;">L</span><span style="color: red;">O</span><span style="color: blue;">G</span>
mobileLabel=\u79fb\u52a8\u7248
# Send an email to the user who upgrades B3log Solo with a discontinuous version #
skipVersionMailSubject=[\u65e0\u9700\u56de\u590d]\u8de8\u7248\u672c\u5347\u7ea7B3log Solo\u63d0\u9192
skipVersionMailBody=Hey, \u60a8\u597d<p>\u975e\u5e38\u9ad8\u5174\u60a8\u51c6\u5907\u5347\u7ea7B3log Solo\uff0c\u4e0d\u8fc7\u76ee\u524d\u8fd8\u4e0d\u652f\u6301\u8de8\u7248\u672c\u5347\u7ea7\u3002\u8bf7\u6309\u7167<a href="https://github.com/b3log/b3log-solo/wiki" target="_blank">\u8bf4\u660e\u6587\u6863</a>\u8fdb\u884c\u5347\u7ea7\u3002\u5bf9\u6b64\u7ed9\u60a8\u5e26\u6765\u7684\u4e0d\u4fbf\u6211\u4eec\u6df1\u8868\u6b49\u610f\uff0c\u8c22\u8c22\u60a8\u5bf9B3log\u56e2\u961f\u7684\u652f\u6301\u3002<p><a href="http://b3log.org" target="_blank">B3log</a>
skipVersionAlert=\u5bf9\u4e0d\u8d77\uff0cB3log Solo\u76ee\u524d\u8fd8\u4e0d\u652f\u6301\u8de8\u7248\u672c\u5347\u7ea7\u3002\u8bf7\u6309\u7167<a href="https://github.com/b3log/b3log-solo/wiki" target="_blank">\u8bf4\u660e\u6587\u6863</a>\u8fdb\u884c\u5347\u7ea7\uff0c\u6216\u76f4\u63a5\u8054\u7cfbB3log\u5f00\u53d1\u8005\u3002
skipVersionMailSubject=[\u65e0\u9700\u56de\u590d]\u8de8\u7248\u672c\u5347\u7ea7 B3log Solo \u63d0\u9192
skipVersionMailBody=Hey, \u60a8\u597d\uff01<p>\u975e\u5e38\u9ad8\u5174\u60a8\u51c6\u5907\u5347\u7ea7 B3log Solo\uff0c\u4e0d\u8fc7\u76ee\u524d\u8fd8\u4e0d\u652f\u6301\u8de8\u7248\u672c\u5347\u7ea7\uff0c\u8bf7\u6309\u7167\u5386\u53f2\u7248\u672c\u4f9d\u6b21\u8fdb\u884c\u5347\u7ea7\u3002</p>\
<p>\u5bf9\u6b64\u7ed9\u60a8\u5e26\u6765\u7684\u4e0d\u4fbf\u6211\u4eec\u6df1\u8868\u6b49\u610f\uff0c\u8c22\u8c22\u60a8\u5bf9 <a href="http://b3log.org" target="_blank">B3log</a> \u7684\u652f\u6301\u3002</p>
skipVersionAlert=\u5bf9\u4e0d\u8d77\uff0cB3log Solo \u76ee\u524d\u8fd8\u4e0d\u652f\u6301\u8de8\u7248\u672c\u5347\u7ea7\uff0c\u8bf7\u6309\u7167\u5386\u53f2\u7248\u672c\u4f9d\u6b21\u8fdb\u884c\u5347\u7ea7\uff0c\u6216\u76f4\u63a5\u8054\u7cfb B3log \u5f00\u53d1\u8005\u3002
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