Procházet zdrojové kódy

Fix export question image when copying question

Angel Fernando Quiroz Campos před 8 roky
rodič
revize
e77a1f2b3c
1 změnil soubory, kde provedl 12 přidání a 4 odebrání
  1. 12 4
      main/exercise/question.class.php

+ 12 - 4
main/exercise/question.class.php

@@ -775,10 +775,18 @@ abstract class Question
 
         // if the question has got an ID and if the picture exists
         if ($this->id && !empty($this->picture)) {
-            $picture = explode('.', $this->picture);
-            $extension = $picture[sizeof($picture) - 1];
-            $picture = 'quiz-'.$questionId.'.'.$extension;
-            $result = @copy($source_path.'/'.$this->picture, $destination_path.'/'.$picture) ? true : false;
+            if (file_exists($source_path.'/'.$this->picture)) {
+                // for backward compatibility
+                $picture = explode('.', $this->picture);
+                $extension = $picture[sizeof($picture) - 1];
+                $picture = 'quiz-'.$questionId.'.'.$extension;
+                $result = @copy($source_path.'/'.$this->picture, $destination_path.'/'.$picture);
+            } else {
+                $imageInfo = DocumentManager::get_document_data_by_id($this->picture, $course_info['code']);
+                $picture = $this->generatePictureName();
+
+                $result = @copy($imageInfo['absolute_path'], $destination_path.'/'.$picture);
+            }
             // If copy was correct then add to the database
             if ($result) {
                 $sql = "UPDATE $TBL_QUESTIONS SET