From ca50abdd5d77747a2506d15c248dd239712153f2 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 29 Oct 2013 16:56:20 +1100 Subject: [PATCH] MDL-41337 files: Fixed bug with accidental delete of the root directory --- lib/db/upgrade.php | 35 +++++++++++++++++++++++++++++++++++ lib/filelib.php | 2 +- version.php | 2 +- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 0d3cce710ff..aaedc61a134 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2206,5 +2206,40 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2013051402.06); } + if ($oldversion < 2013051402.10) { + // 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, 2013051402.10); + } + return true; } diff --git a/lib/filelib.php b/lib/filelib.php index 186abd33fa0..6c50e1721f1 100644 --- a/lib/filelib.php +++ b/lib/filelib.php @@ -807,7 +807,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()) { diff --git a/version.php b/version.php index 8e210040ebe..6843fc4e474 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2013051402.09; // 20130514 = branching date YYYYMMDD - do not modify! +$version = 2013051402.10; // 20130514 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches // .XX = incremental changes