Skip to content
Snippets Groups Projects
Commit f3ee4136 authored by srosse's avatar srosse
Browse files

no-jira: add a parent line checker to the VFS metadata upgrader

parent 0935a6f9
No related branches found
No related tags found
No related merge requests found
...@@ -95,7 +95,7 @@ public class VFSMetadataDAO { ...@@ -95,7 +95,7 @@ public class VFSMetadataDAO {
* @param element The curriculum element * @param element The curriculum element
* @return The materialized path of the specified element * @return The materialized path of the specified element
*/ */
private String getMaterializedPathKeys(VFSMetadataImpl parent, VFSMetadataImpl element) { protected String getMaterializedPathKeys(VFSMetadataImpl parent, VFSMetadataImpl element) {
if(parent != null) { if(parent != null) {
String parentPathOfKeys = parent.getMaterializedPathKeys(); String parentPathOfKeys = parent.getMaterializedPathKeys();
if(parentPathOfKeys == null || "/".equals(parentPathOfKeys)) { if(parentPathOfKeys == null || "/".equals(parentPathOfKeys)) {
......
...@@ -47,6 +47,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -47,6 +47,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.Adler32; import java.util.zip.Adler32;
import java.util.zip.Checksum; import java.util.zip.Checksum;
import org.apache.logging.log4j.Logger;
import org.olat.basesecurity.BaseSecurity; import org.olat.basesecurity.BaseSecurity;
import org.olat.core.commons.modules.bc.FolderConfig; import org.olat.core.commons.modules.bc.FolderConfig;
import org.olat.core.commons.modules.bc.FolderLicenseHandler; import org.olat.core.commons.modules.bc.FolderLicenseHandler;
...@@ -74,7 +75,6 @@ import org.olat.core.commons.services.vfs.model.VFSRevisionImpl; ...@@ -74,7 +75,6 @@ import org.olat.core.commons.services.vfs.model.VFSRevisionImpl;
import org.olat.core.gui.control.Event; import org.olat.core.gui.control.Event;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
import org.olat.core.id.OLATResourceable; import org.olat.core.id.OLATResourceable;
import org.apache.logging.log4j.Logger;
import org.olat.core.logging.Tracing; import org.olat.core.logging.Tracing;
import org.olat.core.util.FileUtils; import org.olat.core.util.FileUtils;
import org.olat.core.util.StringHelper; import org.olat.core.util.StringHelper;
...@@ -1075,6 +1075,27 @@ public class VFSRepositoryServiceImpl implements VFSRepositoryService, GenericEv ...@@ -1075,6 +1075,27 @@ public class VFSRepositoryServiceImpl implements VFSRepositoryService, GenericEv
dbInstance.commit(); dbInstance.commit();
} }
} }
private VFSMetadata checkParentLine(VFSMetadata metadata, VFSMetadata parent) {
if(metadata == null || parent == null) {
return metadata;
}
VFSMetadata persistedParent = ((VFSMetadataImpl)metadata).getParent();
String materializedPath = metadataDao.getMaterializedPathKeys((VFSMetadataImpl)parent, (VFSMetadataImpl)metadata);
if(!persistedParent.equals(parent)) {
((VFSMetadataImpl)metadata).setMaterializedPathKeys(materializedPath);
((VFSMetadataImpl)metadata).setParent(parent);
return metadataDao.updateMetadata(metadata);
}
String pathKeys = ((VFSMetadataImpl)metadata).getMaterializedPathKeys();
if(!pathKeys.equals(materializedPath)) {
((VFSMetadataImpl)metadata).setMaterializedPathKeys(materializedPath);
return metadataDao.updateMetadata(metadata);
}
return metadata;
}
public void migrateDirectories(File folder) throws IOException { public void migrateDirectories(File folder) throws IOException {
Deque<VFSMetadata> parentLine = new LinkedList<>(); Deque<VFSMetadata> parentLine = new LinkedList<>();
...@@ -1094,10 +1115,7 @@ public class VFSRepositoryServiceImpl implements VFSRepositoryService, GenericEv ...@@ -1094,10 +1115,7 @@ public class VFSRepositoryServiceImpl implements VFSRepositoryService, GenericEv
VFSMetadata parent = parentLine.peekLast(); VFSMetadata parent = parentLine.peekLast();
VFSMetadata metadata = migrateMetadata(dir.toFile(), parent); VFSMetadata metadata = migrateMetadata(dir.toFile(), parent);
if(metadata != null && "migrated".equals(metadata.getMigrated())) { metadata = checkParentLine(metadata, parent);
dbInstance.commitAndCloseSession();
return FileVisitResult.SKIP_SUBTREE;
}
parentLine.add(metadata); parentLine.add(metadata);
dbInstance.commit(); dbInstance.commit();
return FileVisitResult.CONTINUE; return FileVisitResult.CONTINUE;
...@@ -1107,7 +1125,8 @@ public class VFSRepositoryServiceImpl implements VFSRepositoryService, GenericEv ...@@ -1107,7 +1125,8 @@ public class VFSRepositoryServiceImpl implements VFSRepositoryService, GenericEv
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
File f = file.toFile(); File f = file.toFile();
if(!f.isHidden() && VFSRepositoryModule.canMeta(f) == VFSConstants.YES) { if(!f.isHidden() && VFSRepositoryModule.canMeta(f) == VFSConstants.YES) {
migrateMetadata(file.toFile(), parentLine.getLast()); VFSMetadata metadata = migrateMetadata(file.toFile(), parentLine.getLast());
checkParentLine(metadata, parentLine.getLast());
migrationCounter.incrementAndGet(); migrationCounter.incrementAndGet();
if(migrationCounter.get() % 25 == 0) { if(migrationCounter.get() % 25 == 0) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment