ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
4include_once './Services/Export/classes/class.ilExportFileInfo.php';
5include_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
28 {
29 $this->eo = $eo;
30 parent::__construct();
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 $GLOBALS['ilLog']->write(__METHOD__);
103 $set_number = 1;
104 foreach($this->eo->getSubitemsForExport() as $ref_id)
105 {
106 // get last export file
108
109 $expi = ilExportFileInfo::lookupLastExport($obj_id, 'xml',$a_target_release);
110
111 if(!$expi instanceof ilExportFileInfo)
112 {
113 $GLOBALS['ilLog']->write(__METHOD__.': Cannot find export file for refId '.$ref_id.', type '.ilObject::_lookupType($a_id));
114 continue;
115 }
116
117 $exp_dir = ilExport::_getExportDirectory($obj_id,'xml',ilObject::_lookupType($obj_id));
118 $exp_full = $exp_dir.DIRECTORY_SEPARATOR.$expi->getFilename();
119
120 $GLOBALS['ilLog']->write(__METHOD__.': zip path '.$exp_full);
121
122 // Unzip
123 ilUtil::unzip($exp_full,true,false);
124
125 // create set directory
126 ilUtil::makeDirParents($this->cont_export_dir.DIRECTORY_SEPARATOR.'set_'.$set_number);
127
128 // cut .zip
129 $new_path_rel = 'set_'.$set_number.DIRECTORY_SEPARATOR.$expi->getBasename();
130 $new_path_abs = $this->cont_export_dir.DIRECTORY_SEPARATOR.$new_path_rel;
131
132 $GLOBALS['ilLog']->write(__METHOD__.': '.$new_path_rel.' '.$new_path_abs);
133
134 // Move export
135 rename(
136 $exp_dir.DIRECTORY_SEPARATOR.$expi->getBasename(),
137 $new_path_abs
138 );
139
140 $GLOBALS['ilLog']->write($exp_dir.DIRECTORY_SEPARATOR.$expi->getBasename().' -> '.$new_path_abs);
141
142 // Delete latest container xml of source
143 if($a_id == $obj_id)
144 {
145 $expi->delete();
146 if(file_exists($exp_full))
147 {
148 $GLOBALS['ilLog']->write(__METHOD__.': Deleting'. $exp_full);
149 unlink($exp_full);
150 }
151 }
152
153 $this->cont_manifest_writer->xmlElement(
154 'ExportSet',
155 array(
156 'Path' => $new_path_rel,
157 'Type' => ilObject::_lookupType($obj_id)
158 )
159 );
160
161
162 ++$set_number;
163 }
164 }
165
173 protected function manifestWriterEnd($a_type, $a_id, $a_target_release)
174 {
175 $this->cont_manifest_writer->xmlEndTag('Manifest');
176 $GLOBALS['ilLog']->write(__METHOD__.': '.$this->cont_export_dir.DIRECTORY_SEPARATOR.'manifest.xml');
177 $this->cont_manifest_writer->xmlDumpFile($this->cont_export_dir.DIRECTORY_SEPARATOR.'manifest.xml',true);
178 }
179}
180?>
exportObject($a_type, $a_id, $a_target_release)
Export a container.
manifestWriterBegin($a_type, $a_id, $a_target_release)
Write container manifest.
addSubitems($a_id, $a_type, $a_target_release)
Add subitems.
manifestWriterEnd($a_type, $a_id, $a_target_release)
Write manifest footer.
__construct(ilExportOptions $eo)
Constructor.
addContainer()
Add container description.
@classDescription Stores information of creation date and versions of export files
static lookupLastExport($a_obj_id, $a_type, $a_version='')
Lookup last export.
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
_createExportDirectory($a_obj_id, $a_export_type="xml", $a_obj_type="")
Create export directory.
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
static _lookupType($a_id, $a_reference=false)
lookup object type
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static zip($a_dir, $a_file, $compress_content=false)
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
static makeDirParents($a_dir)
Create a new directory and all parent directories.
XML writer class.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
$ref_id
Definition: sahs_server.php:39