Author: david
Date: Tue Sep  6 17:10:47 2011
New Revision: 9681

Log:
Enforce upload quotas for multi-file uploader. Refs issue #2023

Modified:
   trunk/apps/qubit/modules/digitalobject/actions/uploadAction.class.php
   trunk/js/multiFileUpload.js

Modified: trunk/apps/qubit/modules/digitalobject/actions/uploadAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/digitalobject/actions/uploadAction.class.php       
Tue Sep  6 16:40:50 2011        (r9680)
+++ trunk/apps/qubit/modules/digitalobject/actions/uploadAction.class.php       
Tue Sep  6 17:10:47 2011        (r9681)
@@ -28,6 +28,14 @@
       throw new sfException;
     }
 
+    $repo = $this->informationObject->getRepository(array('inherit' => true));
+
+    $uploadLimit = $repo->uploadLimit;
+    if (0 < $uploadLimit)
+    {
+      $uploadLimit *= pow(10,9); // Convert to bytes
+    }
+
     ProjectConfiguration::getActive()->loadHelpers('Qubit');
 
     $uploadFiles = array();
@@ -43,6 +51,19 @@
 
     foreach ($_FILES as $file)
     {
+      if (0 <= $uploadLimit && $uploadLimit < $repo->getDiskUsage() + 
$file['size'])
+      {
+        $uploadFiles = array('error' => $this->context->i18n->__(
+          '%1% upload limit of %2% GB exceeded for %3%', array(
+            '%1%' => sfConfig::get('app_ui_label_digitalobject'),
+            '%2%' => round($uploadLimit / pow(10, 9), 2), // convert to GB
+            '%4%' => $this->context->routing->generate(null, array($repo, 
'module' => 'repository')),
+            '%3%' => $repo->__toString())
+        ));
+
+        continue;
+      }
+
       // Get file extension
       $extension = substr($file['name'], strrpos($file['name'], '.'));
 

Modified: trunk/js/multiFileUpload.js
==============================================================================
--- trunk/js/multiFileUpload.js Tue Sep  6 16:40:50 2011        (r9680)
+++ trunk/js/multiFileUpload.js Tue Sep  6 17:10:47 2011        (r9681)
@@ -279,6 +279,19 @@
               // Layers for current upload
               var thumbnailLayer = $('#thumbnail-' + event.id);
 
+              if ('error' in upload)
+              {
+                var uploadDiv = $('#upload-' + event.id);
+
+                // Add error message
+                uploadDiv.prepend('<div class="error">' + upload.error + 
'</div>');
+
+                // Remove thumbnail box
+                thumbnailLayer.remove();
+
+                return;
+              }
+
               thumbnailLayer
                 // Render img tag
                 .html('<img src="' + Qubit.multiFileUpload.uploadTmpDir + '/' 
+ upload.thumb + '"/>')

-- 
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/qubit-commits?hl=en.

Reply via email to