19 declare(strict_types=1);
67 $this->db = $DIC->database();
72 $this->content_style_domain = $DIC
76 $this->
setXMLContent(
'<?xml version="1.0" encoding="utf-8"?>' . $a_xml_data);
81 $this->importDirectory = $a_val;
101 xml_set_object($a_xml_parser, $this);
102 xml_set_element_handler($a_xml_parser,
function (XMLParser $a_xml_parser,
string $a_name, array $a_attribs):
void {
104 },
function (XMLParser $a_xml_parser,
string $a_name):
void {
107 xml_set_character_data_handler($a_xml_parser,
function (XMLParser $a_xml_parser,
string $a_data):
void {
112 public function handlerBeginTag(XMLParser $a_xml_parser,
string $a_name, array $a_attribs): void
116 $this->entity =
'forum';
117 $this->forumArray = [];
121 $this->entity =
'thread';
122 $this->threadArray = [];
126 $this->entity =
'post';
127 $this->postArray = [];
128 $this->mediaObjects = [];
132 $this->entity =
'content';
133 $this->contentArray = [
139 $this->mediaObjects[] = $a_attribs;
143 if (isset($a_attribs[
'Style'])) {
144 $this->last_handled_style_id = (
int) $a_attribs[
'Style'];
148 public function handlerEndTag(XMLParser $a_xml_parser,
string $a_name): void
150 $this->cdata = trim($this->cdata);
151 $property = strtolower($this->entity) .
'Array';
153 if (!property_exists($this, $property)) {
157 $propertyValue = &$this->{$property};
161 $query_num_posts =
"SELECT COUNT(pos_pk) cnt FROM frm_posts WHERE pos_top_fk = " . $this->db->quote(
162 $this->lastHandledForumId,
165 $res_pos = $this->db->query($query_num_posts);
166 $data_pos = $this->db->fetchAssoc($res_pos);
167 $num_posts = (
int) $data_pos[
'cnt'];
169 $query_num_threads =
"SELECT COUNT(thr_pk) cnt FROM frm_threads WHERE thr_top_fk = " . $this->db->quote(
170 $this->lastHandledForumId,
173 $res_thr = $this->db->query($query_num_threads);
174 $data_thr = $this->db->fetchAssoc($res_thr);
175 $num_threads = (
int) $data_thr[
'cnt'];
178 if ($this->lastHandledPostId !== 0) {
179 $update_str = implode(
'#', [
180 (
string) $this->lastHandledForumId,
181 (
string) $this->lastHandledThreadId,
182 (
string) $this->lastHandledPostId
186 $this->db->manipulateF(
188 SET top_last_post = %s, 190 top_num_threads = %s, 192 WHERE top_frm_fk = %s",
193 [
'text',
'integer',
'integer',
'integer',
'integer'],
194 [$update_str, $num_posts, $num_threads, $this->frm_last_mapped_top_usr_id, $this->forum_obj_id]
228 case 'ThreadRatings':
232 case 'PostingActivation':
236 case 'PresetSubject':
244 case 'NotificationType':
248 case 'NotificationEvents':
252 case 'ForceNotification':
256 case 'ToggleNotification':
287 case 'isAuthorModerator':
293 if ($this->entity ===
'forum' && $this->forumArray !== []) {
297 $this->forum->createSettings();
300 (
int) ($this->forumArray[
'UserId'] ?? 0),
303 $this->frm_last_mapped_top_usr_id = $forum_array[
'usr_id'];
306 (
int) ($this->forumArray[
'UpdateUserId'] ?? 0),
314 $this->forum->setDescription(
ilUtil::stripSlashes((
string) ($this->forumArray[
"Description"] ??
'')));
315 $this->forum->update();
316 $this->forum->updateModificationUserId($update_forum_array[
'usr_id']);
320 $newObjProp->setAnonymisation((
bool) ($this->forumArray[
'Pseudonyms'] ??
false));
321 $newObjProp->setStatisticsStatus((
bool) ($this->forumArray[
'Statistics'] ??
false));
322 $newObjProp->setIsThreadRatingEnabled((
bool) ($this->forumArray[
'ThreadRatings'] ??
false));
323 $newObjProp->setPostActivation((
bool) ($this->forumArray[
'PostingActivation'] ??
false));
324 $newObjProp->setPresetSubject((
bool) ($this->forumArray[
'PresetSubject'] ??
false));
325 $newObjProp->setAddReSubject((
bool) ($this->forumArray[
'PresetRe'] ??
false));
326 $newObjProp->setNotificationType(
327 NotificationType::tryFrom(
328 $this->forumArray[
'NotificationType'] ?? NotificationType::ALL_USERS->value
329 ) ?? NotificationType::ALL_USERS
331 $newObjProp->setInterestedEvents((
int) ($this->forumArray[
'NotificationEvents'] ?? 0));
332 $newObjProp->setAdminForceNoti((
bool) ($this->forumArray[
'ForceNotification'] ??
false));
333 $newObjProp->setUserToggleNoti((
bool) ($this->forumArray[
'ToggleNotification'] ??
false));
334 $newObjProp->setFileUploadAllowed((
bool) ($this->forumArray[
'FileUpload'] ??
false));
335 $newObjProp->setMarkModeratorPosts((
bool) ($this->forumArray[
'MarkModeratorPosts'] ??
false));
336 $newObjProp->update();
339 $this->forum_obj_id = $newObjProp->getObjId();
340 $this->mapping[
'frm'][$this->forumArray[
'Id']] =
$id;
341 $this->lastHandledForumId =
$id;
343 $this->importMapping->addMapping(
346 'frm:' . $this->forumArray[
'ObjId'],
347 'frm:' . $this->forum->getId()
350 if ($this->last_handled_style_id) {
352 $this->last_handled_style_id = null;
355 $this->forumArray = [];
361 if ($this->lastHandledPostId !== 0) {
362 $update_str = implode(
'#', [
363 (
string) $this->lastHandledForumId,
364 (
string) $this->lastHandledThreadId,
365 (
string) $this->lastHandledPostId
369 $this->db->manipulateF(
370 "UPDATE frm_threads SET thr_last_post = %s WHERE thr_pk = %s",
372 [$update_str, $this->lastHandledThreadId]
388 case 'MarkModeratorPosts':
395 if ($this->entity ===
'thread' && $this->lastHandledForumId && $this->threadArray !== []) {
397 $this->forumThread->setId((
int) ($this->threadArray[
'Id'] ?? 0));
398 $this->forumThread->setForumId($this->lastHandledForumId);
399 $this->forumThread->setSubject(
ilUtil::stripSlashes((
string) ($this->threadArray[
'Subject'] ??
'')));
400 $this->forumThread->setSticky((
bool) ($this->threadArray[
'Sticky'] ??
false));
401 $this->forumThread->setClosed((
bool) ($this->threadArray[
'Closed'] ??
false));
403 $this->forumThread->setImportName(
404 isset($this->threadArray[
'ImportName']) ?
408 $this->forumThread->setCreateDate($this->threadArray[
'CreateDate']);
409 $this->forumThread->setChangeDate($this->threadArray[
'UpdateDate']);
412 (
int) ($this->threadArray[
'UserId'] ?? 0),
416 $this->forumThread->setDisplayUserId($usr_data[
'usr_id']);
417 $this->forumThread->setUserAlias($usr_data[
'usr_alias']);
420 $this->threadArray[
'AuthorId'] = $this->threadArray[
'UserId'];
424 (
int) ($this->threadArray[
'AuthorId'] ?? 0)
426 $this->forumThread->setThrAuthorId($author_id_data[
'usr_id']);
428 $this->forumThread->insert();
430 $this->mapping[
'thr'][$this->threadArray[
'Id']] = $this->forumThread->getId();
431 $this->lastHandledThreadId = $this->forumThread->getId();
432 $this->threadArray = [];
443 case 'CensorshipMessage':
479 $this->entity ===
'post' &&
480 $this->lastHandledForumId &&
481 $this->postArray !== [] &&
482 $this->forumThread &&
483 $this->lastHandledThreadId
486 $this->forumPost->setThread($this->forumThread);
488 $this->forumPost->setId((
int) $this->postArray[
'Id']);
489 $this->forumPost->setCensorship((
bool) ($this->postArray[
'Censorship'] ??
false));
490 $this->forumPost->setCensorshipComment(
493 $this->forumPost->setNotification((
bool) ($this->postArray[
'Notification'] ??
false));
494 $this->forumPost->setStatus((
bool) ($this->postArray[
'Status'] ??
false));
496 $this->forumPost->setMessage($purifier->purify((
string) ($this->postArray[
'Message'] ??
'')));
497 $this->forumPost->setSubject(
ilUtil::stripSlashes((
string) ($this->postArray[
'Subject'] ??
'')));
498 $this->forumPost->setLft((
int) $this->postArray[
'Lft']);
499 $this->forumPost->setRgt((
int) $this->postArray[
'Rgt']);
500 $this->forumPost->setDepth((
int) $this->postArray[
'Depth']);
501 $this->forumPost->setParentId((
int) $this->postArray[
'ParentId']);
502 $this->forumPost->setThreadId($this->lastHandledThreadId);
503 $this->forumPost->setForumId($this->lastHandledForumId);
505 $this->forumPost->setImportName(
506 isset($this->postArray[
'ImportName']) ?
510 $this->forumPost->setCreateDate($this->postArray[
'CreateDate']);
511 $this->forumPost->setChangeDate($this->postArray[
'UpdateDate']);
514 (
int) ($this->postArray[
'UserId'] ?? 0),
518 (
int) ($this->postArray[
'UpdateUserId'] ?? 0)
520 $this->forumPost->setDisplayUserId($usr_data[
'usr_id']);
521 $this->forumPost->setUserAlias($usr_data[
'usr_alias']);
522 $this->forumPost->setUpdateUserId($update_usr_data[
'usr_id']);
525 $this->postArray[
'AuthorId'] = $this->postArray[
'UserId'];
528 (
int) ($this->postArray[
'AuthorId'] ?? 0)
530 $this->forumPost->setPosAuthorId((
int) $author_id_data[
'usr_id']);
532 if (isset($this->postArray[
'isAuthorModerator']) && strtoupper($this->postArray[
'isAuthorModerator']) ===
'NULL') {
533 $this->forumPost->setIsAuthorModerator(
false);
535 $this->forumPost->setIsAuthorModerator((
bool) $this->postArray[
'isAuthorModerator']);
538 $this->forumPost->insert();
540 if (isset($this->postArray[
'ParentId'], $this->mapping[
'pos'][$this->postArray[
'ParentId']])) {
541 $parentId = (
int) $this->mapping[
'pos'][$this->postArray[
'ParentId']];
546 $postTreeNodeId = $this->db->nextId(
'frm_posts_tree');
547 $this->db->insert(
'frm_posts_tree', [
548 'fpt_pk' => [
'integer', $postTreeNodeId],
549 'thr_fk' => [
'integer', $this->lastHandledThreadId],
550 'pos_fk' => [
'integer', $this->forumPost->getId()],
551 'parent_pos' => [
'integer', $parentId],
552 'lft' => [
'integer', $this->postArray[
'Lft']],
553 'rgt' => [
'integer', $this->postArray[
'Rgt']],
554 'depth' => [
'integer', $this->postArray[
'Depth']],
555 'fpt_date' => [
'timestamp', date(
'Y-m-d H:i:s')]
558 $this->mapping[
'pos'][($this->postArray[
'Id'] ?? 0)] = $this->forumPost->getId();
559 $this->lastHandledPostId = $this->forumPost->getId();
561 $media_objects_found =
false;
562 foreach ($this->mediaObjects as $mob_attr) {
564 if (is_file($importfile)) {
566 basename($importfile),
572 $this->forumPost->setMessage(
575 "src=\"" . $mob_attr[
"label"] .
"\"",
576 "src=\"" . preg_replace(
577 "/(il)_[\d]+_(mob)_([\d]+)/",
582 "src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $mob->getId() .
"\"",
583 $this->forumPost->getMessage()
586 $media_objects_found =
true;
590 if ($media_objects_found) {
591 $this->forumPost->update();
593 $this->postArray = [];
605 $import_path = $this->contentArray[
'content'];
606 if ($import_path !==
'') {
608 $filedata->
importPath($import_path, (
int) $this->lastHandledPostId);
622 $select =
'SELECT od.obj_id, ud.login FROM object_data od INNER JOIN usr_data ud ON od.obj_id = ud.usr_id';
623 if (
$param ===
'import') {
624 $where =
' WHERE od.import_id = ' . $this->db->quote(
625 'il_' . $this->import_install_id .
'_usr_' . $imp_usr_id,
631 $where =
' WHERE ud.usr_id = ' . $this->db->quote(
637 $query = $this->db->query($select . $where);
639 while (
$res = $this->db->fetchAssoc($query)) {
645 'usr_id' => (
int)
$res[
'obj_id'],
646 'usr_alias' => (
string)
$res[
'login']
659 'usr_id' => $this->aobject->getId(),
660 'usr_alias' => $this->aobject->getLogin()
669 if ($imp_usr_id <= 0) {
671 'usr_id' => $imp_usr_id,
672 'usr_alias' => $imp_usr_alias
678 if (isset($this->user_id_mapping[$imp_usr_id])) {
679 return $this->user_id_mapping[$imp_usr_id];
684 $this->user_id_mapping[$imp_usr_id] =
$res;
690 $this->user_id_mapping[$imp_usr_id] = $return_value;
692 return $return_value;
697 if (isset($this->user_id_mapping[$imp_usr_id])) {
698 return $this->user_id_mapping[$imp_usr_id];
703 $this->user_id_mapping[$imp_usr_id] =
$res;
708 if (isset($this->user_id_mapping[$imp_usr_id])) {
709 return $this->user_id_mapping[$imp_usr_id];
714 $this->user_id_mapping[$imp_usr_id] =
$res;
720 $this->user_id_mapping[$imp_usr_id] = $return_value;
722 return $return_value;
725 if (isset($this->user_id_mapping[$imp_usr_id])) {
726 return $this->user_id_mapping[$imp_usr_id];
731 $this->user_id_mapping[$imp_usr_id] =
$res;
737 $this->user_id_mapping[$imp_usr_id] = $return_value;
739 return $return_value;
744 $this->import_install_id =
$id;
749 $query =
"SELECT top_pk FROM frm_data WHERE top_frm_fk = " . $this->db->quote(
750 $this->forum->getId(),
753 $res = $this->db->query($query);
756 return (
int)
$data[
'top_pk'];
761 if ($a_data !==
"\n") {
763 $a_data = preg_replace(
"/\t+/",
" ", $a_data);
765 $this->cdata .= $a_data;
__construct(private ilObjForum $forum, string $a_xml_data, private ilImportMapping $importMapping)
ILIAS Style Content DomainService $content_style_domain
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
setSchemaVersion(?string $schema_version)
int $frm_last_mapped_top_usr_id
getUserIdAndAlias(int $imp_usr_id, string $imp_usr_alias='')
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getIdAndAliasArray(int $imp_usr_id, string $param='import')
static getInstance(int $a_obj_id=0)
int $last_handled_style_id
setHandlers($a_xml_parser)
importPath(string $path_to_file, int $posting_id)
static _refreshStatus(int $a_obj_id, ?array $a_users=null)
handlerEndTag(XMLParser $a_xml_parser, string $a_name)
static getInstanceByType(string $type)
handlerBeginTag(XMLParser $a_xml_parser, string $a_name, array $a_attribs)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
ilForumTopic $forumThread
setXMLContent(string $a_xml_content)
setImportDirectory(?string $a_val)
handlerCharacterData(XMLParser $a_xml_parser, string $a_data)