Parcourir la source

Fix build and restore course assignment backcups - refs BT#13326

Angel Fernando Quiroz Campos il y a 7 ans
Parent
commit
4b5d432b8f

+ 38 - 0
main/inc/lib/fileManage.lib.php

@@ -265,6 +265,44 @@ function copyDirTo($source, $destination, $move = true)
     return true;
 }
 
+/**
+ * Copy a directory and its directories (not files) to an other area
+ *
+ * @param string $source the path of the directory to move
+ * @param string $destination the path of the new area
+ * @return bool false on error
+ */
+function copyDirWithoutFilesTo($source, $destination)
+{
+    $fs = new Filesystem();
+
+    if (!is_dir($source)) {
+        return false;
+    }
+
+    if (!$fs->exists($destination)) {
+        $fs->mkdir($destination);
+    }
+
+    $dirIterator = new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS);
+    $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::SELF_FIRST);
+
+    /** @var \SplFileInfo $item */
+    foreach ($iterator as $item) {
+        if ($item->isFile()) {
+            continue;
+        }
+
+        $newDir = $destination.'/'.$item->getFilename();
+
+        if (!$fs->exists($newDir)) {
+            $fs->mkdir($destination.'/'.$item->getFilename());
+        }
+    }
+
+    return true;
+}
+
 /**
  * Extracting extension of a filename
  *

+ 2 - 3
src/Chamilo/CourseBundle/Component/CourseCopy/CourseArchiver.php

@@ -151,10 +151,9 @@ class CourseArchiver
 
         // Copy work folders (only folders)
         if (isset($course->resources[RESOURCE_WORK]) && is_array($course->resources[RESOURCE_WORK])) {
-            $doc_dir = dirname($backup_dir.'/upload/work/');
+            $doc_dir = $backup_dir.'work';
             @mkdir($doc_dir, $perm_dirs, true);
-            // @todo: adjust to only create subdirs, but not copy files
-            copyDirTo($course->path.'upload/work/', $doc_dir, false);
+            copyDirWithoutFilesTo($course->path.'work/', $doc_dir);
         }
 
         if (isset($course->resources[RESOURCE_ASSET]) && is_array($course->resources[RESOURCE_ASSET])) {

+ 1 - 1
src/Chamilo/CourseBundle/Component/CourseCopy/CourseBuilder.php

@@ -156,7 +156,7 @@ class CourseBuilder
         }
 
         // Add asset
-        if (basename($course['course_image_source'] != 'course.png')) {
+        if ($course['course_image_source'] && basename($course['course_image_source']) != 'course.png') {
             // Add course image courses/XXX/course-pic85x85.png
             $asset = new Asset(
                 $course['course_image_source'],

+ 33 - 33
src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php

@@ -3325,15 +3325,6 @@ class CourseRestorer
                         }
                         break;
                     case FILE_OVERWRITE:
-                        // Creating folder.
-                        $workData = get_work_data_by_path(
-                            $path,
-                            $this->destination_course_info['real_id']
-                        );
-                        break;
-                    case FILE_RENAME:
-                        $obj->params['new_dir'] = $obj->params['title'];
-
                         if (!empty($this->course_origin_id)) {
                             $sql = 'SELECT * FROM '.$table_work_assignment.'
                                     WHERE
@@ -3352,33 +3343,42 @@ class CourseRestorer
                             $obj->params['ends_on'] = $row['ends_on'];
                             $obj->params['enable_qualification'] = $row['enable_qualification'];
                             $obj->params['add_to_calendar'] = !empty($row['add_to_calendar']) ? 1 : 0;
-
-                            if (empty($workData)) {
-                                addDir(
-                                    $obj->params,
-                                    api_get_user_id(),
-                                    $this->destination_course_info,
-                                    0,
-                                    $sessionId
-                                );
-                            } else {
-                                $workId = $workData['iid'];
-                                updateWork(
-                                    $workId,
-                                    $obj->params,
-                                    $this->destination_course_info,
-                                    $sessionId
-                                );
-                                updatePublicationAssignment(
-                                    $workId,
-                                    $obj->params,
-                                    $this->destination_course_info,
-                                    0
-                                );
-                            }
                         }
+                        //No break
+                    case FILE_RENAME:
+                        $workData = get_work_data_by_path(
+                            $path,
+                            $this->destination_course_info['real_id']
+                        );
                         break;
                 }
+
+                $obj->params['work_title'] = $obj->params['title'];
+                $obj->params['new_dir'] = $obj->params['title'];
+
+                if (empty($workData)) {
+                    addDir(
+                        $obj->params,
+                        api_get_user_id(),
+                        $this->destination_course_info,
+                        0,
+                        $sessionId
+                    );
+                } else {
+                    $workId = $workData['iid'];
+                    updateWork(
+                        $workId,
+                        $obj->params,
+                        $this->destination_course_info,
+                        $sessionId
+                    );
+                    updatePublicationAssignment(
+                        $workId,
+                        $obj->params,
+                        $this->destination_course_info,
+                        0
+                    );
+                }
             }
         }
     }