19include_once
'./Services/Xml/classes/class.ilSaxParser.php';
20include_once
'Modules/File/classes/class.ilFileException.php';
21include_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;
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"])) {
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
460 .
$version[
"rollback_version"] .
"|"
461 .
$version[
"rollback_user_id"] .
","
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);
An exception for terminatinating execution or to throw for unit testing.
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
static rename($a_source, $a_target)
Rename a file.
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.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
Class FlySystemFileAccessTest.