ILIAS  release_7 Revision v7.30-3-g800a261c036
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;
31 }
32
41 public function exportObject($a_type, $a_id, $a_target_release = "")
42 {
43 $log = $GLOBALS['DIC']->logger()->exp();
44
45 // if no target release specified, use latest major release number
46 if ($a_target_release == "") {
47 $v = explode(".", ILIAS_VERSION_NUMERIC);
48 $a_target_release = $v[0] . "." . $v[1] . ".0";
49 }
50
51 // Create base export directory
52 ilExport::_createExportDirectory($a_id, "xml", $a_type);
53 $export_dir = ilExport::_getExportDirectory($a_id, "xml", $a_type);
54 $ts = time();
55 $sub_dir = $ts . "__" . IL_INST_ID . "__" . $a_type . "_" . $a_id;
56
57 $this->cont_export_dir = $export_dir . DIRECTORY_SEPARATOR . $sub_dir;
58 ilUtil::makeDirParents($this->cont_export_dir);
59
60 $log->debug('Using base directory: ' . $this->export_run_dir);
61
62 $this->manifestWriterBegin($a_type, $a_id, $a_target_release);
63 $this->addContainer();
64 $this->addSubitems($a_id, $a_type, $a_target_release);
65 $this->manifestWriterEnd($a_type, $a_id, $a_target_release);
66
67 ilUtil::zip($this->cont_export_dir, $this->cont_export_dir . '.zip');
68 ilUtil::delDir($this->cont_export_dir);
69 }
70
75 protected function manifestWriterBegin($a_type, $a_id, $a_target_release)
76 {
77 include_once "./Services/Xml/classes/class.ilXmlWriter.php";
78 $this->cont_manifest_writer = new ilXmlWriter();
79 $this->cont_manifest_writer->xmlHeader();
80 $this->cont_manifest_writer->xmlStartTag(
81 'Manifest',
82 array(
83 "MainEntity" => $a_type,
84 "Title" => ilObject::_lookupTitle($a_id),
85 /* "TargetRelease" => $a_target_release, */
86 "InstallationId" => IL_INST_ID,
87 "InstallationUrl" => ILIAS_HTTP_PATH)
88 );
89 }
90
95 protected function addContainer()
96 {
97 }
98
99
106 protected function addSubitems($a_id, $a_type, $a_target_release)
107 {
108 global $DIC;
109
110 $logger =
111
112 $set_number = 1;
113 foreach ($this->eo->getSubitemsForExport() as $ref_id) {
114 // get last export file
115 $obj_id = ilObject::_lookupObjId($ref_id);
116
117 $expi = ilExportFileInfo::lookupLastExport($obj_id, 'xml', $a_target_release);
118
119 if (!$expi instanceof ilExportFileInfo) {
120 $this->log->warning('Cannot find export file for refId ' . $ref_id . ', type ' . ilObject::_lookupType($a_id));
121 continue;
122 }
123
124 $exp_dir = ilExport::_getExportDirectory($obj_id, 'xml', ilObject::_lookupType($obj_id));
125 $exp_full = $exp_dir . DIRECTORY_SEPARATOR . $expi->getFilename();
126
127 $this->log->debug('Zip path ' . $exp_full);
128
129 // Unzip
130 ilUtil::unzip($exp_full, true, false);
131
132 // create set directory
133 ilUtil::makeDirParents($this->cont_export_dir . DIRECTORY_SEPARATOR . 'set_' . $set_number);
134
135 // cut .zip
136 $new_path_rel = 'set_' . $set_number . DIRECTORY_SEPARATOR . $expi->getBasename();
137 $new_path_abs = $this->cont_export_dir . DIRECTORY_SEPARATOR . $new_path_rel;
138
139 $this->log->debug($new_path_rel . ' ' . $new_path_abs);
140
141 // Move export
142 rename(
143 $exp_dir . DIRECTORY_SEPARATOR . $expi->getBasename(),
144 $new_path_abs
145 );
146
147 $this->log->debug($exp_dir . DIRECTORY_SEPARATOR . $expi->getBasename() . ' -> ' . $new_path_abs);
148
149 // Delete latest container xml of source
150 if ($a_id == $obj_id) {
151 $expi->delete();
152 if (file_exists($exp_full)) {
153 $this->log->info('Deleting' . $exp_full);
154 unlink($exp_full);
155 }
156 }
157
158 $this->cont_manifest_writer->xmlElement(
159 'ExportSet',
160 array(
161 'Path' => $new_path_rel,
162 'Type' => ilObject::_lookupType($obj_id)
163 )
164 );
165
166
167 ++$set_number;
168 }
169 }
170
178 protected function manifestWriterEnd($a_type, $a_id, $a_target_release)
179 {
180 $this->cont_manifest_writer->xmlEndTag('Manifest');
181 $this->log->debug($this->cont_export_dir . DIRECTORY_SEPARATOR . 'manifest.xml');
182 $this->cont_manifest_writer->xmlDumpFile($this->cont_export_dir . DIRECTORY_SEPARATOR . 'manifest.xml', true);
183 }
184}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
manifestWriterBegin($a_type, $a_id, $a_target_release)
Write container manifest.
addSubitems($a_id, $a_type, $a_target_release)
Add subitems.
exportObject($a_type, $a_id, $a_target_release="")
Export a container.
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.
static _createExportDirectory($a_obj_id, $a_export_type="xml", $a_obj_type="")
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)
zips given directory/file into given zip.file
static unzip(string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
static makeDirParents($a_dir)
Create a new directory and all parent directories.
XML writer class.
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
const ILIAS_VERSION_NUMERIC
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc