19 include_once
'./Services/Xml/classes/class.ilSaxParser.php';
20 include_once
'Modules/File/classes/class.ilFileException.php';
21 include_once
'Services/Utilities/classes/class.ilFileUtils.php';
122 parent::__construct();
126 $this->result =
false;
138 $this->importDirectory = $a_val;
149 return $this->importDirectory;
162 xml_set_object($a_xml_parser, $this);
163 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
164 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
188 if (isset($a_attribs[
"obj_id"])) {
190 if ($this->obj_id != -1 && (
int) $read_obj_id != -1 && (
int) $this->obj_id != (
int) $read_obj_id) {
192 "Object IDs (xml $read_obj_id and argument " . $this->obj_id .
") do not match!",
197 if (isset($a_attribs[
"type"])) {
198 $this->file->setFileType($a_attribs[
"type"]);
200 $this->file->setVersion($a_attribs[
"version"]);
201 $this->file->setMaxVersion($a_attribs[
"max_version"]);
202 $this->file->setAction($a_attribs[
"action"]);
203 $this->file->setRollbackVersion($a_attribs[
"rollback_version"]);
204 $this->file->setRollbackUserId($a_attribs[
"rollback_user_id"]);
208 if ($a_name ===
"Version" && !isset($a_attribs[
"mode"])) {
210 $this->version = null;
211 if ($this->date === null) {
213 $this->date = $a_attribs[
"date"];
214 $this->usr_id = $a_attribs[
"usr_id"];
222 $this->isReadingFile =
true;
224 #echo $a_attribs["mode"]; 225 if (isset($a_attribs[
"mode"])) {
226 if ($a_attribs[
"mode"] ==
"GZIP") {
227 if (!function_exists(
"gzread")) {
232 } elseif ($a_attribs[
"mode"] ==
"ZLIB") {
233 if (!function_exists(
"gzuncompress")) {
238 } elseif ($a_attribs[
"mode"] ==
"COPY") {
241 elseif ($a_attribs[
'mode'] ==
'REST') {
247 if ($a_name ===
"Version") {
248 $this->version = $a_attribs[
"version"];
249 $this->max_version = $a_attribs[
"max_version"];
250 $this->date = $a_attribs[
"date"];
251 $this->usr_id = $a_attribs[
"usr_id"];
252 $this->action = $a_attribs[
"action"];
253 $this->rollback_version = $a_attribs[
"rollback_version"];
254 $this->rollback_user_id = $a_attribs[
"rollback_user_id"];
259 $this->file->setVersion($this->version);
273 $this->cdata = trim($this->cdata);
275 $GLOBALS[
'DIC'][
'ilLog']->write(__METHOD__ .
': ' . $this->cdata);
279 $this->result =
true;
282 if (strlen($this->cdata) == 0) {
286 $this->file->setFilename(basename(self::normalizeRelativePath($this->cdata)));
287 $this->file->setTitle($this->cdata);
291 $this->file->setTitle(trim($this->cdata));
294 $this->file->setDescription(trim($this->cdata));
297 $this->file->setRating((
bool) $this->cdata);
301 if ($a_name ===
"Version" && $this->version === null) {
306 $GLOBALS[
'DIC'][
'ilLog']->write($this->mode);
307 $this->isReadingFile =
false;
310 $this->tmpFilename = $this->
getImportDirectory() .
"/" . self::normalizeRelativePath($this->cdata);
313 include_once
'./Services/WebServices/Rest/classes/class.ilRestFileStorage.php';
315 $this->tmpFilename = $storage->getStoredFilePath(self::normalizeRelativePath($this->cdata));
319 $this->tmpFilename = $baseDecodedFilename;
329 unlink($baseDecodedFilename);
334 unlink($baseDecodedFilename);
336 $this->tmpFilename = $baseDecodedFilename;
340 if ($this->version == $this->file->getVersion()) {
342 $rel = LegacyPathHelper::createRelativePath($this->tmpFilename);
343 if ($DIC->filesystem()->temp()->has($rel)) {
344 $this->file->setFileSize($DIC->filesystem()->temp()->getSize($rel, DataSize::Byte)->getSize());
346 $array = $DIC->filesystem()->temp()->listContents(dirname($rel));
347 $first_file = reset($array);
350 $this->file->setFileSize($DIC->filesystem()->temp()->getSize($first_file->getPath(),
351 DataSize::Byte)->getSize());
356 if (!$this->file->getFileType()) {
360 #$ilLog->write(__METHOD__.': Trying to detect mime type...'); 361 include_once(
'./Services/Utilities/classes/class.ilFileUtils.php');
366 $this->versions[] = [
376 $this->version = null;
378 $this->usr_id = null;
396 if ($a_data !=
"\n") {
401 $handle =
fopen($this->tmpFilename,
"a");
402 fwrite($handle, $a_data);
405 $this->cdata .= $a_data;
421 foreach ($this->versions as
$version) {
422 if (!file_exists($version[
"tmpFilename"])) {
424 $files = scandir(dirname($version[
"tmpFilename"]));
425 $version[
"tmpFilename"] = rtrim(dirname($version[
"tmpFilename"]),
427 if (!file_exists($version[
"tmpFilename"])) {
434 if (filesize($version[
"tmpFilename"]) == 0) {
438 $filedir = $this->file->getDirectory($version[
"version"]);
440 if (!is_dir($filedir)) {
441 $this->file->createDirectory();
445 $filename = $filedir .
"/" . $this->file->getFileName();
455 if ($version[
"rollback_version"] !=
"" and $version[
"rollback_version"] != null
456 and $version[
"rollback_user_id"] !=
"" and $version[
"rollback_user_id"] != null
459 . $version[
"version"] .
"|" 460 . $version[
"rollback_version"] .
"|" 461 . $version[
"rollback_user_id"] .
"," 462 . $version[
"max_version"]);
464 if ($version[
"action"] !=
"" and $version[
"action"] != null) {
466 . $version[
"version"] .
"," 467 . $version[
"max_version"]);
470 . $version[
"version"] .
"," 471 . $version[
"max_version"]);
486 require_once(
"./Services/History/classes/class.ilHistory.php");
487 if ($this->file->getRollbackVersion() !=
"" and $this->file->getRollbackVersion() != null
488 and $this->file->getRollbackUserId() !=
"" and $this->file->getRollbackUserId() != null
490 ilHistory::_createEntry($this->file->getId(), $this->file->getAction(), $this->file->getFilename() .
"," . $this->file->getVersion() .
"," . $this->file->getMaxVersion()
491 .
"|" . $this->file->getRollbackVersion() .
"|" . $this->file->getRollbackUserId());
493 if ($this->file->getAction() !=
"" and $this->file->getAction() != null) {
494 ilHistory::_createEntry($this->file->getId(), $this->file->getAction(), $this->file->getFilename() .
"," . $this->file->getVersion() .
"," . $this->file->getMaxVersion());
496 ilHistory::_createEntry($this->file->getId(),
"replace", $this->file->getFilename() .
"," . $this->file->getVersion() .
"," . $this->file->getMaxVersion());
499 $this->file->addNewsNotification(
"file_updated");
515 return $this->result > 0;
535 while (preg_match(
'#\p{C}+|^\./#u',
$path)) {
536 $path = preg_replace(
'#\p{C}+|^\./#u',
'',
$path);
540 foreach (explode(
'/',
$path) as $part) {
554 return implode(
'/', $parts);
setImportDirectory($a_val)
Set import directory.
static $DECOMPRESSION_FAILED
static normalizeRelativePath($path)
Normalize relative directories in a path.
startParsing()
stores xml data in array
Exercise XML Parser which completes/updates a given file by an xml string.
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.
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
start()
starts parsing an changes object by side effect.
static _lookupMimeType($a_file)
static rename($a_source, $a_target)
Rename a file.
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
static $CONTENT_ZLIB_COMPRESSED
Class to report exception.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
__construct($file, $a_xml_data, $obj_id=-1, $mode=0)
Constructor.
static $ID_DEFLATE_METHOD_MISMATCH
setHandlers($a_xml_parser)
set event handlers
static ilTempnam($a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static fastBase64Decode($filein, $fileout)
decodes base encoded file row by row to prevent memory exhaust
static $CONTENT_GZ_COMPRESSED
updateFileContents()
update file according to filename and version and create history entry has to be called after (!) fil...
static _removeEntriesForObject($a_obj_id)
remove all history entries for an object
static getLogger($a_component_id)
Get component logger.
fastGunzip($in, $out)
fast uncompressing the file with the zlib-extension without memory consumption
getImportDirectory()
Get import directory.
setXMLContent($a_xml_content)
static __extractId($ilias_id, $inst_id)
extract ref id from role title, e.g.
static $CONTENT_NOT_COMPRESSED
Class FlySystemFileAccessTest.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
setFileContents()
update file according to filename and version, does not update history has to be called after (!) fil...