From: dongsheng Date: Thu, 28 Aug 2008 06:23:23 +0000 (+0000) Subject: MDL-13766 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c9260130598438ab7a2cadc21c2a8a619c82ad9b;p=moodle.git MDL-13766 1. Change location of cached and downloaded files 2. Clean up expired cache files 3. Remove downloaded files after completing moving --- diff --git a/lib/filelib.php b/lib/filelib.php index 6837e4347c..adfcf0dbcb 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -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); diff --git a/repository/lib.php b/repository/lib.php index bb6c040c61..58fe1164d5 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -32,13 +32,13 @@ * * 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());