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

OO-467: on second thoughts, the low level check of the max number of versions...

OO-467: on second thoughts, the low level check of the max number of versions must detect if the versioning is deactivated and don't add a revision in this case
parent f5d697bb
No related branches found
No related tags found
No related merge requests found
......@@ -34,9 +34,10 @@ import org.olat.core.util.vfs.VFSContainer;
public interface FolderVersioningConfigurator {
/**
* The absolut limit for this instance
* @return -1 for versioning without limit, 0 for no versioning, 1 - n is the maximum number of revision per file
*/
public int versionAllowed();
public int getMaxNumOfVersionsAllowed();
/**
* @param relPath
......
......@@ -130,7 +130,7 @@ public class SimpleVersionConfig implements GenericEventListener, FolderVersioni
}
@Override
public int versionAllowed() {
public int getMaxNumOfVersionsAllowed() {
return getVersionAllowed();
}
......
......@@ -555,6 +555,11 @@ public class VersionsFileManager extends VersionsManager implements Initializabl
*/
@Override
public boolean addToRevisions(Versionable currentVersion, Identity identity, String comment) {
int maxNumOfVersions = versioningConfigurator.getMaxNumOfVersionsAllowed();
if(maxNumOfVersions == 0) {
return true;//deactivated, return all ok
}
VFSLeaf currentFile = (VFSLeaf) currentVersion;
VFSLeaf versionFile = getCanonicalVersionXmlFile(currentFile, true);
......@@ -615,8 +620,7 @@ public class VersionsFileManager extends VersionsManager implements Initializabl
if (identity != null) {
versions.setAuthor(identity.getName());
}
int maxNumOfVersions = versioningConfigurator.versionAllowed();
if(maxNumOfVersions >= 0 && versions.getRevisions().size() >= maxNumOfVersions) {
List<VFSRevision> revisions = versions.getRevisions();
int numOfVersionsToDelete = Math.min(revisions.size(), (revisions.size() - maxNumOfVersions) + 1);
......
......@@ -92,6 +92,14 @@ public abstract class VersionsManager extends BasicManager {
*/
public abstract boolean addVersion(Versionable currentVersion, Identity author, String comment, InputStream newVersion);
/**
* Add a new revision to the files. The method check the number of revisions against the absolute
* maximum limit for the instance.
* @param currentVersion
* @param author
* @param comment
* @return
*/
public abstract boolean addToRevisions(Versionable currentVersion, Identity author, String comment);
/**
......
......@@ -208,9 +208,7 @@ public class VersionManagerTest extends OlatTestCase {
Versions versions = VersionsFileManager.getInstance().createVersionsFor((VFSLeaf)retrievedFile);
List<VFSRevision> revisions = versions.getRevisions();
assertNotNull(revisions);
assertEquals(1, revisions.size());
assertEquals("Version 5", versions.getComment());
assertTrue(revisions.isEmpty());
}
@Test
......
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