]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14589 filedir location now fully configurable through file storage constructor
authorskodak <skodak>
Mon, 4 Aug 2008 13:21:38 +0000 (13:21 +0000)
committerskodak <skodak>
Mon, 4 Aug 2008 13:21:38 +0000 (13:21 +0000)
lib/file/file_storage.php
lib/file/stored_file.php
lib/moodlelib.php

index 40befb7987b1cb1bbe14fc9951237bd97d6b3cc3..948408c05fb29458fc0345881f66e0cd820b7411 100644 (file)
@@ -9,13 +9,8 @@ class file_storage {
      * Contructor
      * @param string $filedir full path to pool directory
      */
-    public function __construct() {
-        global $CFG;
-        if (isset($CFG->filedir)) {
-            $this->filedir = $CFG->filedir;
-        } else {
-            $this->filedir = $CFG->dataroot.'/filedir';
-        }
+    public function __construct($filedir) {
+        $this->filedir = $filedir;
 
         // make sure the file pool directory exists
         if (!is_dir($this->filedir)) {
@@ -28,6 +23,14 @@ class file_storage {
         }
     }
 
+    /**
+     * Returns location of filedir (file pool)
+     * @return string pathname 
+     */
+    public function get_filedir() {
+        return $this->filedir;
+    }
+
     /**
      * Calculates sha1 hash of unique full path name information
      * @param int $contextid
index b7bf489faed924a5093776c77923d0ecf9ade39d..02a4799b46739c36ee26b1752bb00431161df07b 100644 (file)
@@ -41,12 +41,7 @@ class stored_file {
      * @return ful path to pool file with file content
      **/
     protected function get_content_file_location() {
-        global $CFG;
-        if (isset($CFG->filedir)) {
-            $filedir = $CFG->filedir;
-        } else {
-            $filedir = $CFG->dataroot.'/filedir';
-        }
+        $filedir = $this->fs->get_filedir();
         $contenthash = $this->file_record->contenthash;
         $l1 = $contenthash[0].$contenthash[1];
         $l2 = $contenthash[2].$contenthash[3];
index b4999efbe2ed230926c5febb68283f9c2b805469..44c3afeac93f58141b0229d513ad1b8c34be6482 100644 (file)
@@ -4502,7 +4502,13 @@ function get_file_storage() {
 
     require_once("$CFG->libdir/filelib.php");
 
-    $fs = new file_storage();
+    if (isset($CFG->filedir)) {
+        $filedir = $CFG->filedir;
+    } else {
+        $filedir = $CFG->dataroot.'/filedir';
+    }
+
+    $fs = new file_storage($filedir);
 
     return $fs;
 }