]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-13766
authordongsheng <dongsheng>
Thu, 28 Aug 2008 06:23:23 +0000 (06:23 +0000)
committerdongsheng <dongsheng>
Thu, 28 Aug 2008 06:23:23 +0000 (06:23 +0000)
1. Change location of cached and downloaded files
2. Clean up expired cache files
3. Remove downloaded files after completing moving

lib/filelib.php
repository/lib.php

index 6837e4347c37333d58dec77fe4f8d2007442e9dd..adfcf0dbcb458b194faa1405b87e64dfbf63f55e 100644 (file)
@@ -1730,11 +1730,11 @@ class curl_cache {
     public $dir = '';
     function __construct(){
         global $CFG;
-        if (!file_exists($CFG->dataroot.'/repository/cache')) {
-            mkdir($CFG->dataroot.'/repository/cache/', 0777, true);
+        if (!file_exists($CFG->dataroot.'/cache/repository/')) {
+            mkdir($CFG->dataroot.'/cache/repository/', 0777, true);
         }
-        if(is_dir($CFG->dataroot.'/repository/cache')) {
-            $this->dir = $CFG->dataroot.'/repository/cache/';
+        if(is_dir($CFG->dataroot.'/cache/repository/')) {
+            $this->dir = $CFG->dataroot.'/cache/repository/';
         }
         if (empty($CFG->repository_cache_expire)) {
             $CFG->repository_cache_expire = 120;
@@ -1742,6 +1742,7 @@ class curl_cache {
     }
     public function get($param){
         global $CFG;
+        $this->cleanup($CFG->repository_cache_expire);
         $filename = md5(serialize($param));
         if(file_exists($this->dir.$filename)) {
             $lasttime = filemtime($this->dir.$filename);
index bb6c040c619192280891a94210a54f66727199c2..58fe1164d57b93133050bf0c257b4644c01a039f 100644 (file)
  *
  * class repository is an abstract class, some functions must be implemented in subclass.
  *
- * See an example of use of this library in repository/box/repository.class.php
+ * See an example of use of this library in repository/boxnet/repository.class.php
  *
  * A few notes :
  *   // options are stored as serialized format in database
  *   $options = array('api_key'=>'dmls97d8j3i9tn7av8y71m9eb55vrtj4',
  *                  'auth_token'=>'', 'path_root'=>'/');
- *   $repo    = new repository_xxx($options);
+ *   $repo = new repository_xxx($options);
  *   // print login page or a link to redirect to another page
  *   $repo->print_login();
  *   // call get_listing, and print result
@@ -133,11 +133,11 @@ abstract class repository {
      */
     public function get_file($url, $file = '') {
         global $CFG;
-        if (!file_exists($CFG->dataroot.'/repository/download')) {
-            mkdir($CFG->dataroot.'/repository/download/', 0777, true);
+        if (!file_exists($CFG->dataroot.'/temp/download')) {
+            mkdir($CFG->dataroot.'/temp/download/', 0777, true);
         }
-        if(is_dir($CFG->dataroot.'/repository/download')) {
-            $dir = $CFG->dataroot.'/repository/download/';
+        if(is_dir($CFG->dataroot.'/temp/download')) {
+            $dir = $CFG->dataroot.'/temp/download/';
         }
         if(empty($file)) {
             $file = uniqid('repo').'_'.time().'.tmp';
@@ -585,14 +585,14 @@ function repository_static_function($plugin, $function) {
  * @param string $filepath filepath in file area
  * @return array information of file in file pool
  */
-function repository_move_to_filepool($path, $name, $itemid, $filearea = 'user_draft', $filepath = '/') {
+function repository_move_to_filepool($path, $name, $itemid, $filearea = 'user_draft') {
     global $DB, $CFG, $USER;
     $context = get_context_instance(CONTEXT_USER, $USER->id);
     $entry = new object();
     $entry->filearea  = $filearea;
     $entry->contextid = $context->id;
     $entry->filename  = $name;
-    $entry->filepath  = $filepath;
+    $entry->filepath  = '/'.uniqid().'/';
     $entry->timecreated  = time();
     $entry->timemodified = time();
     if(is_numeric($itemid)) {
@@ -605,6 +605,7 @@ function repository_move_to_filepool($path, $name, $itemid, $filearea = 'user_dr
     $fs = get_file_storage();
     $browser = get_file_browser();
     if ($file = $fs->create_file_from_pathname($entry, $path)) {
+        $delete = unlink($path);
         $ret = $browser->get_file_info($context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
         if(!empty($ret)){
             return array('url'=>$ret->get_url(),'id'=>$file->get_itemid());