MDL-23885 flattening filepool directory structure - hopefully this will lower the number of directories but still keep a reasonable number of files in each directory on large installs; see tracker for more details

This commit is contained in:
Petr Skoda
2010-08-25 21:45:34 +00:00
parent d533e6d7e3
commit d0b6f92a23
5 changed files with 83 additions and 7 deletions
+8
View File
@@ -5075,6 +5075,14 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
// Main savepoint reached
upgrade_main_savepoint(true, 2010080901);
}
if ($oldversion < 2010082502) {
// migrate file pool xx/xx/xx directory structure to xx/xx in older 2.0dev installs
upgrade_simplify_overkill_pool_structure();
upgrade_main_savepoint(true, 2010082502);
}
return true;
}
+71
View File
@@ -86,6 +86,8 @@ function upgrade_migrate_files_courses() {
global $DB, $CFG;
require_once($CFG->libdir.'/filelib.php');
set_config('upgradenewfilemirgation', 1);
$count = $DB->count_records('course');
$pbar = new progress_bar('migratecoursefiles', 500, true);
@@ -103,6 +105,75 @@ function upgrade_migrate_files_courses() {
return true;
}
/**
* Moodle 2.0dev was using xx/xx/xx file pool directory structure, this migrates the existing files to xx/xx.
* This will not be executed in production upgrades...
* @return void
*/
function upgrade_simplify_overkill_pool_structure() {
global $CFG, $OUTPUT;
if (isset($CFG->upgradenewfilemirgation)) {
// newer upgrade, directory structure is in the form xx/xx already
unset_config('upgradenewfilemirgation');
return;
}
$filedir = $CFG->dataroot.'/filedir'; // hardcoded hack, do not use elsewhere!!
echo $OUTPUT->notification("Changing file pool directory structure, this may take a while...", 'notifysuccess');
$dir_l1 = new DirectoryIterator($filedir);
foreach ($dir_l1 as $d1) {
if ($d1->isDot() or $d1->isLink() or !$d1->isDir()) {
continue;
}
$name1 = $d1->getFilename();
if (strlen($name1) != 2) {
continue; //weird
}
$dir_l2 = new DirectoryIterator("$filedir/$name1");
foreach ($dir_l2 as $d2) {
if ($d2->isDot() or $d2->isLink() or !$d2->isDir()) {
continue;
}
$name2 = $d2->getFilename();
if (strlen($name2) != 2) {
continue; //weird
}
$dir_l3 = new DirectoryIterator("$filedir/$name1/$name2");
foreach ($dir_l3 as $d3) {
if ($d3->isDot() or $d3->isLink() or !$d3->isDir()) {
continue;
}
$name3 = $d3->getFilename();
if (strlen($name3) != 2) {
continue; //weird
}
$dir_l4 = new DirectoryIterator("$filedir/$name1/$name2/$name3");
foreach ($dir_l4 as $d4) {
if (!$d4->isFile()) {
continue; //. or ..
}
upgrade_set_timeout(60*5); // set up timeout, may also abort execution
$newfile = "$filedir/$name1/$name2/".$d4->getFilename();
$oldfile = "$filedir/$name1/$name2/$name3/".$d4->getFilename();
if (!file_exists($newfile)) {
rename($oldfile, $newfile);
}
}
unset($d4);
unset($dir_l4);
rmdir("$filedir/$name1/$name2/$name3");
}
unset($d3);
unset($dir_l3); // release file handles
}
unset($d2);
unset($dir_l2); // release file handles
}
}
/**
* Internal function - do not use directly
*/
+2 -4
View File
@@ -1051,8 +1051,7 @@ class file_storage {
protected function path_from_hash($contenthash) {
$l1 = $contenthash[0].$contenthash[1];
$l2 = $contenthash[2].$contenthash[3];
$l3 = $contenthash[4].$contenthash[5];
return "$this->filedir/$l1/$l2/$l3";
return "$this->filedir/$l1/$l2";
}
/**
@@ -1066,8 +1065,7 @@ class file_storage {
protected function trash_path_from_hash($contenthash) {
$l1 = $contenthash[0].$contenthash[1];
$l2 = $contenthash[2].$contenthash[3];
$l3 = $contenthash[4].$contenthash[5];
return "$this->trashdir/$l1/$l2/$l3";
return "$this->trashdir/$l1/$l2";
}
/**
+1 -2
View File
@@ -97,8 +97,7 @@ class stored_file {
$contenthash = $this->file_record->contenthash;
$l1 = $contenthash[0].$contenthash[1];
$l2 = $contenthash[2].$contenthash[3];
$l3 = $contenthash[4].$contenthash[5];
return "$filedir/$l1/$l2/$l3/$contenthash";
return "$filedir/$l1/$l2/$contenthash";
}
/**
+1 -1
View File
@@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
$version = 2010082500; // YYYYMMDD = date of the last version bump
$version = 2010082502; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 Preview 4+ (Build: 20100825)'; // Human-friendly version name