Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo-1
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
solo-1
Commits
c696eb21
Unverified
Commit
c696eb21
authored
Nov 11, 2019
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🎨
存档重复问题订正程序
parent
3e4142d8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
2 deletions
+72
-2
src/main/java/org/b3log/solo/Server.java
src/main/java/org/b3log/solo/Server.java
+2
-1
src/main/java/org/b3log/solo/processor/console/RepairConsole.java
.../java/org/b3log/solo/processor/console/RepairConsole.java
+70
-1
No files found.
src/main/java/org/b3log/solo/Server.java
View file @
c696eb21
...
...
@@ -46,7 +46,7 @@ import org.json.JSONObject;
* Server.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.0.0.
2
, Nov 11, 2019
* @version 2.0.0.
3
, Nov 11, 2019
* @since 1.2.0
*/
public
final
class
Server
extends
BaseServer
{
...
...
@@ -437,6 +437,7 @@ public final class Server extends BaseServer {
final
RepairConsole
repairConsole
=
beanManager
.
getReference
(
RepairConsole
.
class
);
Dispatcher
.
get
(
"/fix/restore-signs"
,
repairConsole:
:
restoreSigns
);
Dispatcher
.
get
(
"/fix/archivedate-articles"
,
repairConsole:
:
cleanArchiveDateArticles
);
final
TagConsole
tagConsole
=
beanManager
.
getReference
(
TagConsole
.
class
);
Dispatcher
.
get
(
"/console/tags"
,
tagConsole:
:
getTags
);
...
...
src/main/java/org/b3log/solo/processor/console/RepairConsole.java
View file @
c696eb21
...
...
@@ -17,6 +17,7 @@
*/
package
org
.
b3log
.
solo
.
processor
.
console
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.http.RequestContext
;
import
org.b3log.latke.http.annotation.Before
;
import
org.b3log.latke.http.annotation.RequestProcessor
;
...
...
@@ -24,7 +25,9 @@ import org.b3log.latke.http.renderer.TextHtmlRenderer;
import
org.b3log.latke.ioc.Inject
;
import
org.b3log.latke.logging.Level
;
import
org.b3log.latke.logging.Logger
;
import
org.b3log.latke.repository.*
;
import
org.b3log.solo.model.Option
;
import
org.b3log.solo.repository.ArchiveDateArticleRepository
;
import
org.b3log.solo.repository.ArticleRepository
;
import
org.b3log.solo.repository.TagArticleRepository
;
import
org.b3log.solo.repository.TagRepository
;
...
...
@@ -34,11 +37,13 @@ import org.b3log.solo.service.StatisticMgmtService;
import
org.b3log.solo.service.StatisticQueryService
;
import
org.json.JSONObject
;
import
java.util.List
;
/**
* Provides patches on some special issues.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.
2.0.21, Mar 3
, 2019
* @version 1.
3.0.0, Nov 11
, 2019
* @since 0.3.1
*/
@RequestProcessor
...
...
@@ -80,6 +85,12 @@ public class RepairConsole {
@Inject
private
ArticleRepository
articleRepository
;
/**
* ArchiveDate-Article repository.
*/
@Inject
private
ArchiveDateArticleRepository
archiveDateArticleRepository
;
/**
* Statistic query service.
*/
...
...
@@ -113,4 +124,62 @@ public class RepairConsole {
renderer
.
setContent
(
"Restores signs failed, error msg ["
+
e
.
getMessage
()
+
"]"
);
}
}
/**
* Cleans duplicated archive date-articles.
*
* @param context the specified context
*/
public
void
cleanArchiveDateArticles
(
final
RequestContext
context
)
{
final
TextHtmlRenderer
renderer
=
new
TextHtmlRenderer
();
context
.
setRenderer
(
renderer
);
final
Transaction
transaction
=
archiveDateArticleRepository
.
beginTransaction
();
try
{
// 清理存档-文章关联表中的冗余数据
final
String
tablePrefix
=
Latkes
.
getLocalProperty
(
"jdbc.tablePrefix"
)
+
"_"
;
final
List
<
JSONObject
>
archiveDateArticles
=
archiveDateArticleRepository
.
select
(
"SELECT\n"
+
"\t*\n"
+
"FROM\n"
+
"\t"
+
tablePrefix
+
"archivedate_article\n"
+
"WHERE\n"
+
"\tarticle_oId IN (\n"
+
"\t\tSELECT\n"
+
"\t\t\tarticle_oId\n"
+
"\t\tFROM\n"
+
"\t\t\t"
+
tablePrefix
+
"archivedate_article\n"
+
"\t\tGROUP BY\n"
+
"\t\t\tarticle_oId\n"
+
"\t\tHAVING\n"
+
"\t\t\tcount(*) > 1\n"
+
"\t) ORDER BY archiveDate_oId, article_oId DESC"
);
for
(
int
i
=
0
;
i
<
archiveDateArticles
.
size
();
i
++)
{
final
JSONObject
archiveDateArticle
=
archiveDateArticles
.
get
(
i
);
final
String
archiveDateId
=
archiveDateArticle
.
optString
(
"archiveDate_oId"
);
final
String
articleId
=
archiveDateArticle
.
optString
(
"article_oId"
);
archiveDateArticleRepository
.
remove
(
new
Query
().
setFilter
(
CompositeFilterOperator
.
and
(
new
PropertyFilter
(
"archiveDate_oId"
,
FilterOperator
.
EQUAL
,
archiveDateId
),
new
PropertyFilter
(
"article_oId"
,
FilterOperator
.
EQUAL
,
articleId
),
new
PropertyFilter
(
"oId"
,
FilterOperator
.
NOT_EQUAL
,
archiveDateArticle
.
optString
(
"oId"
)))));
while
(
i
<
archiveDateArticles
.
size
()
-
1
)
{
if
(!
archiveDateId
.
equalsIgnoreCase
(
archiveDateArticles
.
get
(
i
+
1
).
optString
(
"archiveDate_oId"
))
||
!
articleId
.
equalsIgnoreCase
(
archiveDateArticles
.
get
(
i
+
1
).
optString
(
"article_oId"
)))
{
break
;
}
i
++;
}
}
transaction
.
commit
();
renderer
.
setContent
(
"Cleaned duplicated archive date articles"
);
}
catch
(
final
Exception
e
)
{
if
(
transaction
.
isActive
())
{
transaction
.
rollback
();
}
LOGGER
.
log
(
Level
.
ERROR
,
e
.
getMessage
(),
e
);
renderer
.
setContent
(
"Clean duplicated archive date articles failed ["
+
e
.
getMessage
()
+
"]"
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment