fix #1827 add migration
This commit is contained in:
parent
ca14d7b1e3
commit
1eadbaf544
2 changed files with 39 additions and 2 deletions
|
@ -31,6 +31,7 @@ import org.codelibs.fess.es.config.exbhv.RoleTypeBhv;
|
|||
import org.codelibs.fess.es.config.exbhv.WebConfigBhv;
|
||||
import org.codelibs.fess.es.config.exbhv.WebConfigToRoleBhv;
|
||||
import org.codelibs.fess.es.user.exbhv.RoleBhv;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
import org.codelibs.fess.util.UpgradeUtil;
|
||||
import org.elasticsearch.client.IndicesAdminClient;
|
||||
import org.lastaflute.web.Execute;
|
||||
|
@ -182,7 +183,7 @@ public class AdminUpgradeAction extends FessAdminAction {
|
|||
}
|
||||
|
||||
private void upgradeFrom12_2() {
|
||||
// nothing
|
||||
ComponentUtil.getThumbnailManager().migrate();
|
||||
}
|
||||
|
||||
private void upgradeFromAll() {
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.codelibs.fess.thumbnail;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.FileVisitor;
|
||||
import java.nio.file.Files;
|
||||
|
@ -30,6 +31,7 @@ import java.util.concurrent.BlockingQueue;
|
|||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
@ -277,9 +279,13 @@ public class ThumbnailManager {
|
|||
}
|
||||
|
||||
protected String getImageFilename(final Map<String, Object> docMap) {
|
||||
final StringBuilder buf = new StringBuilder(50);
|
||||
final FessConfig fessConfig = ComponentUtil.getFessConfig();
|
||||
final String docid = DocumentUtil.getValue(docMap, fessConfig.getIndexFieldDocId(), String.class);
|
||||
return getImageFilename(docid);
|
||||
}
|
||||
|
||||
protected String getImageFilename(final String docid) {
|
||||
final StringBuilder buf = new StringBuilder(50);
|
||||
for (int i = 0; i < docid.length(); i++) {
|
||||
if (i > 0 && i % splitSize == 0) {
|
||||
buf.append('/');
|
||||
|
@ -470,6 +476,36 @@ public class ThumbnailManager {
|
|||
|
||||
}
|
||||
|
||||
public void migrate() {
|
||||
new Thread(() -> {
|
||||
final Path basePath = baseDir.toPath();
|
||||
final String suffix = "." + imageExtention;
|
||||
try (Stream<Path> paths = Files.walk(basePath)) {
|
||||
paths.filter(path -> path.toFile().getName().endsWith(imageExtention)).forEach(path -> {
|
||||
final Path subPath = basePath.relativize(path);
|
||||
final String docId = subPath.toString().replace("/", StringUtil.EMPTY).replace(suffix, StringUtil.EMPTY);
|
||||
final String filename = getImageFilename(docId);
|
||||
final Path newPath = basePath.resolve(filename);
|
||||
if (!path.equals(newPath)) {
|
||||
try {
|
||||
try {
|
||||
Files.createDirectories(newPath.getParent());
|
||||
} catch (final FileAlreadyExistsException e) {
|
||||
// ignore
|
||||
}
|
||||
Files.move(path, newPath);
|
||||
logger.info("Move " + path + " to " + newPath);
|
||||
} catch (IOException e) {
|
||||
logger.warn("Failed to move " + path, e);
|
||||
}
|
||||
}
|
||||
} );
|
||||
} catch (IOException e) {
|
||||
logger.warn("Failed to migrate thumbnail images.", e);
|
||||
}
|
||||
}, "ThumbnailMigrator").start();
|
||||
}
|
||||
|
||||
public void setThumbnailPathCacheSize(final int thumbnailPathCacheSize) {
|
||||
this.thumbnailPathCacheSize = thumbnailPathCacheSize;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue