MDL-23985 removing all make_user_dir() and get_user_directories() usage
This commit is contained in:
@@ -288,7 +288,9 @@ class auth_plugin_mnet extends auth_plugin_base {
|
||||
foreach ((array) $remoteuser as $key => $val) {
|
||||
|
||||
// TODO: fetch image if it has changed
|
||||
//TODO: rewrite to use new file storage
|
||||
if ($key == 'imagehash') {
|
||||
/*
|
||||
$dirname = make_user_directory($localuser->id, true);
|
||||
$filename = "$dirname/f1.jpg";
|
||||
|
||||
@@ -316,6 +318,7 @@ class auth_plugin_mnet extends auth_plugin_base {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if($key == 'myhosts') {
|
||||
@@ -1105,6 +1108,9 @@ class auth_plugin_mnet extends auth_plugin_base {
|
||||
function fetch_user_image($username) {
|
||||
global $CFG, $DB;
|
||||
|
||||
//TODO: rewrite to use new file storage
|
||||
return false;
|
||||
/*
|
||||
if ($user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id))) {
|
||||
$filename1 = make_user_directory($user->id, true) . "/f1.jpg";
|
||||
$filename2 = make_user_directory($user->id, true) . "/f2.jpg";
|
||||
@@ -1118,6 +1124,7 @@ class auth_plugin_mnet extends auth_plugin_base {
|
||||
return $return;
|
||||
}
|
||||
return false;
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -203,13 +203,7 @@
|
||||
array('backup_code'=>$backup_unique_code, 'table_name'=>'user'), "", "id, old_id");
|
||||
|
||||
foreach ($backup_users as $user) {
|
||||
//Is this user needed in the backup?
|
||||
$userdir = make_user_directory($user->old_id, true);
|
||||
if (check_dir_exists($userdir)) {
|
||||
$count++;
|
||||
}
|
||||
//Do some output
|
||||
backup_flush(30);
|
||||
//TODO: deleted old user pic processing
|
||||
}
|
||||
$backup_users->close();
|
||||
//Gets the user data
|
||||
@@ -2456,6 +2450,8 @@
|
||||
array('backup_code'=>$preferences->backup_unique_code, 'table_name'=>'user'), "", "id, old_id");
|
||||
foreach ($backup_users as $user) {
|
||||
//If this user's directory exists, copy it
|
||||
//TODO: rewrite to use new file storage
|
||||
/*
|
||||
$userdir = make_user_directory($user->old_id, true);
|
||||
if (check_dir_exists($userdir)) {
|
||||
//first remove dirroot so we can split out the folders.
|
||||
@@ -2473,7 +2469,7 @@
|
||||
"$CFG->dataroot/temp/backup/$preferences->backup_unique_code/user_files/$group/$user->old_id");
|
||||
}
|
||||
//Do some output
|
||||
backup_flush(30);
|
||||
backup_flush(30);*/
|
||||
}
|
||||
$backup_users->close();
|
||||
|
||||
|
||||
+1
-19
@@ -2571,25 +2571,7 @@ define('RESTORE_GROUPS_GROUPINGS', 3);
|
||||
//If that user exists in backup_ids
|
||||
if ($user = backup_getid($restore->backup_unique_code,"user",$olduserid)) {
|
||||
//Only if user has been created now or if it existed previously, but he hasn't got an image (see bug 1123)
|
||||
$newuserdir = make_user_directory($user->new_id, true); // Doesn't create the folder, just returns the location
|
||||
|
||||
// restore images if new user or image does not exist yet
|
||||
if (!empty($user->new) or !check_dir_exists($newuserdir)) {
|
||||
if (make_user_directory($user->new_id)) { // Creates the folder
|
||||
$status = backup_copy_file($backup_location, $newuserdir, true);
|
||||
$counter ++;
|
||||
}
|
||||
//Do some output
|
||||
if ($counter % 2 == 0) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo ".";
|
||||
if ($counter % 40 == 0) {
|
||||
echo "<br />";
|
||||
}
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
}
|
||||
//TODO: user images are now in new file storage, old code deleted
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5109,81 +5109,6 @@ function get_file_packer($mimetype='application/zip') {
|
||||
return $fp[$mimetype];
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a directory for a particular user.
|
||||
*
|
||||
* @global object
|
||||
* @param int $userid The id of the user in question - maps to id field of 'user' table.
|
||||
* @param bool $test Whether we are only testing the return value (do not create the directory)
|
||||
* @return string|false Returns full path to directory if successful, false if not
|
||||
*/
|
||||
function make_user_directory($userid, $test=false) {
|
||||
global $CFG, $OUTPUT;
|
||||
|
||||
if (is_bool($userid) || $userid < 0 || !preg_match('/^[0-9]{1,10}$/', $userid) || $userid > 2147483647) {
|
||||
if (!$test) {
|
||||
echo $OUTPUT->notification("Given userid was not a valid integer! (" . gettype($userid) . " $userid)");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Generate a two-level path for the userid. First level groups them by slices of 1000 users, second level is userid
|
||||
$level1 = floor($userid / 1000) * 1000;
|
||||
|
||||
$userdir = "user/$level1/$userid";
|
||||
if ($test) {
|
||||
return $CFG->dataroot . '/' . $userdir;
|
||||
} else {
|
||||
return make_upload_directory($userdir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of full paths to user directories, indexed by their userids.
|
||||
*
|
||||
* @global object
|
||||
* @param bool $only_non_empty Only return directories that contain files
|
||||
* @param bool $legacy Search for user directories in legacy location (dataroot/users/userid) instead of (dataroot/user/section/userid)
|
||||
* @return array An associative array: userid=>array(basedir => $basedir, userfolder => $userfolder)
|
||||
*/
|
||||
function get_user_directories($only_non_empty=true, $legacy=false) {
|
||||
global $CFG, $OUTPUT;
|
||||
|
||||
$rootdir = $CFG->dataroot."/user";
|
||||
|
||||
if ($legacy) {
|
||||
$rootdir = $CFG->dataroot."/users";
|
||||
}
|
||||
$dirlist = array();
|
||||
|
||||
//Check if directory exists
|
||||
if (check_dir_exists($rootdir, true)) {
|
||||
if ($legacy) {
|
||||
if ($userlist = get_directory_list($rootdir, '', true, true, false)) {
|
||||
foreach ($userlist as $userid) {
|
||||
$dirlist[$userid] = array('basedir' => $rootdir, 'userfolder' => $userid);
|
||||
}
|
||||
} else {
|
||||
echo $OUTPUT->notification("no directories found under $rootdir");
|
||||
}
|
||||
} else {
|
||||
if ($grouplist =get_directory_list($rootdir, '', true, true, false)) { // directories will be in the form 0, 1000, 2000 etc...
|
||||
foreach ($grouplist as $group) {
|
||||
if ($userlist = get_directory_list("$rootdir/$group", '', true, true, false)) {
|
||||
foreach ($userlist as $userid) {
|
||||
$dirlist[$userid] = array('basedir' => $rootdir, 'userfolder' => $group . '/' . $userid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo $OUTPUT->notification("$rootdir does not exist!");
|
||||
return false;
|
||||
}
|
||||
return $dirlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current name of file on disk if it exists.
|
||||
*
|
||||
|
||||
@@ -389,25 +389,6 @@ class moodlelib_test extends UnitTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
function test_make_user_directory() {
|
||||
global $CFG;
|
||||
|
||||
// Test success conditions
|
||||
$this->assertEqual("$CFG->dataroot/user/0/0", make_user_directory(0, true));
|
||||
$this->assertEqual("$CFG->dataroot/user/0/1", make_user_directory(1, true));
|
||||
$this->assertEqual("$CFG->dataroot/user/0/999", make_user_directory(999, true));
|
||||
$this->assertEqual("$CFG->dataroot/user/1000/1000", make_user_directory(1000, true));
|
||||
$this->assertEqual("$CFG->dataroot/user/2147483000/2147483647", make_user_directory(2147483647, true)); // Largest int possible
|
||||
|
||||
// Test fail conditions
|
||||
$this->assertFalse(make_user_directory(2147483648, true)); // outside int boundary
|
||||
$this->assertFalse(make_user_directory(-1, true));
|
||||
$this->assertFalse(make_user_directory('string', true));
|
||||
$this->assertFalse(make_user_directory(false, true));
|
||||
$this->assertFalse(make_user_directory(true, true));
|
||||
|
||||
}
|
||||
|
||||
function test_shorten_text() {
|
||||
$text = "short text already no tags";
|
||||
$this->assertEqual($text, shorten_text($text));
|
||||
|
||||
Reference in New Issue
Block a user