ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilExportContainer.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Export/classes/class.ilExportFileInfo.php';
5 include_once './Services/Export/classes/class.ilExport.php';
6 
7 
16 {
17  private $cont_export_dir = '';
18  private $cont_manifest_writer = null;
19  private $eo = null;
20 
21 
27  public function __construct(ilExportOptions $eo)
28  {
29  $this->eo = $eo;
31  }
32 
41  public function exportObject($a_type, $a_id, $a_target_release)
42  {
43  // Create base export directory
44  ilExport::_createExportDirectory($a_id, "xml", $a_type);
45  $export_dir = ilExport::_getExportDirectory($a_id, "xml", $a_type);
46  $ts = time();
47  $sub_dir = $ts."__".IL_INST_ID."__".$a_type."_".$a_id;
48 
49  $this->cont_export_dir = $export_dir.DIRECTORY_SEPARATOR.$sub_dir;
50  ilUtil::makeDirParents($this->cont_export_dir);
51 
52  $GLOBALS['ilLog']->write(__METHOD__.' using base directory: '.$this->export_run_dir);
53 
54  $this->manifestWriterBegin($a_type, $a_id, $a_target_release);
55  $this->addContainer();
56  $this->addSubitems($a_id,$a_type,$a_target_release);
57  $this->manifestWriterEnd($a_type, $a_id, $a_target_release);
58 
59  ilUtil::zip($this->cont_export_dir, $this->cont_export_dir.'.zip');
60  ilUtil::delDir($this->cont_export_dir);
61  }
62 
67  protected function manifestWriterBegin($a_type, $a_id, $a_target_release)
68  {
69  $GLOBALS['ilLog']->write(__METHOD__.': wrinting manifest');
70  include_once "./Services/Xml/classes/class.ilXmlWriter.php";
71  $this->cont_manifest_writer = new ilXmlWriter();
72  $this->cont_manifest_writer->xmlHeader();
73  $this->cont_manifest_writer->xmlStartTag(
74  'Manifest',
75  array(
76  "MainEntity" => $a_type,
77  "Title" => ilObject::_lookupTitle($a_id),
78  "TargetRelease" => $a_target_release,
79  "InstallationId" => IL_INST_ID,
80  "InstallationUrl" => ILIAS_HTTP_PATH)
81  );
82  }
83 
88  protected function addContainer()
89  {
90 
91  }
92 
93 
100  protected function addSubitems($a_id,$a_type,$a_target_release)
101  {
102  $set_number = 1;
103  foreach($this->eo->getSubitemsForExport() as $ref_id)
104  {
105  // get last export file
106  $obj_id = ilObject::_lookupObjId($ref_id);
107 
108  $expi = ilExportFileInfo::lookupLastExport($obj_id, 'xml',$a_target_release);
109 
110  if(!$expi instanceof ilExportFileInfo)
111  {
112  $GLOBALS['ilLog']->write(__METHOD__.': Cannot find export file for refId '.$ref_id.', type '.ilObject::_lookupType($a_id));
113  continue;
114  }
115 
116  $exp_dir = ilExport::_getExportDirectory($obj_id,'xml',ilObject::_lookupType($obj_id));
117  $exp_full = $exp_dir.DIRECTORY_SEPARATOR.$expi->getFilename();
118 
119  $GLOBALS['ilLog']->write(__METHOD__.': zip path '.$exp_full);
120 
121  // Unzip
122  ilUtil::unzip($exp_full,true,false);
123 
124  // create set directory
125  ilUtil::makeDirParents($this->cont_export_dir.DIRECTORY_SEPARATOR.'set_'.$set_number);
126 
127  // cut .zip
128  $new_path_rel = 'set_'.$set_number.DIRECTORY_SEPARATOR.$expi->getBasename();
129  $new_path_abs = $this->cont_export_dir.DIRECTORY_SEPARATOR.$new_path_rel;
130 
131  $GLOBALS['ilLog']->write(__METHOD__.': '.$new_path_rel.' '.$new_path_abs);
132 
133  // Move export
134  rename(
135  $exp_dir.DIRECTORY_SEPARATOR.$expi->getBasename(),
136  $new_path_abs
137  );
138 
139  $GLOBALS['ilLog']->write($exp_dir.DIRECTORY_SEPARATOR.$expi->getBasename().' -> '.$new_path_abs);
140 
141  // Delete latest container xml of source
142  if($a_id == $obj_id)
143  {
144  $expi->delete();
145  if(file_exists($exp_full))
146  {
147  $GLOBALS['ilLog']->write(__METHOD__.': Deleting'. $exp_full);
148  unlink($exp_full);
149  }
150  }
151 
152  $this->cont_manifest_writer->xmlElement(
153  'ExportSet',
154  array(
155  'Path' => $new_path_rel,
156  'Type' => ilObject::_lookupType($obj_id)
157  )
158  );
159 
160 
161  ++$set_number;
162  }
163  }
164 
172  protected function manifestWriterEnd($a_type, $a_id, $a_target_release)
173  {
174  $this->cont_manifest_writer->xmlEndTag('Manifest');
175  $GLOBALS['ilLog']->write(__METHOD__.': '.$this->cont_export_dir.DIRECTORY_SEPARATOR.'manifest.xml');
176  $this->cont_manifest_writer->xmlDumpFile($this->cont_export_dir.DIRECTORY_SEPARATOR.'manifest.xml',true);
177  }
178 }
179 ?>