81 $this->result =
false;
92 $this->import_directory = $a_val;
114 xml_set_object($a_xml_parser, $this);
115 xml_set_element_handler($a_xml_parser,
'handlerBeginTag',
'handlerEndTag');
116 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
129 public function handlerBeginTag($a_xml_parser,
string $a_name, array $a_attribs): void
137 if (isset($a_attribs[
"obj_id"])) {
139 if ($this->obj_id != -1 && (
int) $read_obj_id != -1 && $this->obj_id != (
int) $read_obj_id) {
141 "Object IDs (xml $read_obj_id and argument " . $this->obj_id .
") do not match!",
150 if ($a_name ===
"Version" && !isset($a_attribs[
"mode"])) {
152 $this->version = null;
153 if ($this->date === null) {
155 $this->date = $a_attribs[
"date"];
156 $this->usr_id = (
int) $a_attribs[
"usr_id"];
164 #echo $a_attribs["mode"]; 165 if (isset($a_attribs[
"mode"])) {
166 if ($a_attribs[
"mode"] ==
"GZIP") {
167 if (!function_exists(
"gzread")) {
169 "Deflating with gzip is not supported",
175 } elseif ($a_attribs[
"mode"] ==
"ZLIB") {
176 if (!function_exists(
"gzuncompress")) {
178 "Deflating with zlib (compress/uncompress) is not supported",
184 } elseif ($a_attribs[
"mode"] ==
"COPY") {
187 elseif ($a_attribs[
'mode'] ==
'REST') {
193 if ($a_name ===
"Version") {
194 $this->version = (
int) $a_attribs[
"version"];
195 $this->max_version = (
int) $a_attribs[
"max_version"];
196 $this->date = (
int) $a_attribs[
"date"];
197 $this->usr_id = (
int) $a_attribs[
"usr_id"];
198 $this->action = (string) $a_attribs[
"action"];
211 $this->cdata = trim($this->cdata);
213 $GLOBALS[
'DIC'][
'ilLog']->write(__METHOD__ .
': ' . $this->cdata);
217 $this->result =
true;
220 if ($this->cdata ===
'') {
224 $this->file->setFilename($this->cdata);
225 $this->file->setTitle($this->cdata);
229 $this->file->setTitle(trim($this->cdata));
232 $this->file->setDescription(trim($this->cdata));
235 $this->file->setRating((
bool) $this->cdata);
239 if ($a_name ===
"Version" && $this->version === null) {
246 $this->tmpFilename = $this->
getImportDirectory() .
"/" . self::normalizeRelativePath($this->cdata);
250 $this->tmpFilename = $storage->getStoredFilePath(self::normalizeRelativePath($this->cdata));
254 $this->tmpFilename = $baseDecodedFilename;
261 if (!$this->
fastGunzip($baseDecodedFilename, $this->tmpFilename)) {
263 "Deflating with fastzunzip failed",
267 unlink($baseDecodedFilename);
269 if (!$this->
fastGunzip($baseDecodedFilename, $this->tmpFilename)) {
271 "Deflating with fastDecompress failed",
275 unlink($baseDecodedFilename);
277 $this->tmpFilename = $baseDecodedFilename;
284 if ($this->version == $this->file->getVersion()) {
285 if (is_file($this->tmpFilename)) {
286 $this->file->setFileSize(filesize($this->tmpFilename));
290 if (!$this->file->getFileType()) {
292 $this->file->setFileType(MimeType::getMimeType($this->tmpFilename));
296 $this->versions[] = [
304 $this->version = null;
306 $this->usr_id = null;
321 if ($a_data !=
"\n") {
326 $this->cdata .= $a_data;
328 $this->cdata .= $a_data;
343 foreach ($this->versions as $version) {
344 if (!file_exists($version[
"tmpFilename"])) {
345 if (!isset($version[
"tmpFilename"])) {
349 $files = scandir(dirname($version[
"tmpFilename"]));
350 $version[
"tmpFilename"] = rtrim(
351 dirname($version[
"tmpFilename"]),
354 if (!file_exists($version[
"tmpFilename"])) {
361 if (filesize($version[
"tmpFilename"]) == 0) {
366 $import_file_version_path = $version[
"tmpFilename"];
368 $stream = Streams::ofResource(fopen($import_file_version_path,
'rb'));
369 $this->file->appendStream($stream, $this->file->getTitle());
394 return $this->result > 0;
409 $path = str_replace(
'\\',
'/', $path);
411 while (preg_match(
'#\p{C}+|^\./#u', $path)) {
412 $path = preg_replace(
'#\p{C}+|^\./#u',
'', $path);
416 foreach (explode(
'/', $path) as $part) {
430 return implode(
'/',
$parts);
435 $fh = fopen($filein,
'rb');
436 $fh2 = fopen($fileout,
'wb');
437 stream_filter_append($fh2,
'convert.base64-decode');
441 if ($chunk ===
false) {
444 fwrite($fh2, $chunk);
454 if (!file_exists($in) || !is_readable($in)) {
457 if ((!file_exists($out) && !is_writable(dirname($out)) || (file_exists($out) && !is_writable($out)))) {
461 $in_file = gzopen($in,
"rb");
462 $out_file = fopen($out,
"wb");
464 while (!gzeof($in_file)) {
465 $buffer = gzread($in_file, 4096);
466 fwrite($out_file, $buffer, 4096);
fastGunzip(string $in, string $out)
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
handler for begin of element
int $mode
Content compression mode, defaults to no compression.
static getLogger(string $a_component_id)
Get component logger.
startParsing()
stores xml data in array
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fastBase64Decode(string $filein, string $fileout)
handlerEndTag($a_xml_parser, string $a_name)
handler for end of element
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
start()
starts parsing an changes object by side effect.
static int $DECOMPRESSION_FAILED
static _removeEntriesForObject(int $a_obj_id)
remove all history entries for an object
string $tmpFilename
file of temporary file where we store the file content instead of in memory
__construct(ilObjFile $file, string $a_xml_data, int $obj_id=-1, int $mode=0)
Constructor.
static int $CONTENT_GZ_COMPRESSED
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
handlerCharacterData($a_xml_parser, string $a_data)
handler for character data
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static int $CONTENT_NOT_COMPRESSED
static normalizeRelativePath(string $path)
Normalize relative directories in a path.
static int $CONTENT_ZLIB_COMPRESSED
setHandlers($a_xml_parser)
set event handlers
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
setImportDirectory(?string $a_val)
Set import directory.
updateFileContents()
update file according to filename and version and create history entry has to be called after (!) fil...
static int $ID_DEFLATE_METHOD_MISMATCH
static __extractId(string $ilias_id, int $inst_id)
extract ref id from role title, e.g.
__construct(Container $dic, ilPlugin $plugin)
ilObjFile $file
Exercise object which has been parsed.
int $obj_id
this will be matched against the id in the xml in case we want to update an exercise ...
getImportDirectory()
Get import directory.
bool $result
result of parsing and updating
setXMLContent(string $a_xml_content)
setFileContents()
update file according to filename and version, does not update history has to be called after (!) fil...