Skip to content

Commit

Permalink
MDL-22982
Browse files Browse the repository at this point in the history
1. rename repository.class to lib.php
2. fixed repository_callback.php
3. repository_ajax use moodle default exception handler
4. improve file_get_user_used_space performance
  • Loading branch information
Dongsheng Cai committed Jul 5, 2010
1 parent 2d5a051 commit e35194b
Show file tree
Hide file tree
Showing 32 changed files with 1,511 additions and 1,588 deletions.
1 change: 1 addition & 0 deletions lang/en/repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
$string['instancesforothers'] = 'private instance(s)';
$string['invalidjson'] = 'Invalid JSON string';
$string['invalidplugin'] = 'Invalid repository {$a} plug-in';
$string['invalidfiletype'] = '{$a} filetype cannot be accepted.';
$string['invalidrepositoryid'] = 'Invalid repository ID';
$string['isactive'] = 'Active?';
$string['keyword'] = 'Keyword';
Expand Down
41 changes: 16 additions & 25 deletions lib/filelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,26 +514,17 @@ function file_get_draft_area_info($draftitemid) {
* @return int total bytes
*/
function file_get_user_used_space() {
global $DB, $CFG, $USER;
global $DB, $USER;

$usercontext = get_context_instance(CONTEXT_USER, $USER->id);

$totalbytes = 0;
$files = array();
//TODO: rewrite to true sql SUM(), this is goign to run out of memory if limits are hight!
$file_records = $DB->get_records('files', "contextid = ? AND component = 'user' AND filearea != 'draft'", array($usercontext->id));
foreach ($file_records as $file_record) {
if ($file_record->filename === '.') {
continue;
}
// doesn't count same files
if (!isset($files[$file_record->contenthash])) {
$totalbytes += $file_record->filesize;
} else {
$files[$file_record->contenthash] = true;
}
}
return (int)$totalbytes;
$sql = "SELECT SUM(files1.filesize) AS totalbytes FROM {files} files1
JOIN (SELECT contenthash, filename, MAX(id) AS id
FROM {files}
WHERE contextid = ? AND component = ? AND filearea != ?
GROUP BY contenthash, filename) files2 ON files1.id = files2.id";
$params = array('contextid'=>$usercontext->id, 'component'=>'user', 'filearea'=>'draft');
$record = $DB->get_record_sql($sql, $params);
return (int)$record->totalbytes;
}

/**
Expand Down Expand Up @@ -2874,7 +2865,7 @@ function __construct($module = 'repository'){
}

/**
* @todo Document this function
* Get cached value
*
* @global object
* @global object
Expand All @@ -2901,10 +2892,10 @@ public function get($param){
}

/**
* @todo Document this function
* Set cache value
*
* @global object
* @global object
* @global object $CFG
* @global object $USER
* @param mixed $param
* @param mixed $val
*/
Expand All @@ -2917,7 +2908,7 @@ public function set($param, $val){
}

/**
* @todo Document this function
* Remove cache files
*
* @param int $expire The number os seconds before expiry
*/
Expand All @@ -2936,8 +2927,8 @@ public function cleanup($expire){
/**
* delete current user's cache file
*
* @global object
* @global object
* @global object $CFG
* @global object $USER
*/
public function refresh(){
global $CFG, $USER;
Expand Down
2 changes: 1 addition & 1 deletion lib/simpletest/testrepositorylib.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
$repository_plugins = get_list_of_plugins('repository');

foreach ($repository_plugins as $plugin) {
require_once($CFG->dirroot . "/repository/$plugin/repository.class.php");
require_once($CFG->dirroot . "/repository/$plugin/lib.php");
Mock::generatePartial("repository_$plugin", "partialmock_$plugin", array('send_package'));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ public function get_file($uuid, $file = '') {
return array('path'=>$path, 'url'=>$url);
}

public function print_search($client_id) {
$str = parent::print_search($client_id);
public function print_search() {
$str = parent::print_search();
$str .= '<label>Space: </label><br /><select name="space">';
foreach ($this->user_session->stores as $v) {
$str .= '<option ';
Expand Down
File renamed without changes.
Loading

0 comments on commit e35194b

Please sign in to comment.