MDL-28022 glossary entry without attachment can be exported to Mahara as Leap2A content
authorDavid Mudrak <david@moodle.com>
Fri, 1 Jul 2011 00:34:00 +0000 (02:34 +0200)
committerDavid Mudrak <david@moodle.com>
Fri, 1 Jul 2011 00:34:00 +0000 (02:34 +0200)
The problem here was that the manifest file was written into the
'./files/leap2a.xml' instead of the './leap2a.xml' in the ZIP package.
I believe there was a bug in the write_new_file() using the 3rd parameter
incorrectly. A detailed review of all other modules using the same
method must happen soon.

mod/glossary/locallib.php

index 03727b0..5dbe303 100644 (file)
@@ -303,19 +303,34 @@ class glossary_entry_portfolio_caller extends portfolio_module_caller_base {
      */
     public function prepare_package() {
         global $DB;
+
         $format = $this->exporter->get('format');
         $content = self::entry_content($this->course, $this->cm, $this->glossary, $this->entry, $this->aliases, $format);
-        $filename = clean_filename($this->entry->concept) . '.html';
-        if ($this->exporter->get('formatclass') == PORTFOLIO_FORMAT_LEAP2A) {
-            global $USER;
-            $writer = $this->get('exporter')->get('format')->leap2a_writer($USER);
-            $filename = $this->get('exporter')->get('format')->manifest_name();
+
+        if ($this->exporter->get('formatclass') === PORTFOLIO_FORMAT_PLAINHTML) {
+            $filename = clean_filename($this->entry->concept) . '.html';
+            $this->exporter->write_new_file($content, $filename);
+
+        } else if ($this->exporter->get('formatclass') === PORTFOLIO_FORMAT_RICHHTML) {
+            if ($this->multifiles) {
+                foreach ($this->multifiles as $file) {
+                    $this->exporter->copy_existing_file($file);
+                }
+            }
+            $filename = clean_filename($this->entry->concept) . '.html';
+            $this->exporter->write_new_file($content, $filename);
+
+        } else if ($this->exporter->get('formatclass') === PORTFOLIO_FORMAT_LEAP2A) {
+            $writer = $this->get('exporter')->get('format')->leap2a_writer();
             $entry = new portfolio_format_leap2a_entry('glossaryentry' . $this->entry->id, $this->entry->concept, 'entry', $content);
             $entry->author = $DB->get_record('user', array('id' => $this->entry->userid), 'id,firstname,lastname,email');
             $entry->published = $this->entry->timecreated;
             $entry->updated = $this->entry->timemodified;
             if ($this->multifiles) {
-                $writer->link_files($entry, $this->multifiles, 'glossaryentry' . $this->entry->id . 'file');
+                $writer->link_files($entry, $this->multifiles);
+                foreach ($this->multifiles as $file) {
+                    $this->exporter->copy_existing_file($file);
+                }
             }
             if ($this->categories) {
                 foreach ($this->categories as $cat) {
@@ -327,13 +342,12 @@ class glossary_entry_portfolio_caller extends portfolio_module_caller_base {
             }
             $writer->add_entry($entry);
             $content = $writer->to_xml();
+            $filename = $this->get('exporter')->get('format')->manifest_name();
+            $this->exporter->write_new_file($content, $filename);
+
+        } else {
+            throw new portfolio_caller_exception('unexpected_format_class', 'glossary');
         }
-        if ($this->multifiles) {
-            foreach ($this->multifiles as $file) {
-                $this->exporter->copy_existing_file($file);
-            }
-        }
-        return $this->exporter->write_new_file($content, $filename, !empty($this->multifiles));
     }
 
     /**