Author: david
Date: Tue Aug 16 17:11:54 2011
New Revision: 9513

Log:
Add getDiskUsage() method for finding total disk usage for digital objects in 
repository

Modified:
   trunk/lib/model/QubitRepository.php

Modified: trunk/lib/model/QubitRepository.php
==============================================================================
--- trunk/lib/model/QubitRepository.php Tue Aug 16 16:42:26 2011        (r9512)
+++ trunk/lib/model/QubitRepository.php Tue Aug 16 17:11:54 2011        (r9513)
@@ -152,6 +152,32 @@
     return options_for_select($selectOptions, $default, $options);
   }
 
+  /**
+   * Get disk space used by digital objects in this repository
+   *
+   * @return integer disk usage in bytes
+   */
+  public function getDiskUsage()
+  {
+    $du = 0;
+    $repoDir = sfConfig::get('app_upload_dir').'/repo/'.$this->id;
+
+    if (!file_exists($repoDir))
+    {
+      return 0;
+    }
+
+    // Derived from http://www.php.net/manual/en/function.filesize.php#94566
+    $iterator = new RecursiveIteratorIterator(new 
RecursiveDirectoryIterator($repoDir));
+    foreach ($iterator as $item)
+    {
+      $du += $item->getSize();
+    }
+
+    return $du;
+  }
+
+
   /**************
   Import methods
   ***************/

-- 
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