Commit f3a7f485 authored by Petr Skoda's avatar Petr Skoda
Browse files

MDL-26452 fix resource mod regression breaking upgrade on Windows

parent d911c72b
......@@ -228,24 +228,22 @@ function xmldb_resource_upgrade($oldversion) {
$instances = $DB->get_recordset_sql($sql);
foreach ($instances as $instance) {
$context = get_context_instance(CONTEXT_MODULE, $instance->cmid);
$component = 'mod_resource';
$filearea = 'content';
$itemid = 0;
$filepath = file_correct_filepath(dirname($instance->mainfile));
$filename = basename($instance->mainfile);
file_set_sortorder($context->id, $component, $filearea, $itemid, $filepath, $filename, 1);
if (empty($instance->mainfile)) {
// weird
continue;
}
$context = get_context_instance(CONTEXT_MODULE, $instance->cmid, MUST_EXIST);
$parts = explode('/', $instance->mainfile);
$filename = array_pop($parts);
$filepath = implode('/', $parts);
file_set_sortorder($context->id, 'mod_resource', 'content', 0, $filepath, $filename, 1);
}
$instances->close();
/// Define field mainfile to be dropped from resource
$table = new xmldb_table('resource');
$field = new xmldb_field('mainfile');
/// Conditionally launch drop field mainfile
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
$dbman->drop_field($table, $field);
/// resource savepoint reached
upgrade_mod_savepoint(true, 2009080501, 'resource');
......
......@@ -67,12 +67,13 @@ if ($resource->tobemigrated) {
}
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder');
$files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder DESC, id ASC', false); // TODO: this is not very efficient!!
if (count($files) < 1) {
resource_print_filenotfound($resource, $cm, $course);
die;
} else {
$file = array_pop($files);
$file = reset($files);
unset($files);
}
if ($redirect) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment