From 665120d4e644079570c5e283f58e9165409f5a31 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Mon, 11 Jul 2011 22:37:34 +0200 Subject: [PATCH] MDL-28221 Legacy resource URL pointing to the course itself are migrated as File module This patch replays the logic of resource_20_migrate() function. If a file is referred via URL to the course files of the course being backed up, then such a resource is converted to the File module (mod/resource) rather than URL module. --- mod/resource/backup/moodle1/lib.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mod/resource/backup/moodle1/lib.php b/mod/resource/backup/moodle1/lib.php index b18172b8da1..cb3fea39697 100644 --- a/mod/resource/backup/moodle1/lib.php +++ b/mod/resource/backup/moodle1/lib.php @@ -185,13 +185,17 @@ class moodle1_mod_resource_handler extends moodle1_mod_handler { $resource['intro'] = moodle1_converter::migrate_referenced_files($resource['intro'], $this->fileman); // convert the referenced file itself as a main file in the content area + $reference = $data['reference']; + if (strpos($reference, '$@FILEPHP@$') === 0) { + $reference = str_replace(array('$@FILEPHP@$', '$@SLASH@$', '$@FORCEDOWNLOAD@$'), array('', '/', ''), $reference); + } $this->fileman->filearea = 'content'; $this->fileman->itemid = 0; try { - $this->fileman->migrate_file('course_files/'.$data['reference'], '/', null, 1); + $this->fileman->migrate_file('course_files/'.$reference, '/', null, 1); } catch (moodle1_convert_exception $e) { // the file probably does not exist - $this->log('error migrating the resource main file', backup::LOG_WARNING, 'course_files/'.$data['reference']); + $this->log('error migrating the resource main file', backup::LOG_WARNING, 'course_files/'.$reference); } // write resource.xml @@ -247,6 +251,12 @@ class moodle1_mod_resource_handler extends moodle1_mod_handler { $name = 'imscp'; break; case 'file': + // if starts with $@FILEPHP@$ then it is URL link to a local course file + // to be migrated to the new resource module + if (strpos($reference, '$@FILEPHP@$') === 0) { + $name = null; + break; + } // if http:// https:// ftp:// OR starts with slash need to be converted to URL if (strpos($reference, '://') or strpos($reference, '/') === 0) { $name = 'url';