From d410d03d1332672abb52275c7fe1ec4458d8e884 Mon Sep 17 00:00:00 2001 From: ywarnier Date: Tue, 8 Mar 2011 23:01:02 -0500 Subject: [PATCH] Fix small problem in course copy when directory not registered in original course (CT#3059) --- main/coursecopy/classes/CourseRestorer.class.php | 11 ++++++++--- main/inc/lib/fileUpload.lib.php | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/main/coursecopy/classes/CourseRestorer.class.php b/main/coursecopy/classes/CourseRestorer.class.php index ece10f8a57..7ae3c41256 100755 --- a/main/coursecopy/classes/CourseRestorer.class.php +++ b/main/coursecopy/classes/CourseRestorer.class.php @@ -233,9 +233,14 @@ class CourseRestorer if (!is_dir($path.'document/'.$new)) { $created_dir = create_unexisting_directory($destination_course,api_get_user_id(),0, 0 ,$path.'document',$new,basename($new),$visibility); } - } - - if ($document->file_type == DOCUMENT) { + + } elseif ($document->file_type == DOCUMENT) { + if (!is_dir($path.dirname($document->path))) { + $visibility = $document->item_properties[0]['visibility']; + $new = substr($document->path, 8); + // This code fixes the possibility for a file without a directory entry to be + $created_dir = create_unexisting_directory($destination_course,api_get_user_id(),0, 0 ,$path.'document',$new,basename($new),$visibility,true); + } if (file_exists($path.$document->path)) { switch ($this->file_option) { diff --git a/main/inc/lib/fileUpload.lib.php b/main/inc/lib/fileUpload.lib.php index 5c3aaf82f0..1aa7b09547 100755 --- a/main/inc/lib/fileUpload.lib.php +++ b/main/inc/lib/fileUpload.lib.php @@ -1035,11 +1035,14 @@ function search_img_from_html($html_file) { * @param array $_course current course information * @param int $user_id current user id * @param string $desiredDirName complete path of the desired name + * @param string The visible name of the directory + * @param int Visibility (0 for invisible, 1 for visible, 2 for deleted) * @return string actual directory name if it succeeds, * boolean false otherwise */ function create_unexisting_directory($_course, $user_id, $to_group_id, $to_user_id, $base_work_dir, $desired_dir_name, $title = null, $visibility = '') { $nb = ''; + // add numerical suffix to directory if another one of the same number already exists while (file_exists($base_work_dir.$desired_dir_name.$nb)) { $nb += 1; }