[LON-CAPA-cvs] cvs: loncom /interface londocs.pm

raeburn raeburn@source.lon-capa.org
Mon, 15 Dec 2008 03:02:19 -0000


raeburn		Mon Dec 15 03:02:19 2008 EDT

  Modified files:              
    /loncom/interface	londocs.pm 
  Log:
  - Check return value when pasting uploaded folder or composite page.
    - If error occurs when saving new map
      - do not update the map for the current folder
      - display an error message
  
  
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.320 loncom/interface/londocs.pm:1.321
--- loncom/interface/londocs.pm:1.320	Sat Dec 13 00:19:07 2008
+++ loncom/interface/londocs.pm	Mon Dec 15 03:02:19 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.320 2008/12/13 00:19:07 raeburn Exp $
+# $Id: londocs.pm,v 1.321 2008/12/15 03:02:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1270,7 +1270,9 @@
 sub do_paste_from_buffer {
     my ($coursenum,$coursedom,$folder) = @_;
 
-    return 0 if (!$env{'form.pastemarked'});
+    if (!$env{'form.pastemarked'}) {
+        return;
+    }
 
 # paste resource to end of list
     my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
@@ -1283,8 +1285,16 @@
 	my $newurl=$1.$newid.'.'.$2;
 	my $storefn=$newurl;
 	$storefn=~s{^/\w+/$match_domain/$match_username/}{};
-	&Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
-					   &Apache::lonnet::getfile($url));
+	my $paste_map_result =
+            &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
+					       &Apache::lonnet::getfile($url));
+        if ($paste_map_result eq '/adm/notfound.html') {
+            if ($url=~/\.page$/) {
+                return &mt('Paste failed: an error occurred saving the composite page');
+            } else {
+                return &mt('Paste failed: an error occurred saving the folder');
+            }
+        }
 	$url = $newurl;
     }
 # published maps can only exists once, so remove it from paste buffer when done
@@ -1326,6 +1336,7 @@
 
     $LONCAPA::map::resources[$newidx]= 	$title.':'.$url.':'.$ext.':normal:res';
     push(@LONCAPA::map::order, $newidx);
+    return 'ok';
 # Store the result
 }
 
@@ -1444,9 +1455,14 @@
 	}
 	    
 	if ($env{'form.pastemarked'}) {
-	    &do_paste_from_buffer($coursenum,$coursedom,$folder);
-	    ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
-	    return $errtext if ($fatal);
+            my $paste_res = 
+                &do_paste_from_buffer($coursenum,$coursedom,$folder);
+            if ($paste_res eq 'ok') {
+                ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
+                return $errtext if ($fatal);
+            } elsif ($paste_res ne '') {
+                $r->print('<p><span class="LC_error">'.$paste_res.'</span></p>');
+            }
 	}
 
 	$r->print($upload_output);