[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm /publisher loncfile.pm lonupload.pm

raeburn raeburn at source.lon-capa.org
Wed Jul 3 01:03:19 EDT 2013


raeburn		Wed Jul  3 05:03:19 2013 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
    /loncom/publisher	loncfile.pm lonupload.pm 
  Log:
  - Bug 6168 (a part).
    - Display warning if copying file would exceed quota in authoring space
    - Testing if quota would be exceeded by file upload moved from lonupload.pm
      to &excess_filesize_authorspace() routine in loncommon.pm to facilitate reuse. 
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1134 loncom/interface/loncommon.pm:1.1135
--- loncom/interface/loncommon.pm:1.1134	Tue Jul  2 19:04:36 2013
+++ loncom/interface/loncommon.pm	Wed Jul  3 05:03:12 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1134 2013/07/02 19:04:36 raeburn Exp $
+# $Id: loncommon.pm,v 1.1135 2013/07/03 05:03:12 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -8759,6 +8759,47 @@
     }
 }
 
+###############################################
+
+=pod
+
+=item * &excess_filesize_authorspace()
+
+Returns warning message if upload of file to authoring space, or copying
+of existing file within authoring space will cause quota to be exceeded.
+
+Inputs: 6
+1. username
+2. domain
+3. directory path for top level of current authoring space
+4. filename of file for which action is being requested
+5. filesize (kB) of file
+6. action being taken: copy or upload.
+
+Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
+         otherwise return null. 
+
+=cut
+
+sub excess_filesize_authorspace {
+    my ($uname,$udom,$authorspace,$filename,$filesize,$action) = @_;
+    my $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author'); #expressed in MB
+    $disk_quota = int($disk_quota * 1000);
+    my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
+    if (($current_disk_usage + $filesize) > $disk_quota) {
+        return '<p><span class="LC_warning">'.
+                &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
+                    '<span class="LC_filename">'.$filename.'</span>',$filesize).'</span>'.
+               '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
+                            $disk_quota,$current_disk_usage).
+               '</p>';
+    }
+    return;
+}
+
+###############################################
+
+
 sub get_secgrprole_info {
     my ($cdom,$cnum,$needroles,$type)  = @_;
     my %sections_count = &get_sections($cdom,$cnum);
Index: loncom/publisher/loncfile.pm
diff -u loncom/publisher/loncfile.pm:1.119 loncom/publisher/loncfile.pm:1.120
--- loncom/publisher/loncfile.pm:1.119	Tue Jun  4 22:20:16 2013
+++ loncom/publisher/loncfile.pm	Wed Jul  3 05:03:19 2013
@@ -9,7 +9,7 @@
 #  and displays a page showing the results of the action.
 #
 #
-# $Id: loncfile.pm,v 1.119 2013/06/04 22:20:16 raeburn Exp $
+# $Id: loncfile.pm,v 1.120 2013/07/03 05:03:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -700,9 +700,21 @@
 	my ($type,$return)=&exists($user, $domain, $newfilename);
 	$request->print($return);
 	if ($type eq 'error') {
-	    $request->print('<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a>');
+	    $request->print('<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a></form>');
 	    return;
 	}
+# Check if there is enough space.
+        my @fileinfo = stat($fn);
+        my ($dir,$fname) = ($fn =~ m{^(.+/)([^/]+)$});
+        my $filesize = $fileinfo[7];
+        $filesize = int($filesize/1000); #expressed in kb
+        my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$domain/$user";
+        my $output = &Apache::loncommon::excess_filesize_authorspace($user,$domain,$authorspace,
+                                                                     $fname,$filesize,'copy');
+        if ($output) {
+            $request->print($output.'<br /><a href="'.&url($dir).'">'.&mt('Cancel').'</a></form>');
+            return;
+        }
     $request->print(
         '<input type="hidden" name="newfilename"'
        .' value="'.$newfilename.'" />'
Index: loncom/publisher/lonupload.pm
diff -u loncom/publisher/lonupload.pm:1.63 loncom/publisher/lonupload.pm:1.64
--- loncom/publisher/lonupload.pm:1.63	Tue Jul  2 19:04:49 2013
+++ loncom/publisher/lonupload.pm	Wed Jul  3 05:03:19 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to upload files into construction space
 #
-# $Id: lonupload.pm,v 1.63 2013/07/02 19:04:49 raeburn Exp $
+# $Id: lonupload.pm,v 1.64 2013/07/03 05:03:19 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -201,19 +201,14 @@
         return;
     }
     $filesize = int($filesize/1000); #expressed in kb
-    my $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author'); #expressed in Mb
-    $disk_quota = int($disk_quota * 1000);
-    my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
-    my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
-    if (($current_disk_usage + $filesize) > $disk_quota){
-        $r->print('<span class="LC_warning">'.
-                  &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$env{'form.upfile.filename'}.'</span>',$filesize).'</span>'.
-                  '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).
-                  '</p>'.
-                  &earlyout($fn,$uname,$udom));
+    my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
+    my $output = &Apache::loncommon::excess_filesize_authorspace($uname,$udom,$authorspace,
+                                                                 $env{'form.upfile.filename'},$filesize,'upload');
+    if ($output) {
+        $r->print($output.&earlyout($fn,$uname,$udom));
         return;
     }
-    
+
 # Split part that I can change from the part that I cannot change
     my ($fn1,$fn2)=($fn=~/^(\/priv\/[^\/]+\/[^\/]+\/)(.*)$/);
     # Display additional options for upload




More information about the LON-CAPA-cvs mailing list