/** * main export routine */ public function export() { // the xml stuff $this->export_header(); $this->setup_links(); $this->notify_progress_callback(10, get_string('exportingviews', 'export')); $this->export_collections(); $this->export_views(); $this->notify_progress_callback(50, get_string('exportingartefacts', 'export')); $this->export_artefacts(); $this->notify_progress_callback(80, get_string('exportingartefactplugindata', 'export')); $internal = null; foreach ($this->specialcases as $plugin => $artefacts) { if ($plugin == 'internal') { $internal = $artefacts; continue; // do it last so other plugins can inject persondata } $classname = 'LeapExport' . ucfirst($plugin); $pluginexport = new $classname($this, $artefacts); $this->xml .= $pluginexport->get_export_xml(); } if (!empty($internal)) { $pluginexport = new LeapExportInternal($this, $internal); $this->xml .= $pluginexport->get_export_xml(); } $this->notify_progress_callback(85, get_string('exportingfooter', 'export')); $this->export_footer(); $this->notify_progress_callback(90, get_string('writingfiles', 'export')); // write out xml to a file if (!file_put_contents($this->exportdir . $this->leapfile, $this->xml)) { throw new SystemException("Couldn't write LEAP data to the file"); } // copy attachments over foreach ($this->attachments as $id => $fileinfo) { $existingfile = $fileinfo->file; $desiredname = $fileinfo->name; copy($existingfile, $this->exportdir . $this->filedir . $id . '-' . $desiredname); } $this->notify_progress_callback(95, get_string('creatingzipfile', 'export')); // zip everything up $cwd = getcwd(); $command = sprintf('%s %s %s %s %s', get_config('pathtozip'), get_config('ziprecursearg'), escapeshellarg($this->exportdir . $this->zipfile), escapeshellarg($this->leapfile), escapeshellarg($this->filedir)); $output = array(); chdir($this->exportdir); exec($command, $output, $returnvar); chdir($cwd); if ($returnvar != 0) { throw new SystemException('Failed to zip the export file: return code ' . $returnvar); } $this->notify_progress_callback(100, get_string('Done', 'export')); return $this->zipfile; }
/** * main export routine */ public function export() { global $SESSION; // the xml stuff $this->export_header(); $this->setup_links(); $this->notify_progress_callback(10, get_string('exportingviews', 'export')); if ($this->viewexportmode == PluginExport::EXPORT_LIST_OF_COLLECTIONS || $this->viewexportmode == PluginExport::EXPORT_ALL_VIEWS_COLLECTIONS) { $this->export_collections(); } $this->export_views(); $this->notify_progress_callback(50, get_string('exportingartefacts', 'export')); $this->export_artefacts(); $this->notify_progress_callback(80, get_string('exportingartefactplugindata', 'export')); $internal = null; foreach ($this->specialcases as $plugin => $artefacts) { if ($plugin == 'internal') { $internal = $artefacts; continue; // do it last so other plugins can inject persondata } $classname = 'LeapExport' . ucfirst($plugin); $pluginexport = new $classname($this, $artefacts); $this->xml .= $pluginexport->get_export_xml(); } if (!empty($internal)) { $pluginexport = new LeapExportInternal($this, $internal); $this->xml .= $pluginexport->get_export_xml(); } $this->notify_progress_callback(85, get_string('exportingfooter', 'export')); $this->export_footer(); $this->notify_progress_callback(90, get_string('writingfiles', 'export')); // Filter invalid XML characters out of the final product require_once 'file.php'; $this->xml = preg_replace(xml_filter_regex(), '', $this->xml); // write out xml to a file if (!file_put_contents($this->exportdir . $this->leapfile, $this->xml)) { $SESSION->add_error_msg(get_string('couldnotwriteLEAPdata', 'export')); } // copy attachments over foreach ($this->attachments as $id => $fileinfo) { $existingfile = $fileinfo->file; $desiredname = $fileinfo->name; if (!is_file($existingfile) || !copy($existingfile, $this->exportdir . $this->filedir . $id . '-' . $desiredname)) { $SESSION->add_error_msg(get_string('couldnotcopyattachment', 'export', $desiredname)); } } $this->notify_progress_callback(95, get_string('creatingzipfile', 'export')); // zip everything up try { create_zip_archive($this->exportdir, $this->zipfile, array($this->leapfile, $this->filedir)); } catch (SystemException $e) { throw new SystemException('Failed to zip the export file: ' . $e->getMessage()); } $this->notify_progress_callback(100, get_string('Done', 'export')); return $this->zipfile; }