MDL-41337 files: Fixed bug with accidental delete of the root directory

This commit is contained in:
Marina Glancy 2013-10-29 16:56:20 +11:00
parent 68291f2d57
commit d90c811585
3 changed files with 37 additions and 2 deletions

View File

@ -2739,5 +2739,40 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2013102201.00);
}
if ($oldversion < 2013102500.01) {
// Find all fileareas that have missing root folder entry and add the root folder entry.
if (empty($CFG->filesrootrecordsfixed)) {
$sql = "SELECT distinct f1.contextid, f1.component, f1.filearea, f1.itemid
FROM {files} f1 left JOIN {files} f2
ON f1.contextid = f2.contextid
AND f1.component = f2.component
AND f1.filearea = f2.filearea
AND f1.itemid = f2.itemid
AND f2.filename = '.'
AND f2.filepath = '/'
WHERE (f1.component <> 'user' or f1.filearea <> 'draft')
and f2.id is null";
$rs = $DB->get_recordset_sql($sql);
$defaults = array('filepath' => '/',
'filename' => '.',
'userid' => $USER->id,
'filesize' => 0,
'timecreated' => time(),
'timemodified' => time(),
'contenthash' => sha1(''));
foreach ($rs as $r) {
$pathhash = sha1("/$r->contextid/$r->component/$r->filearea/$r->itemid".'/.');
$DB->insert_record('files', (array)$r + $defaults +
array('pathnamehash' => $pathhash));
}
$rs->close();
// To skip running the same script on the upgrade to the next major release.
set_config('filesrootrecordsfixed', 1);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2013102500.01);
}
return true;
}

View File

@ -832,7 +832,7 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea
$newhashes = array();
$filecount = 0;
foreach ($draftfiles as $file) {
if (!$options['subdirs'] && ($file->get_filepath() !== '/' or $file->is_directory())) {
if (!$options['subdirs'] && $file->get_filepath() !== '/') {
continue;
}
if (!$allowreferences && $file->is_external_file()) {

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2013102500.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2013102500.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.