18include_once
'./Services/Xml/classes/class.ilSaxParser.php';
19include_once
'Modules/File/classes/class.ilFileException.php';
20include_once
'Services/Utilities/classes/class.ilFileUtils.php';
117 $this->result =
false;
129 $this->importDirectory = $a_val;
140 return $this->importDirectory;
153 xml_set_object($a_xml_parser, $this);
154 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
155 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
175 $ilLog =
$DIC[
'ilLog'];
179 if (isset($a_attribs[
"obj_id"])) {
181 if ($this->obj_id != -1 && (
int) $read_obj_id != -1 && (
int) $this->obj_id != (
int) $read_obj_id) {
183 "Object IDs (xml $read_obj_id and argument " . $this->obj_id .
") do not match!",
188 if (isset($a_attribs[
"type"])) {
189 $this->file->setFileType($a_attribs[
"type"]);
191 $this->file->setVersion($a_attribs[
"version"]);
192 $this->file->setMaxVersion($a_attribs[
"max_version"]);
196 if ($a_name ===
"Version" && !isset($a_attribs[
"mode"])) {
198 $this->version =
null;
199 if ($this->date ===
null) {
201 $this->date = $a_attribs[
"date"];
202 $this->usr_id = $a_attribs[
"usr_id"];
210 $this->isReadingFile =
true;
212 #echo $a_attribs["mode"];
213 if (isset($a_attribs[
"mode"])) {
214 if ($a_attribs[
"mode"] ==
"GZIP") {
215 if (!function_exists(
"gzread")) {
220 } elseif ($a_attribs[
"mode"] ==
"ZLIB") {
221 if (!function_exists(
"gzuncompress")) {
226 } elseif ($a_attribs[
"mode"] ==
"COPY") {
229 elseif ($a_attribs[
'mode'] ==
'REST') {
235 if ($a_name ===
"Version") {
236 $this->version = $a_attribs[
"version"];
237 $this->max_version = $a_attribs[
"max_version"];
238 $this->date = $a_attribs[
"date"];
239 $this->usr_id = $a_attribs[
"usr_id"];
240 $this->action = $a_attribs[
"action"];
245 $this->file->setVersion($this->version);
259 $this->cdata = trim($this->cdata);
261 $GLOBALS[
'DIC'][
'ilLog']->write(__METHOD__ .
': ' . $this->cdata);
265 $this->result =
true;
268 if (strlen($this->cdata) == 0) {
272 $this->file->setFilename($this->cdata);
273 $this->file->setTitle($this->cdata);
277 $this->file->setTitle(trim($this->cdata));
280 $this->file->setDescription(trim($this->cdata));
283 $this->file->setRating((
bool) $this->cdata);
287 if ($a_name ===
"Version" && $this->version ===
null) {
292 $GLOBALS[
'DIC'][
'ilLog']->write($this->mode);
293 $this->isReadingFile =
false;
299 include_once
'./Services/WebServices/Rest/classes/class.ilRestFileStorage.php';
301 $this->tmpFilename = $storage->getStoredFilePath(self::normalizeRelativePath($this->cdata));
305 $this->tmpFilename = $baseDecodedFilename;
315 unlink($baseDecodedFilename);
320 unlink($baseDecodedFilename);
322 $this->tmpFilename = $baseDecodedFilename;
329 if ($this->version == $this->file->getVersion()) {
330 if (is_file($this->tmpFilename)) {
331 $this->file->setFileSize(filesize($this->tmpFilename));
335 if (!$this->file->getFileType()) {
337 $ilLog =
$DIC[
'ilLog'];
339 #$ilLog->write(__METHOD__.': Trying to detect mime type...');
340 include_once(
'./Services/Utilities/classes/class.ilFileUtils.php');
345 $this->versions[] = [
353 $this->version =
null;
355 $this->usr_id =
null;
373 if ($a_data !=
"\n") {
378 $handle = fopen($this->tmpFilename,
"a");
379 fwrite($handle, $a_data);
382 $this->cdata .= $a_data;
398 foreach ($this->versions as
$version) {
399 if (!file_exists(
$version[
"tmpFilename"])) {
400 if (!isset(
$version[
"tmpFilename"])) {
404 $files = scandir(dirname(
$version[
"tmpFilename"]));
406 "/") .
"/" . $files[2];
407 if (!file_exists(
$version[
"tmpFilename"])) {
414 if (filesize(
$version[
"tmpFilename"]) == 0) {
419 $import_file_version_path =
$version[
"tmpFilename"];
421 $stream = Streams::ofResource(fopen($import_file_version_path,
'rb'));
422 $this->file->appendStream($stream, $this->file->getTitle());
436 if ($this->file->getAction() !=
"" and $this->file->getAction() !=
null) {
437 ilHistory::_createEntry($this->file->getId(), $this->file->getAction(), $this->file->getFilename() .
"," . $this->file->getVersion() .
"," . $this->file->getMaxVersion());
439 ilHistory::_createEntry($this->file->getId(),
"replace", $this->file->getFilename() .
"," . $this->file->getVersion() .
"," . $this->file->getMaxVersion());
442 $this->file->notifyUpdate($this->file->getId(), $this->file->getDescription());
458 return $this->result > 0;
476 $path = str_replace(
'\\',
'/', $path);
478 while (preg_match(
'#\p{C}+|^\./#u', $path)) {
479 $path = preg_replace(
'#\p{C}+|^\./#u',
'', $path);
483 foreach (explode(
'/', $path) as $part) {
497 return implode(
'/', $parts);
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
An exception for terminatinating execution or to throw for unit testing.
Class Streams Stream factory which enables the user to create streams without the knowledge of the co...
Class to report exception.
static $ID_DEFLATE_METHOD_MISMATCH
static $DECOMPRESSION_FAILED
fastGunzip($in, $out)
fast uncompressing the file with the zlib-extension without memory consumption
static _lookupMimeType($a_file)
static fastBase64Decode($filein, $fileout)
decodes base encoded file row by row to prevent memory exhaust
getImportDirectory()
Get import directory.
setHandlers($a_xml_parser)
set event handlers
setFileContents()
update file according to filename and version, does not update history has to be called after (!...
updateFileContents()
update file according to filename and version and create history entry has to be called after (!...
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
static $CONTENT_ZLIB_COMPRESSED
setImportDirectory($a_val)
Set import directory.
start()
starts parsing an changes object by side effect.
__construct($file, $a_xml_data, $obj_id=-1, $mode=0)
Constructor.
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
static $CONTENT_GZ_COMPRESSED
static $CONTENT_NOT_COMPRESSED
static normalizeRelativePath($path)
Normalize relative directories in a path.
static _removeEntriesForObject($a_obj_id)
remove all history entries for an object
static _createEntry( $a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.
static getLogger($a_component_id)
Get component logger.
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
setXMLContent($a_xml_content)
startParsing()
stores xml data in array
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static __extractId($ilias_id, $inst_id)
extract ref id from role title, e.g.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc