19declare(strict_types=1);
75 $this->db =
$DIC->database();
80 $this->content_style_domain =
$DIC
84 $this->
setXMLContent(
'<?xml version="1.0" encoding="utf-8"?>' . $a_xml_data);
89 $this->importDirectory = $a_val;
109 xml_set_element_handler(
111 function (XMLParser $a_xml_parser,
string $a_name, array $a_attribs):
void {
114 function (XMLParser $a_xml_parser,
string $a_name):
void {
118 xml_set_character_data_handler($a_xml_parser,
function (XMLParser $a_xml_parser,
string $a_data):
void {
123 public function handlerBeginTag(XMLParser $a_xml_parser,
string $a_name, array $a_attribs): void
127 $this->entity =
'forum';
128 $this->forumArray = [];
132 $this->entity =
'thread';
133 $this->post_tree_structure = [];
134 $this->threadArray = [];
138 $this->entity =
'post';
139 $this->postArray = [];
140 $this->mediaObjects = [];
144 $this->entity =
'content';
145 $this->contentArray = [
151 $this->mediaObjects[] = $a_attribs;
155 if (isset($a_attribs[
'Style'])) {
156 $this->last_handled_style_id = (
int) $a_attribs[
'Style'];
160 public function handlerEndTag(XMLParser $a_xml_parser,
string $a_name): void
162 $this->cdata = trim($this->cdata);
163 $property = strtolower($this->entity) .
'Array';
165 if (!property_exists($this, $property)) {
169 $propertyValue = &$this->{$property};
173 $query_num_posts =
'SELECT COUNT(pos_pk) cnt FROM frm_posts WHERE pos_top_fk = ' . $this->db->quote(
174 $this->lastHandledForumId,
177 $res_pos = $this->db->query($query_num_posts);
178 $data_pos = $this->db->fetchAssoc($res_pos);
179 $num_posts = (
int) $data_pos[
'cnt'];
181 $query_num_threads =
'SELECT COUNT(thr_pk) cnt FROM frm_threads WHERE thr_top_fk = ' . $this->db->quote(
182 $this->lastHandledForumId,
185 $res_thr = $this->db->query($query_num_threads);
186 $data_thr = $this->db->fetchAssoc($res_thr);
187 $num_threads = (
int) $data_thr[
'cnt'];
190 if ($this->lastHandledPostId !== 0) {
191 $update_str = implode(
'#', [
192 (
string) $this->lastHandledForumId,
193 (
string) $this->lastHandledThreadId,
194 (
string) $this->lastHandledPostId
198 $this->db->manipulateF(
200 SET top_last_post = %s,
202 top_num_threads = %s,
204 WHERE top_frm_fk = %s',
205 [
'text',
'integer',
'integer',
'integer',
'integer'],
206 [$update_str, $num_posts, $num_threads, $this->frm_last_mapped_top_usr_id, $this->forum_obj_id]
240 case 'ThreadRatings':
244 case 'PostingActivation':
248 case 'PresetSubject':
256 case 'NotificationType':
260 case 'NotificationEvents':
264 case 'ForceNotification':
268 case 'ToggleNotification':
299 case 'isAuthorModerator':
305 if ($this->entity ===
'forum' && $this->forumArray !== []) {
309 $this->forum->createSettings();
312 (
int) ($this->forumArray[
'UserId'] ?? 0),
315 $this->frm_last_mapped_top_usr_id = $forum_array[
'usr_id'];
318 (
int) ($this->forumArray[
'UpdateUserId'] ?? 0),
326 $this->forum->setDescription(
329 $this->forum->update();
330 $this->forum->updateModificationUserId($update_forum_array[
'usr_id']);
333 $newObjProp->setDefaultView(
336 $newObjProp->setAnonymisation((
bool) ($this->forumArray[
'Pseudonyms'] ??
false));
337 $newObjProp->setStatisticsStatus((
bool) ($this->forumArray[
'Statistics'] ??
false));
338 $newObjProp->setIsThreadRatingEnabled((
bool) ($this->forumArray[
'ThreadRatings'] ??
false));
339 $newObjProp->setPostActivation((
bool) ($this->forumArray[
'PostingActivation'] ??
false));
340 $newObjProp->setPresetSubject((
bool) ($this->forumArray[
'PresetSubject'] ??
false));
341 $newObjProp->setAddReSubject((
bool) ($this->forumArray[
'PresetRe'] ??
false));
342 $newObjProp->setNotificationType(
343 NotificationType::tryFrom(
344 $this->forumArray[
'NotificationType'] ?? NotificationType::ALL_USERS->value
345 ) ?? NotificationType::ALL_USERS
347 $newObjProp->setInterestedEvents((
int) ($this->forumArray[
'NotificationEvents'] ?? 0));
348 $newObjProp->setAdminForceNoti((
bool) ($this->forumArray[
'ForceNotification'] ??
false));
349 $newObjProp->setUserToggleNoti((
bool) ($this->forumArray[
'ToggleNotification'] ??
false));
350 $newObjProp->setFileUploadAllowed((
bool) ($this->forumArray[
'FileUpload'] ??
false));
351 $newObjProp->setMarkModeratorPosts((
bool) ($this->forumArray[
'MarkModeratorPosts'] ??
false));
352 $newObjProp->update();
355 $this->forum_obj_id = $newObjProp->getObjId();
356 $this->mapping[
'frm'][$this->forumArray[
'Id']] =
$id;
357 $this->lastHandledForumId =
$id;
359 $this->importMapping->addMapping(
360 'components/ILIAS/COPage',
362 'frm:' . $this->forumArray[
'ObjId'],
363 'frm:' . $this->forum->getId()
366 if ($this->last_handled_style_id) {
368 $this->last_handled_style_id =
null;
371 $this->forumArray = [];
377 if ($this->lastHandledPostId !== 0) {
378 $update_str = implode(
'#', [
379 (
string) $this->lastHandledForumId,
380 (
string) $this->lastHandledThreadId,
381 (
string) $this->lastHandledPostId
385 $this->db->manipulateF(
386 'UPDATE frm_threads SET thr_last_post = %s WHERE thr_pk = %s',
388 [$update_str, $this->lastHandledThreadId]
404 case 'MarkModeratorPosts':
411 if ($this->entity ===
'thread' && $this->lastHandledForumId && $this->threadArray !== []) {
413 $this->forumThread->setId((
int) $this->threadArray[
'Id']);
414 $this->forumThread->setForumId($this->lastHandledForumId);
415 $this->forumThread->setSubject(
418 $this->forumThread->setSticky((
bool) ($this->threadArray[
'Sticky'] ??
false));
419 $this->forumThread->setClosed((
bool) ($this->threadArray[
'Closed'] ??
false));
421 $this->forumThread->setImportName(
422 isset($this->threadArray[
'ImportName']) ?
426 $this->forumThread->setCreateDate($this->threadArray[
'CreateDate']);
427 $this->forumThread->setChangeDate($this->threadArray[
'UpdateDate']);
430 (
int) ($this->threadArray[
'UserId'] ?? 0),
434 $this->forumThread->setDisplayUserId($usr_data[
'usr_id']);
435 $this->forumThread->setUserAlias($usr_data[
'usr_alias']);
438 $this->threadArray[
'AuthorId'] = $this->threadArray[
'UserId'];
442 (
int) ($this->threadArray[
'AuthorId'] ?? 0)
444 $this->forumThread->setThrAuthorId($author_id_data[
'usr_id']);
446 $this->forumThread->insert();
448 $this->mapping[
'thr'][$this->threadArray[
'Id']] = $this->forumThread->getId();
449 $this->lastHandledThreadId = $this->forumThread->getId();
450 $this->threadArray = [];
461 case 'CensorshipMessage':
497 $this->entity ===
'post' &&
498 $this->lastHandledForumId &&
499 $this->postArray !== [] &&
500 $this->forumThread &&
501 $this->lastHandledThreadId
504 $this->forumPost->setThread($this->forumThread);
506 $this->forumPost->setId((
int) $this->postArray[
'Id']);
507 $this->forumPost->setCensorship((
bool) ($this->postArray[
'Censorship'] ??
false));
508 $this->forumPost->setCensorshipComment(
511 $this->forumPost->setNotification((
bool) ($this->postArray[
'Notification'] ??
false));
512 $this->forumPost->setStatus((
bool) ($this->postArray[
'Status'] ??
false));
514 $this->forumPost->setMessage($purifier->purify((
string) ($this->postArray[
'Message'] ??
'')));
515 $this->forumPost->setSubject(
ilUtil::stripSlashes((
string) ($this->postArray[
'Subject'] ??
'')));
516 $this->forumPost->setLft((
int) $this->postArray[
'Lft']);
517 $this->forumPost->setRgt((
int) $this->postArray[
'Rgt']);
518 $this->forumPost->setDepth((
int) $this->postArray[
'Depth']);
519 $this->forumPost->setParentId((
int) $this->postArray[
'ParentId']);
520 $this->forumPost->setThreadId($this->lastHandledThreadId);
521 $this->forumPost->setForumId($this->lastHandledForumId);
523 $this->forumPost->setImportName(
524 isset($this->postArray[
'ImportName']) ?
528 $this->forumPost->setCreateDate($this->postArray[
'CreateDate']);
529 $this->forumPost->setChangeDate($this->postArray[
'UpdateDate']);
532 (
int) ($this->postArray[
'UserId'] ?? 0),
536 (
int) ($this->postArray[
'UpdateUserId'] ?? 0)
538 $this->forumPost->setDisplayUserId($usr_data[
'usr_id']);
539 $this->forumPost->setUserAlias($usr_data[
'usr_alias']);
540 $this->forumPost->setUpdateUserId($update_usr_data[
'usr_id']);
543 $this->postArray[
'AuthorId'] = $this->postArray[
'UserId'];
546 (
int) ($this->postArray[
'AuthorId'] ?? 0)
548 $this->forumPost->setPosAuthorId((
int) $author_id_data[
'usr_id']);
550 if (isset($this->postArray[
'isAuthorModerator']) && strtoupper($this->postArray[
'isAuthorModerator']) ===
'NULL') {
551 $this->forumPost->setIsAuthorModerator(
false);
553 $this->forumPost->setIsAuthorModerator((
bool) $this->postArray[
'isAuthorModerator']);
556 $this->forumPost->insert();
558 if (isset($this->postArray[
'ParentId'], $this->mapping[
'pos'][$this->postArray[
'ParentId']])) {
559 $parent_id = (
int) $this->mapping[
'pos'][$this->postArray[
'ParentId']];
564 if ($parent_id === 0 && (
int) $this->postArray[
'Lft'] > 1) {
566 (
int) $this->postArray[
'Lft'],
567 (
int) $this->postArray[
'Rgt']
571 $postTreeNodeId = $this->db->nextId(
'frm_posts_tree');
572 $this->db->insert(
'frm_posts_tree', [
573 'fpt_pk' => [
'integer', $postTreeNodeId],
574 'thr_fk' => [
'integer', $this->lastHandledThreadId],
575 'pos_fk' => [
'integer', $this->forumPost->getId()],
576 'parent_pos' => [
'integer', $parent_id],
577 'lft' => [
'integer', $this->postArray[
'Lft']],
578 'rgt' => [
'integer', $this->postArray[
'Rgt']],
579 'depth' => [
'integer', $this->postArray[
'Depth']],
580 'fpt_date' => [
'timestamp', date(
'Y-m-d H:i:s')]
583 $this->mapping[
'pos'][$this->postArray[
'Id']] = $this->forumPost->getId();
584 $this->post_tree_structure[] = [
585 'id' => (
int) $this->postArray[
'Id'],
586 'lft' => (
int) $this->postArray[
'Lft'],
587 'rgt' => (
int) $this->postArray[
'Rgt'],
588 'new_id' => $this->forumPost->getId()
590 $this->lastHandledPostId = $this->forumPost->getId();
592 $media_objects_found =
false;
593 foreach ($this->mediaObjects as $mob_attr) {
595 if (is_file($importfile)) {
597 basename($importfile),
603 $this->forumPost->setMessage(
606 'src="' . $mob_attr[
'label'] .
'"',
607 'src="' . preg_replace(
608 "/(il)_[\d]+_(mob)_([\d]+)/",
613 'src="' .
'il_' .
IL_INST_ID .
'_mob_' . $mob->getId() .
'"',
614 $this->forumPost->getMessage()
617 $media_objects_found =
true;
621 if ($media_objects_found) {
622 $this->forumPost->update();
624 $this->postArray = [];
634 $filedata =
new ilFileDataForum($this->forum->getId(), $this->lastHandledPostId);
636 $import_path = $this->contentArray[
'content'];
637 if ($import_path !==
'') {
639 $filedata->importPath($import_path, (
int) $this->lastHandledPostId);
653 $select =
'SELECT od.obj_id, ud.login FROM object_data od INNER JOIN usr_data ud ON od.obj_id = ud.usr_id';
654 if (
$param ===
'import') {
655 $where =
' WHERE od.import_id = ' . $this->db->quote(
656 'il_' . $this->import_install_id .
'_usr_' . $imp_usr_id,
662 $where =
' WHERE ud.usr_id = ' . $this->db->quote(
668 $query = $this->db->query($select . $where);
670 while (
$res = $this->db->fetchAssoc($query)) {
676 'usr_id' => (
int)
$res[
'obj_id'],
677 'usr_alias' => (
string)
$res[
'login']
690 'usr_id' => $this->aobject->getId(),
691 'usr_alias' => $this->aobject->getLogin()
700 if ($imp_usr_id <= 0) {
702 'usr_id' => $imp_usr_id,
703 'usr_alias' => $imp_usr_alias
709 if (isset($this->user_id_mapping[$imp_usr_id])) {
710 return $this->user_id_mapping[$imp_usr_id];
715 $this->user_id_mapping[$imp_usr_id] =
$res;
721 $this->user_id_mapping[$imp_usr_id] = $return_value;
723 return $return_value;
728 if (isset($this->user_id_mapping[$imp_usr_id])) {
729 return $this->user_id_mapping[$imp_usr_id];
734 $this->user_id_mapping[$imp_usr_id] =
$res;
739 if (isset($this->user_id_mapping[$imp_usr_id])) {
740 return $this->user_id_mapping[$imp_usr_id];
745 $this->user_id_mapping[$imp_usr_id] =
$res;
751 $this->user_id_mapping[$imp_usr_id] = $return_value;
753 return $return_value;
756 if (isset($this->user_id_mapping[$imp_usr_id])) {
757 return $this->user_id_mapping[$imp_usr_id];
762 $this->user_id_mapping[$imp_usr_id] =
$res;
768 $this->user_id_mapping[$imp_usr_id] = $return_value;
770 return $return_value;
775 $this->import_install_id =
$id;
780 $query =
'SELECT top_pk FROM frm_data WHERE top_frm_fk = ' . $this->db->quote(
781 $this->forum->getId(),
784 $res = $this->db->query($query);
787 return (
int)
$data[
'top_pk'];
792 if ($a_data !==
"\n") {
794 $a_data = preg_replace(
"/\t+/",
' ', $a_data);
796 $this->cdata .= $a_data;
807 $closest_span = PHP_INT_MAX;
809 foreach ($this->post_tree_structure as $node) {
810 if ($node[
'lft'] < $lft && $node[
'rgt'] > $rgt) {
812 $span = $node[
'rgt'] - $node[
'lft'];
813 if ($span < $closest_span) {
814 $closest_span = $span;
815 $parent_id = (
int) $node[
'new_id'];
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static getInstance(int $a_obj_id=0)
ILIAS Style Content DomainService $content_style_domain
int $frm_last_mapped_top_usr_id
__construct(private readonly ilObjForum $forum, string $a_xml_data, private readonly ilImportMapping $importMapping)
setSchemaVersion(?string $schema_version)
int $last_handled_style_id
array $post_tree_structure
setHandlers($a_xml_parser)
determineParentFromNestedSet(int $lft, int $rgt)
Find the closest parent using Nested Set values in memory.
handlerCharacterData(XMLParser $a_xml_parser, string $a_data)
handlerBeginTag(XMLParser $a_xml_parser, string $a_name, array $a_attribs)
handlerEndTag(XMLParser $a_xml_parser, string $a_name)
setImportDirectory(?string $a_val)
readonly ilObjUser $aobject
getUserIdAndAlias(int $imp_usr_id, string $imp_usr_alias='')
getIdAndAliasArray(int $imp_usr_id, string $param='import')
ilForumTopic $forumThread
readonly ilDBInterface $db
static getInstanceByType(string $type)
static _refreshStatus(int $a_obj_id, ?array $a_users=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setXMLContent(string $a_xml_content)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc