From fb3193171a7cb01c81dbfb587a5a2384b37c05b7 Mon Sep 17 00:00:00 2001
From: Ruediger Kurz <r.kurz@alkacon.com>
Date: Fri, 25 Oct 2013 15:57:46 +0200
Subject: [PATCH] Disable Solr in the opencms-search.xml during upgrade
 process.

---
 build.gradle                                  |  5 +++++
 .../setup/xml/v8/CmsXmlAddSolrSearch.java     | 21 +++++++++++++++++--
 webapp/update/readme.txt                      | 15 ++++++++++++-
 3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/build.gradle b/build.gradle
index 0c1c0fbcdb8..1f30de662cd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -504,6 +504,11 @@ task updater (dependsOn: setupJar, type: Zip){
         include 'update/**'
         exclude 'update/empty.jar'
         exclude 'update/readme.txt'
+    }
+	from ("${projectDir}/webapp/WEB-INF/solr/conf"){
+		into '/WEB-INF/solr-update/'
+        include 'schema.xml'
+        include 'solrconfig.xml'
     }
     from "${projectDir}/webapp/update/readme.txt"
     from ("${projectDir}/webapp/WEB-INF"){
diff --git a/src-setup/org/opencms/setup/xml/v8/CmsXmlAddSolrSearch.java b/src-setup/org/opencms/setup/xml/v8/CmsXmlAddSolrSearch.java
index f0e656e08a0..dee866a6cf1 100644
--- a/src-setup/org/opencms/setup/xml/v8/CmsXmlAddSolrSearch.java
+++ b/src-setup/org/opencms/setup/xml/v8/CmsXmlAddSolrSearch.java
@@ -32,6 +32,7 @@
 import java.util.Collections;
 import java.util.List;
 
+import org.dom4j.Attribute;
 import org.dom4j.Document;
 import org.dom4j.DocumentException;
 import org.dom4j.Element;
@@ -52,10 +53,10 @@ public boolean executeUpdate(Document doc, String xpath, boolean forReal) {
 
         Element node = (Element)doc.selectSingleNode("/opencms/search");
         if (node.selectSingleNode("solr") == null) {
-            String solrComment = "To enable Solr in OpenCms you must create a solr/ home\n"
+            String solrComment = " To enable Solr in OpenCms you must create a solr/ home\n"
                 + "           directory in the WEB-INF folder of your OpenCms application.\n"
                 + "           Copy the solr/ folder from the OpenCms standard distribution\n"
-                + "           as a starting point for your configuration.";
+                + "           as a starting point for your configuration. ";
             try {
                 Element solrElement = createElementFromXml("<solr enabled=\"false\"></solr>");
                 solrElement.addComment(solrComment);
@@ -64,6 +65,22 @@ public boolean executeUpdate(Document doc, String xpath, boolean forReal) {
                 System.out.println("Could not add solr node");
                 return false;
             }
+        } else {
+            String solrComment = "\n"
+                + "           During the update Solr will be disabled in the WEB-INF/config/opencms-search.xml.\n"
+                + "           To update Solr you must update the 'schema.xml and' the 'solrconfig.xml' manually.\n"
+                + "           The new default configuration files are located in the solr-update/ directory in\n"
+                + "           the WEB-INF folder of your application. If you are using the default configuration\n"
+                + "           from the distribution, it is sufficient to copy the new configuration files to the\n"
+                + "           WEB-INF/solr folder. Else if you have customized the Solr configuration you might\n"
+                + "           want to merge the 'schema.xml' and the 'solrconfig.xml' first. When you are done\n"
+                + "           set the attribute enabled to 'true' again.\n";
+            Element solrElement = (Element)node.selectSingleNode("solr");
+            Attribute a = solrElement.attribute("enabled");
+            if (a != null) {
+                a.setValue("false");
+            }
+            solrElement.addComment(solrComment);
         }
         return true;
     }
diff --git a/webapp/update/readme.txt b/webapp/update/readme.txt
index 1d99c0178f5..a2ce1022dd3 100644
--- a/webapp/update/readme.txt
+++ b/webapp/update/readme.txt
@@ -102,7 +102,20 @@ The wizard will finish similar to the setup wizard. After the final confirmation
 the wizard will be locked again (in the opencms.properties file).
 
 
-6. Shutdown and restart your OpenCms servlet container
+
+6. Update Solr configuration
+
+During the update Solr will be disabled in the WEB-INF/config/opencms-search.xml.
+To update Solr you must update the 'schema.xml and' the 'solrconfig.xml' manually.
+The new default configuration files are located in the solr-update/ directory in 
+the WEB-INF folder of your application. If you are using the default configuration
+from the distribution, it is sufficient to copy the new configuration files to the
+WEB-INF/solr folder. Else if you have customized the Solr configuration you might 
+want to merge the 'schema.xml' and the 'solrconfig.xml' first. When you are done 
+set the attribute enabled to 'true' again (and restart the servelt container).
+
+
+7. Shutdown and restart your OpenCms servlet container
 
 Note: to be sure all jsp files work correctly please delete the servlet containers
 work directory (ie. ${TOMCAT_HOME}/work/Catalina/localhost/opencms/) and the