From abc7ff306b45378051381cd4c4d2a0d555e16b96 Mon Sep 17 00:00:00 2001
From: gnaegi <none@none>
Date: Thu, 27 Jul 2017 12:38:40 +0200
Subject: [PATCH] OO-2505 update course editor title on import only when repo
 entry title was modified

---
 .../repository/handlers/CourseHandler.java    | 28 +++++++++++++++++--
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/olat/repository/handlers/CourseHandler.java b/src/main/java/org/olat/repository/handlers/CourseHandler.java
index ae064d36726..c2cfbf27621 100644
--- a/src/main/java/org/olat/repository/handlers/CourseHandler.java
+++ b/src/main/java/org/olat/repository/handlers/CourseHandler.java
@@ -26,6 +26,8 @@
 package org.olat.repository.handlers;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.nio.file.DirectoryStream;
 import java.nio.file.FileVisitResult;
@@ -254,9 +256,29 @@ public class CourseHandler implements RepositoryHandler {
 		course = CourseFactory.loadCourse(cgm.getCourseResource());
 		course.postImport(fImportBaseDirectory, envMapper);
 		
-		//rename root nodes
-		course.getRunStructure().getRootNode().setShortTitle(Formatter.truncateOnly(displayname, 25)); //do not use truncate!
-		course.getRunStructure().getRootNode().setLongTitle(displayname);
+		//rename root nodes, but only when user modified the course title
+		boolean doUpdateTitle = true;
+		File repoConfigXml = new File(fImportBaseDirectory, "repo.xml");
+		if (repoConfigXml.exists()) {
+			RepositoryEntryImport importConfig;
+			try {
+				importConfig = RepositoryEntryImportExport.getConfiguration(new FileInputStream(repoConfigXml));
+				if(importConfig != null) {
+					if (displayname.equals(importConfig.getDisplayname())) {					
+						// do not update if title was not modified during import
+						// user does not expect to have an updated title and there is a chance
+						// the root node title is not the same as the course title
+						doUpdateTitle = false;
+					}
+				}
+			} catch (FileNotFoundException e) {
+				// ignore
+			}
+		}
+		if (doUpdateTitle) {
+			course.getRunStructure().getRootNode().setShortTitle(Formatter.truncateOnly(displayname, 25)); //do not use truncate!
+			course.getRunStructure().getRootNode().setLongTitle(displayname);
+		}
 		//course.saveRunStructure();
 		CourseEditorTreeNode editorRootNode = ((CourseEditorTreeNode)course.getEditorTreeModel().getRootNode());
 		editorRootNode.getCourseNode().setShortTitle(Formatter.truncateOnly(displayname, 25)); //do not use truncate!
-- 
GitLab