svn commit: r598789 - /lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Restore.java

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Author: rfrovarp
Date: Tue Nov 27 14:27:56 2007
New Revision: 598789

URL: http://svn.apache.org/viewvc?rev=598789&view=rev
Log:
Don't allow restore to paths that don't exist. Prevents ghost nodes from bug 43861.

Modified:
    lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Restore.java

Modified: lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Restore.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Restore.java?rev=598789&r1=598788&r2=598789&view=diff
==============================================================================
--- lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Restore.java (original)
+++ lenya/trunk/src/modules-core/sitemanagement/java/src/org/apache/lenya/cms/site/usecases/Restore.java Tue Nov 27 14:27:56 2007
@@ -17,8 +17,11 @@
  */
 package org.apache.lenya.cms.site.usecases;
 
+import org.apache.lenya.cms.publication.Area;
 import org.apache.lenya.cms.publication.Document;
+import org.apache.lenya.cms.publication.DocumentLocator;
 import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.cms.site.SiteUtil;
 import org.apache.lenya.cms.workflow.WorkflowUtil;
 import org.apache.lenya.workflow.Workflowable;
 
@@ -50,6 +53,25 @@
         return "restore";
     }
 
+    protected void doCheckPreconditions() throws Exception {
+        super.doCheckPreconditions();
+
+        String targetAreaName = getTargetArea(); 
+        Document doc = getSourceDocument();
+        if(doc == null) {
+            return;
+        }
+        // Check to see if parent node exists in target to prevent ghost nodes
+        Area targetArea = doc.getPublication().getArea(targetAreaName);
+        DocumentLocator targetLoc = doc.getLocator().getAreaVersion(targetAreaName);
+        targetLoc = SiteUtil.getAvailableLocator(this.manager, getDocumentFactory(), targetLoc);
+        String targetPath = targetLoc.getPath();
+        targetPath = targetPath.substring(0,targetPath.lastIndexOf('/'));
+        if(!targetArea.getSite().contains(targetPath)) {
+            addErrorMessage("The authoring path [" + targetPath + "] does not exist.");
+        }
+    }
+  
     protected void doCheckPostconditions() throws Exception {
         super.doCheckPostconditions();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.