Should fix bug when copy course files to another course see #3934

skala
Julio Montoya 14 years ago
parent 15c3d7aa29
commit b0e4ca1dad
  1. 16
      main/coursecopy/classes/CourseRestorer.class.php
  2. 140
      main/inc/lib/document.lib.php

@ -29,9 +29,9 @@ require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'document.lib.php';
define('FILE_SKIP', 1);
define('FILE_RENAME', 2);
define('FILE_OVERWRITE', 3);
define('FILE_SKIP', 1);
define('FILE_RENAME', 2);
define('FILE_OVERWRITE', 3);
define('UTF8_CONVERT', false);
@ -289,7 +289,7 @@ class CourseRestorer
$table = Database :: get_course_table(TABLE_DOCUMENT);
$resources = $this->course->resources;
foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) {
$path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
@ -300,7 +300,7 @@ class CourseRestorer
} else {
$my_session_id = $session_id;
}
if ($document->file_type == FOLDER) {
$visibility = $document->item_properties[0]['visibility'];
@ -321,8 +321,7 @@ class CourseRestorer
echo 'file type'; var_dump($document->file_type);
echo 'session'; var_dump($session_id);
echo 'file _exists'; var_dump($path.$document->path); var_dump(file_exists($path.$document->path));
*/
*/
if (!is_dir($path.dirname($document->path))) {
continue;
$visibility = $document->item_properties[0]['visibility'];
@ -338,7 +337,7 @@ class CourseRestorer
}
if (file_exists($path.$document->path)) {
//var_dump ('enter');
//var_dump($this->file_option);
switch ($this->file_option) {
case FILE_OVERWRITE :
@ -379,6 +378,7 @@ class CourseRestorer
//Replace old course code with the new destination code
$file_info = pathinfo($path.$document->path);
if (in_array($file_info['extension'], array('html','htm'))) {
$content = file_get_contents($path.$document->path);
if (UTF8_CONVERT) $content = utf8_encode($content);

@ -1907,74 +1907,98 @@ class DocumentManager {
$orig_course_info = api_get_course_info($origin_course_code);
$orig_course_path = api_get_path(SYS_PATH).'courses/'.$orig_course_info['path'].'/';
$destination_course_code = CourseManager::get_course_id_from_path ($destination_course_directory);
$destination_course_info = api_get_course_info($destination_course_code);
$dest_course_path = api_get_path(SYS_COURSE_PATH).$destination_course_directory.'/';
foreach ($orig_source_html as $source) {
// get information about source url
$real_orig_url = $source[0]; // url
$scope_url = $source[1]; // scope (local, remote)
$type_url = $source[2]; // tyle (rel, abs, url)
// Get path and query from origin url
$orig_parse_url = parse_url($real_orig_url);
$real_orig_path = $orig_parse_url['path'];
$real_orig_query = $orig_parse_url['query'];
// Replace origin course code by destination course code from origin url query
$dest_url_query = '';
if (!empty($real_orig_query)) {
$dest_url_query = '?'.$real_orig_query;
if (strpos($dest_url_query,$origin_course_code) !== false) {
$dest_url_query = str_replace($origin_course_code, $destination_course_code, $dest_url_query);
$user_id = api_get_user_id();
if (!empty($orig_source_html)) {
foreach ($orig_source_html as $source) {
// get information about source url
$real_orig_url = $source[0]; // url
$scope_url = $source[1]; // scope (local, remote)
$type_url = $source[2]; // tyle (rel, abs, url)
// Get path and query from origin url
$orig_parse_url = parse_url($real_orig_url);
$real_orig_path = $orig_parse_url['path'];
$real_orig_query = $orig_parse_url['query'];
// Replace origin course code by destination course code from origin url query
$dest_url_query = '';
if (!empty($real_orig_query)) {
$dest_url_query = '?'.$real_orig_query;
if (strpos($dest_url_query,$origin_course_code) !== false) {
$dest_url_query = str_replace($origin_course_code, $destination_course_code, $dest_url_query);
}
}
}
if ($scope_url == 'local') {
if ( $type_url == 'abs' || $type_url == 'rel') {
$document_file = strstr($real_orig_path, 'document');
if (strpos($real_orig_path,$document_file) !== false) {
$origin_filepath = $orig_course_path.$document_file;
$destination_filepath = $dest_course_path.$document_file;
// copy origin file inside destination course
if (file_exists($origin_filepath)) {
$filepath_dir = dirname($destination_filepath);
if (!is_dir($filepath_dir)) {
$perm = api_get_permissions_for_new_directories();
@mkdir($filepath_dir, $perm, true);
}
if (!file_exists($destination_filepath)) {
@copy($origin_filepath, $destination_filepath);
if ($scope_url == 'local') {
if ($type_url == 'abs' || $type_url == 'rel') {
$document_file = strstr($real_orig_path, 'document');
if (strpos($real_orig_path,$document_file) !== false) {
$origin_filepath = $orig_course_path.$document_file;
$destination_filepath = $dest_course_path.$document_file;
// copy origin file inside destination course
if (file_exists($origin_filepath)) {
$filepath_dir = dirname($destination_filepath);
if (!is_dir($filepath_dir)) {
$perm = api_get_permissions_for_new_directories();
$result = @mkdir($filepath_dir, $perm, true);
if ($result) {
$filepath_to_add = str_replace(array($dest_course_path, 'document'), '', $filepath_dir);
//Add to item properties to the new folder
$doc_id = add_document($destination_course_info, $filepath_to_add, 'folder', 0, basename($filepath_to_add));
api_item_property_update($destination_course_info, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $user_id, null, null, null, null);
}
}
if (!file_exists($destination_filepath)) {
$result = @copy($origin_filepath, $destination_filepath);
if ($result) {
$filepath_to_add = str_replace(array($dest_course_path, 'document'), '', $destination_filepath);
$size = filesize($destination_filepath);
//Add to item properties to the file
$doc_id = add_document($destination_course_info, $filepath_to_add, 'file', $size, basename($filepath_to_add));
api_item_property_update($destination_course_info, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $user_id, null, null, null, null);
}
}
}
}
// Replace origin course path by destination course path
if (strpos($content_html,$real_orig_url) !== false) {
//$origin_course_code
$url_course_path = str_replace($orig_course_info['path'].'/'.$document_file, '', $real_orig_path);
$destination_url = $url_course_path.$destination_course_directory.'/'.$document_file.$dest_url_query;
// Replace origin course path by destination course path
if (strpos($content_html,$real_orig_url) !== false) {
//$origin_course_code
$url_course_path = str_replace($orig_course_info['path'].'/'.$document_file, '', $real_orig_path);
$destination_url = $url_course_path.$destination_course_directory.'/'.$document_file.$dest_url_query;
//If the course code doesn't exist in the path? what we do? Nothing! see BT#1985
if (strpos($real_orig_path, $origin_course_code) === false) {
$url_course_path = $real_orig_path;
$destination_url = $real_orig_path;
//If the course code doesn't exist in the path? what we do? Nothing! see BT#1985
if (strpos($real_orig_path, $origin_course_code) === false) {
$url_course_path = $real_orig_path;
$destination_url = $real_orig_path;
}
$content_html = str_replace($real_orig_url, $destination_url, $content_html);
}
$content_html = str_replace($real_orig_url, $destination_url, $content_html);
}
}
// replace origin course code by destination course code from origin url
if (strpos($real_orig_url, '?') === 0) {
$dest_url = str_replace($origin_course_code, $destination_course_code, $real_orig_url);
$content_html = str_replace($real_orig_url, $dest_url, $content_html);
}
} else {
if ($type_url == 'url') {
// replace origin course code by destination course code from origin url
if (strpos($real_orig_url, '?') === 0) {
$dest_url = str_replace($origin_course_code, $destination_course_code, $real_orig_url);
$content_html = str_replace($real_orig_url, $dest_url, $content_html);
}
} else {
if ($type_url == 'url') {
}
}
}
}

Loading…
Cancel
Save