From 28b0d86f7987367018a57f2eea00017341c0c776 Mon Sep 17 00:00:00 2001
From: srosse <stephane.rosse@frentix.com>
Date: Tue, 21 Apr 2020 07:44:28 +0200
Subject: [PATCH] OO-4649: don't archive test if the test entry is already
 deleted

Don't archive test in a course element if the test entry is already
deleted, same for survey and self test
---
 src/main/java/org/olat/course/nodes/IQSELFCourseNode.java | 6 +++++-
 src/main/java/org/olat/course/nodes/IQSURVCourseNode.java | 6 +++++-
 src/main/java/org/olat/course/nodes/IQTESTCourseNode.java | 7 ++++++-
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/olat/course/nodes/IQSELFCourseNode.java b/src/main/java/org/olat/course/nodes/IQSELFCourseNode.java
index da475a142a0..fb078e249dd 100644
--- a/src/main/java/org/olat/course/nodes/IQSELFCourseNode.java
+++ b/src/main/java/org/olat/course/nodes/IQSELFCourseNode.java
@@ -260,7 +260,11 @@ public class IQSELFCourseNode extends AbstractAccessableCourseNode implements Se
 	public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options,
 			ZipOutputStream exportStream, String archivePath, String charset) {
 		String repositorySoftKey = (String) getModuleConfiguration().get(IQEditController.CONFIG_KEY_REPOSITORY_SOFTKEY);
-		RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repositorySoftKey, true);
+		RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repositorySoftKey, false);
+		if(re == null) {
+			log.error("Cannot archive course node. Missing repository entry with soft key: ", repositorySoftKey);
+			return false;
+		}
 		
 		try {
 			if(ImsQTI21Resource.TYPE_NAME.equals(re.getOlatResource().getResourceableTypeName())) {
diff --git a/src/main/java/org/olat/course/nodes/IQSURVCourseNode.java b/src/main/java/org/olat/course/nodes/IQSURVCourseNode.java
index 82612535703..a68bc105b53 100644
--- a/src/main/java/org/olat/course/nodes/IQSURVCourseNode.java
+++ b/src/main/java/org/olat/course/nodes/IQSURVCourseNode.java
@@ -305,7 +305,11 @@ public class IQSURVCourseNode extends AbstractAccessableCourseNode implements QT
 			ZipOutputStream exportStream, String archivePath, String charset) {
 		QTIExportManager qem = QTIExportManager.getInstance();
 		String repositorySoftKey = (String) getModuleConfiguration().get(IQEditController.CONFIG_KEY_REPOSITORY_SOFTKEY);
-		RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repositorySoftKey, true);
+		RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repositorySoftKey, false);
+		if(re == null) {
+			log.error("Cannot archive course node. Missing repository entry with soft key: ", repositorySoftKey);
+			return false;
+		}
 
 		QTIExportFormatter qef = new QTIExportFormatterCSVType3(locale, null,"\t", "\"", "\r\n", false);
 		try {
diff --git a/src/main/java/org/olat/course/nodes/IQTESTCourseNode.java b/src/main/java/org/olat/course/nodes/IQTESTCourseNode.java
index 5caa4b0707b..7979b05a7d2 100644
--- a/src/main/java/org/olat/course/nodes/IQTESTCourseNode.java
+++ b/src/main/java/org/olat/course/nodes/IQTESTCourseNode.java
@@ -713,7 +713,12 @@ public class IQTESTCourseNode extends AbstractAccessableCourseNode implements Pe
 		// 1) prepare result export
 		CourseEnvironment courseEnv = course.getCourseEnvironment();
 		try {
-			RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repositorySoftKey, true);
+			RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repositorySoftKey, false);
+			if(re == null) {
+				log.error("Cannot archive course node. Missing repository entry with soft key: ", repositorySoftKey);
+				return false;
+			}
+			
 			boolean onyx = QTIResourceTypeModule.isOnyxTest(re.getOlatResource());
 			if (onyx) {
 				return true;
-- 
GitLab