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
bd1755f3
Unverified
Commit
bd1755f3
authored
Nov 11, 2019
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🐛
Fix #12940
查询语句在主程序中进行了修复,历史数据通过 v3.6.7 升级程序进行修复订正
parent
0df0329a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
110 additions
and
0 deletions
+110
-0
src/main/java/org/b3log/solo/upgrade/V366_367.java
src/main/java/org/b3log/solo/upgrade/V366_367.java
+110
-0
No files found.
src/main/java/org/b3log/solo/upgrade/V366_367.java
0 → 100644
View file @
bd1755f3
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-present, b3log.org
*
* 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
.
upgrade
;
import
org.b3log.latke.Latkes
;
import
org.b3log.latke.ioc.BeanManager
;
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.ArchiveDateRepository
;
import
org.b3log.solo.repository.OptionRepository
;
import
org.json.JSONObject
;
import
java.util.List
;
/**
* Upgrade script from v3.6.6 to v3.6.7.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Nov 11, 2019
* @since 3.6.7
*/
public
final
class
V366_367
{
/**
* Logger.
*/
private
static
final
Logger
LOGGER
=
Logger
.
getLogger
(
V366_367
.
class
);
/**
* Performs upgrade from v3.6.6 to v3.6.7.
*
* @throws Exception upgrade fails
*/
public
static
void
perform
()
throws
Exception
{
final
String
fromVer
=
"3.6.6"
;
final
String
toVer
=
"3.6.7"
;
LOGGER
.
log
(
Level
.
INFO
,
"Upgrading from version ["
+
fromVer
+
"] to version ["
+
toVer
+
"]...."
);
final
BeanManager
beanManager
=
BeanManager
.
getInstance
();
final
OptionRepository
optionRepository
=
beanManager
.
getReference
(
OptionRepository
.
class
);
final
ArchiveDateRepository
archiveDateRepository
=
beanManager
.
getReference
(
ArchiveDateRepository
.
class
);
final
ArchiveDateArticleRepository
archiveDateArticleRepository
=
beanManager
.
getReference
(
ArchiveDateArticleRepository
.
class
);
try
{
final
Transaction
transaction
=
optionRepository
.
beginTransaction
();
// 清理存档-文章关联表中的冗余数据
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 DESC"
);
for
(
int
i
=
0
;
i
<
archiveDateArticles
.
size
();
i
++)
{
final
JSONObject
archiveDateArticle
=
archiveDateArticles
.
get
(
i
);
final
String
archiveDateId
=
archiveDateArticle
.
optString
(
"archiveDate_oId"
);
archiveDateArticleRepository
.
remove
(
new
Query
().
setFilter
(
CompositeFilterOperator
.
and
(
new
PropertyFilter
(
"archiveDate_oId"
,
FilterOperator
.
EQUAL
,
archiveDateId
),
new
PropertyFilter
(
"article_oId"
,
FilterOperator
.
EQUAL
,
archiveDateArticle
.
optString
(
"article_oId"
)),
new
PropertyFilter
(
"oId"
,
FilterOperator
.
NOT_EQUAL
,
archiveDateArticle
.
optString
(
"oId"
)))));
while
(
i
<
archiveDateArticles
.
size
()
-
1
)
{
if
(!
archiveDateId
.
equalsIgnoreCase
(
archiveDateArticles
.
get
(
i
+
1
).
optString
(
"archiveDate_oId"
)))
{
break
;
}
i
++;
}
}
final
JSONObject
versionOpt
=
optionRepository
.
get
(
Option
.
ID_C_VERSION
);
versionOpt
.
put
(
Option
.
OPTION_VALUE
,
toVer
);
optionRepository
.
update
(
Option
.
ID_C_VERSION
,
versionOpt
);
transaction
.
commit
();
LOGGER
.
log
(
Level
.
INFO
,
"Upgraded from version ["
+
fromVer
+
"] to version ["
+
toVer
+
"] successfully"
);
}
catch
(
final
Exception
e
)
{
LOGGER
.
log
(
Level
.
ERROR
,
"Upgrade failed!"
,
e
);
throw
new
Exception
(
"Upgrade failed from version ["
+
fromVer
+
"] to version ["
+
toVer
+
"]"
);
}
}
}
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