Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 54a0a16b53f94e8d2cd7eacc293f48c2913ed0e9 1 parent 75d8d06
@marinaglancy marinaglancy authored
Showing with 37 additions and 2 deletions.
  1. +35 −0 lib/db/upgrade.php
  2. +1 −1  lib/filelib.php
  3. +1 −1  version.php
View
35 lib/db/upgrade.php
@@ -1794,5 +1794,40 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2012120306.05);
}
+ if ($oldversion < 2012120306.09) {
+ // 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, 2012120306.09);
+ }
+
return true;
}
View
2  lib/filelib.php
@@ -794,7 +794,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
2  version.php
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2012120306.08; // 20121203 = branching date YYYYMMDD - do not modify!
+$version = 2012120306.09; // 20121203 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches
// .XX = incremental changes
Please sign in to comment.
Something went wrong with that request. Please try again.