Commit 7da94004 authored by Liang Ding's avatar Liang Ding

#12725

parent e18a7a02
...@@ -58,7 +58,7 @@ import javax.servlet.http.HttpSessionEvent; ...@@ -58,7 +58,7 @@ import javax.servlet.http.HttpSessionEvent;
* Solo Servlet listener. * Solo Servlet listener.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.10.0.11, Mar 17, 2019 * @version 1.10.0.12, Mar 20, 2019
* @since 0.3.1 * @since 0.3.1
*/ */
public final class SoloServletListener extends AbstractServletListener { public final class SoloServletListener extends AbstractServletListener {
...@@ -403,7 +403,9 @@ public final class SoloServletListener extends AbstractServletListener { ...@@ -403,7 +403,9 @@ public final class SoloServletListener extends AbstractServletListener {
final TagConsole tagConsole = beanManager.getReference(TagConsole.class); final TagConsole tagConsole = beanManager.getReference(TagConsole.class);
DispatcherServlet.get("/console/tags", tagConsole::getTags); DispatcherServlet.get("/console/tags", tagConsole::getTags);
DispatcherServlet.get("/console/tag/unused", tagConsole::getUnusedTags); DispatcherServlet.get("/console/tag/unused", tagConsole::getUnusedTags);
DispatcherServlet.delete("/console/tag/unused", tagConsole::removeUnusedTags);
final OtherConsole otherConsole = beanManager.getReference(OtherConsole.class);
DispatcherServlet.delete("/console/archive/unused", otherConsole::removeUnusedArchives);
final UserConsole userConsole = beanManager.getReference(UserConsole.class); final UserConsole userConsole = beanManager.getReference(UserConsole.class);
DispatcherServlet.put("/console/user/", userConsole::updateUser); DispatcherServlet.put("/console/user/", userConsole::updateUser);
......
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.processor.console;
import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.servlet.RequestContext;
import org.b3log.latke.servlet.annotation.Before;
import org.b3log.latke.servlet.annotation.RequestProcessor;
import org.b3log.latke.servlet.renderer.JsonRenderer;
import org.b3log.solo.service.ArchiveDateMgmtService;
import org.b3log.solo.service.TagMgmtService;
import org.json.JSONObject;
/**
* Other console request processing.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Mar 20, 2019
* @since 3.4.0
*/
@RequestProcessor
public class OtherConsole {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(OtherConsole.class);
/**
* Tag management service.
*/
@Inject
private TagMgmtService tagMgmtService;
/**
* ArchiveDate maangement service.
*/
@Inject
private ArchiveDateMgmtService archiveDateMgmtService;
/**
* Language service.
*/
@Inject
private LangPropsService langPropsService;
/**
* Removes all unused archives.
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "msg": ""
* }
* </pre>
* </p>
*
* @param context the specified request context
*/
@Before(ConsoleAdminAuthAdvice.class)
public void removeUnusedArchives(final RequestContext context) {
final JsonRenderer renderer = new JsonRenderer();
context.setRenderer(renderer);
final JSONObject jsonObject = new JSONObject();
renderer.setJSONObject(jsonObject);
try {
archiveDateMgmtService.removeUnusedArchiveDates();
jsonObject.put(Keys.STATUS_CODE, true);
jsonObject.put(Keys.MSG, langPropsService.get("removeSuccLabel"));
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Removes unused archives failed", e);
jsonObject.put(Keys.MSG, langPropsService.get("removeFailLabel"));
}
}
/**
* Removes all unused tags.
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "msg": ""
* }
* </pre>
* </p>
*
* @param context the specified request context
*/
@Before(ConsoleAdminAuthAdvice.class)
public void removeUnusedTags(final RequestContext context) {
final JsonRenderer renderer = new JsonRenderer();
context.setRenderer(renderer);
final JSONObject jsonObject = new JSONObject();
renderer.setJSONObject(jsonObject);
try {
tagMgmtService.removeUnusedTags();
jsonObject.put(Keys.STATUS_CODE, true);
jsonObject.put(Keys.MSG, langPropsService.get("removeSuccLabel"));
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Removes unused tags failed", e);
jsonObject.put(Keys.MSG, langPropsService.get("removeFailLabel"));
}
}
}
...@@ -56,18 +56,6 @@ public class TagConsole { ...@@ -56,18 +56,6 @@ public class TagConsole {
@Inject @Inject
private TagQueryService tagQueryService; private TagQueryService tagQueryService;
/**
* Tag management service.
*/
@Inject
private TagMgmtService tagMgmtService;
/**
* Language service.
*/
@Inject
private LangPropsService langPropsService;
/** /**
* Gets all tags. * Gets all tags.
* <p> * <p>
...@@ -148,36 +136,4 @@ public class TagConsole { ...@@ -148,36 +136,4 @@ public class TagConsole {
jsonObject.put(Keys.STATUS_CODE, false); jsonObject.put(Keys.STATUS_CODE, false);
} }
} }
/**
* Removes all unused tags.
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "msg": ""
* }
* </pre>
* </p>
*
* @param context the specified request context
*/
@Before(ConsoleAdminAuthAdvice.class)
public void removeUnusedTags(final RequestContext context) {
final JsonRenderer renderer = new JsonRenderer();
context.setRenderer(renderer);
final JSONObject jsonObject = new JSONObject();
renderer.setJSONObject(jsonObject);
try {
tagMgmtService.removeUnusedTags();
jsonObject.put(Keys.STATUS_CODE, true);
jsonObject.put(Keys.MSG, langPropsService.get("removeSuccLabel"));
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Removes unused tags failed", e);
jsonObject.put(Keys.MSG, langPropsService.get("removeFailLabel"));
}
}
} }
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.service;
import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.repository.RepositoryException;
import org.b3log.latke.repository.Transaction;
import org.b3log.latke.service.annotation.Service;
import org.b3log.solo.model.ArchiveDate;
import org.b3log.solo.repository.ArchiveDateArticleRepository;
import org.b3log.solo.repository.ArchiveDateRepository;
import org.json.JSONObject;
import java.util.List;
/**
* Archive date query service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Mar 20, 2019
* @since 3.4.0
*/
@Service
public class ArchiveDateMgmtService {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(ArchiveDateMgmtService.class);
/**
* Archive date repository.
*/
@Inject
private ArchiveDateRepository archiveDateRepository;
/**
* Archive date-Article repository.
*/
@Inject
private ArchiveDateArticleRepository archiveDateArticleRepository;
/**
* Removes all unused archive dates.
*
* @return a list of archive dates, returns an empty list if not found
*/
public void removeUnusedArchiveDates() {
final Transaction transaction = archiveDateRepository.beginTransaction();
try {
final List<JSONObject> archiveDates = archiveDateRepository.getArchiveDates();
for (final JSONObject archiveDate : archiveDates) {
if (1 > archiveDate.optInt(ArchiveDate.ARCHIVE_DATE_T_PUBLISHED_ARTICLE_COUNT)) {
final String archiveDateId = archiveDate.optString(Keys.OBJECT_ID);
archiveDateRepository.remove(archiveDateId);
}
}
transaction.commit();
} catch (final RepositoryException e) {
if (transaction.isActive()) {
transaction.rollback();
}
LOGGER.log(Level.ERROR, "Gets archive dates failed", e);
}
}
}
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
# Author: Dongxu Wang # Author: Dongxu Wang
# #
removeUnusedArchivesLabel=Remove Unused Archives
syncGitHubLabel=<a href="https://github.com/b3log/solo/issues/12676" target="_blank">Allow sync GitHub repo</a>: syncGitHubLabel=<a href="https://github.com/b3log/solo/issues/12676" target="_blank">Allow sync GitHub repo</a>:
queryUserFailedLabel=Query user info failed queryUserFailedLabel=Query user info failed
commentContentLabel=Content commentContentLabel=Content
...@@ -33,7 +34,7 @@ pushSuccLabel=Sync Successful ...@@ -33,7 +34,7 @@ pushSuccLabel=Sync Successful
pushToHacpaiLabel=Sync to Hacpai pushToHacpaiLabel=Sync to Hacpai
getUploadTokenErrLabel=Get community file storage service upload token failed getUploadTokenErrLabel=Get community file storage service upload token failed
startToUseLabel=Start startToUseLabel=Start
clearTagLabel=Clear tag clearDataLabel=Clear data
exportDataLabel=Export data exportDataLabel=Export data
syncToCommunityLabel=Sync to community syncToCommunityLabel=Sync to community
cntLabel= cntLabel=
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
# Author: Dongxu Wang # Author: Dongxu Wang
# #
removeUnusedArchivesLabel=\u79FB\u9664\u672A\u4F7F\u7528\u5B58\u6863
syncGitHubLabel=<a href="https://github.com/b3log/solo/issues/12676" target="_blank">\u5141\u8BB8\u540C\u6B65 GitHub \u4ED3\u5E93</a>\uFF1A syncGitHubLabel=<a href="https://github.com/b3log/solo/issues/12676" target="_blank">\u5141\u8BB8\u540C\u6B65 GitHub \u4ED3\u5E93</a>\uFF1A
queryUserFailedLabel=\u67E5\u8BE2\u7528\u6237\u4FE1\u606F\u5931\u8D25 queryUserFailedLabel=\u67E5\u8BE2\u7528\u6237\u4FE1\u606F\u5931\u8D25
commentContentLabel=\u8BC4\u8BBA\u5185\u5BB9 commentContentLabel=\u8BC4\u8BBA\u5185\u5BB9
...@@ -33,7 +34,7 @@ pushSuccLabel=\u63A8\u9001\u6210\u529F ...@@ -33,7 +34,7 @@ pushSuccLabel=\u63A8\u9001\u6210\u529F
pushToHacpaiLabel=\u63A8\u9001\u5230\u793E\u533A pushToHacpaiLabel=\u63A8\u9001\u5230\u793E\u533A
getUploadTokenErrLabel=\u83B7\u53D6\u793E\u533A\u6587\u4EF6\u5B58\u50A8\u670D\u52A1\u4E0A\u4F20\u51ED\u8BC1\u5F02\u5E38 getUploadTokenErrLabel=\u83B7\u53D6\u793E\u533A\u6587\u4EF6\u5B58\u50A8\u670D\u52A1\u4E0A\u4F20\u51ED\u8BC1\u5F02\u5E38
startToUseLabel=\u5F00\u59CB\u4F7F\u7528 startToUseLabel=\u5F00\u59CB\u4F7F\u7528
clearTagLabel=\u6807\u7B7E\u6E05\u7406 clearDataLabel=\u6570\u636E\u6E05\u7406
exportDataLabel=\u6570\u636E\u5BFC\u51FA exportDataLabel=\u6570\u636E\u5BFC\u51FA
syncToCommunityLabel=\u540C\u6B65\u5230\u793E\u533A syncToCommunityLabel=\u540C\u6B65\u5230\u793E\u533A
cntLabel=\u4E2A cntLabel=\u4E2A
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<ul> <ul>
<li> <li>
<div id="tabOthers_tag"> <div id="tabOthers_tag">
<a href="#tools/others/tag">${clearTagLabel}</a> <a href="#tools/others/tag">${clearDataLabel}</a>
</div> </div>
</li> </li>
<li> <li>
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
<div id="tabOthersPanel" class="sub-tabs-main"> <div id="tabOthersPanel" class="sub-tabs-main">
<div id="tabOthersPanel_tag" class="fn__none"> <div id="tabOthersPanel_tag" class="fn__none">
<button class="fn__margin12" onclick="admin.others.removeUnusedTags();">${removeUnusedTagsLabel}</button> <button class="fn__margin12" onclick="admin.others.removeUnusedTags();">${removeUnusedTagsLabel}</button>
<button class="fn__margin12" onclick="admin.others.removeUnusedArchives();">${removeUnusedArchivesLabel}</button>
</div> </div>
<div id="tabOthersPanel_data" class="fn__none"> <div id="tabOthersPanel_data" class="fn__none">
<#if supportExport> <#if supportExport>
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
* *
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a> * @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @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, Nov 11, 2017 * @version 1.4.0.0, Mar 20, 2019
*/ */
/* others 相关操作 */ /* others 相关操作 */
...@@ -32,6 +32,21 @@ admin.others = { ...@@ -32,6 +32,21 @@ admin.others = {
$("#tabOthers").tabs(); $("#tabOthers").tabs();
$('#loadMsg').text('') $('#loadMsg').text('')
}, },
/*
* @description 移除未使用的存档
*/
removeUnusedArchives: function () {
$("#tipMsg").text("");
$.ajax({
url: Label.servePath + "/console/archive/unused",
type: "DELETE",
cache: false,
success: function (result, textStatus) {
$("#tipMsg").text(result.msg);
}
});
},
/* /*
* @description 移除未使用的标签 * @description 移除未使用的标签
*/ */
......
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