Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MDL-28221 Legacy resource URL pointing to the course itself are migra…
…ted 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.
  • Loading branch information
mudrd8mz committed Jul 11, 2011
1 parent 498c722 commit 47f5964
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions mod/resource/backup/moodle1/lib.php
Expand Up @@ -185,13 +185,17 @@ public function process_resource(array $data, array $raw) {
$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
Expand Down Expand Up @@ -247,6 +251,12 @@ protected function get_successor($type, $reference) {
$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';
Expand Down

0 comments on commit 47f5964

Please sign in to comment.