19 declare(strict_types=1);
70 $this->db = $DIC->database();
75 $this->content_style_domain = $DIC
79 $this->
setXMLContent(
'<?xml version="1.0" encoding="utf-8"?>' . $a_xml_data);
84 $this->importDirectory = $a_val;
104 xml_set_element_handler(
106 function (XMLParser $a_xml_parser,
string $a_name, array $a_attribs):
void {
109 function (XMLParser $a_xml_parser,
string $a_name):
void {
113 xml_set_character_data_handler($a_xml_parser,
function (XMLParser $a_xml_parser,
string $a_data):
void {
118 public function handlerBeginTag(XMLParser $a_xml_parser,
string $a_name, array $a_attribs): void
122 $this->entity =
'forum';
123 $this->forumArray = [];
127 $this->entity =
'thread';
128 $this->threadArray = [];
132 $this->entity =
'post';
133 $this->postArray = [];
134 $this->mediaObjects = [];
138 $this->entity =
'content';
139 $this->contentArray = [
145 $this->mediaObjects[] = $a_attribs;
149 if (isset($a_attribs[
'Style'])) {
150 $this->last_handled_style_id = (
int) $a_attribs[
'Style'];
154 public function handlerEndTag(XMLParser $a_xml_parser,
string $a_name): void
156 $this->cdata = trim($this->cdata);
157 $property = strtolower($this->entity) .
'Array';
159 if (!property_exists($this, $property)) {
163 $propertyValue = &$this->{$property};
167 $query_num_posts =
'SELECT COUNT(pos_pk) cnt FROM frm_posts WHERE pos_top_fk = ' . $this->db->quote(
168 $this->lastHandledForumId,
171 $res_pos = $this->db->query($query_num_posts);
172 $data_pos = $this->db->fetchAssoc($res_pos);
173 $num_posts = (
int) $data_pos[
'cnt'];
175 $query_num_threads =
'SELECT COUNT(thr_pk) cnt FROM frm_threads WHERE thr_top_fk = ' . $this->db->quote(
176 $this->lastHandledForumId,
179 $res_thr = $this->db->query($query_num_threads);
180 $data_thr = $this->db->fetchAssoc($res_thr);
181 $num_threads = (
int) $data_thr[
'cnt'];
184 if ($this->lastHandledPostId !== 0) {
185 $update_str = implode(
'#', [
186 (
string) $this->lastHandledForumId,
187 (
string) $this->lastHandledThreadId,
188 (
string) $this->lastHandledPostId
192 $this->db->manipulateF(
194 SET top_last_post = %s, 196 top_num_threads = %s, 198 WHERE top_frm_fk = %s',
199 [
'text',
'integer',
'integer',
'integer',
'integer'],
200 [$update_str, $num_posts, $num_threads, $this->frm_last_mapped_top_usr_id, $this->forum_obj_id]
234 case 'ThreadRatings':
238 case 'PostingActivation':
242 case 'PresetSubject':
250 case 'NotificationType':
254 case 'NotificationEvents':
258 case 'ForceNotification':
262 case 'ToggleNotification':
293 case 'isAuthorModerator':
299 if ($this->entity ===
'forum' && $this->forumArray !== []) {
303 $this->forum->createSettings();
306 (
int) ($this->forumArray[
'UserId'] ?? 0),
309 $this->frm_last_mapped_top_usr_id = $forum_array[
'usr_id'];
312 (
int) ($this->forumArray[
'UpdateUserId'] ?? 0),
320 $this->forum->setDescription(
323 $this->forum->update();
324 $this->forum->updateModificationUserId($update_forum_array[
'usr_id']);
327 $newObjProp->setDefaultView(
330 $newObjProp->setAnonymisation((
bool) ($this->forumArray[
'Pseudonyms'] ??
false));
331 $newObjProp->setStatisticsStatus((
bool) ($this->forumArray[
'Statistics'] ??
false));
332 $newObjProp->setIsThreadRatingEnabled((
bool) ($this->forumArray[
'ThreadRatings'] ??
false));
333 $newObjProp->setPostActivation((
bool) ($this->forumArray[
'PostingActivation'] ??
false));
334 $newObjProp->setPresetSubject((
bool) ($this->forumArray[
'PresetSubject'] ??
false));
335 $newObjProp->setAddReSubject((
bool) ($this->forumArray[
'PresetRe'] ??
false));
336 $newObjProp->setNotificationType(
337 NotificationType::tryFrom(
338 $this->forumArray[
'NotificationType'] ?? NotificationType::ALL_USERS->value
339 ) ?? NotificationType::ALL_USERS
341 $newObjProp->setInterestedEvents((
int) ($this->forumArray[
'NotificationEvents'] ?? 0));
342 $newObjProp->setAdminForceNoti((
bool) ($this->forumArray[
'ForceNotification'] ??
false));
343 $newObjProp->setUserToggleNoti((
bool) ($this->forumArray[
'ToggleNotification'] ??
false));
344 $newObjProp->setFileUploadAllowed((
bool) ($this->forumArray[
'FileUpload'] ??
false));
345 $newObjProp->setMarkModeratorPosts((
bool) ($this->forumArray[
'MarkModeratorPosts'] ??
false));
346 $newObjProp->update();
349 $this->forum_obj_id = $newObjProp->getObjId();
350 $this->mapping[
'frm'][$this->forumArray[
'Id']] =
$id;
351 $this->lastHandledForumId =
$id;
353 $this->importMapping->addMapping(
354 'components/ILIAS/COPage',
356 'frm:' . $this->forumArray[
'ObjId'],
357 'frm:' . $this->forum->getId()
360 if ($this->last_handled_style_id) {
362 $this->last_handled_style_id =
null;
365 $this->forumArray = [];
371 if ($this->lastHandledPostId !== 0) {
372 $update_str = implode(
'#', [
373 (
string) $this->lastHandledForumId,
374 (
string) $this->lastHandledThreadId,
375 (
string) $this->lastHandledPostId
379 $this->db->manipulateF(
380 'UPDATE frm_threads SET thr_last_post = %s WHERE thr_pk = %s',
382 [$update_str, $this->lastHandledThreadId]
398 case 'MarkModeratorPosts':
405 if ($this->entity ===
'thread' && $this->lastHandledForumId && $this->threadArray !== []) {
407 $this->forumThread->setId((
int) ($this->threadArray[
'Id'] ?? 0));
408 $this->forumThread->setForumId($this->lastHandledForumId);
409 $this->forumThread->setSubject(
412 $this->forumThread->setSticky((
bool) ($this->threadArray[
'Sticky'] ??
false));
413 $this->forumThread->setClosed((
bool) ($this->threadArray[
'Closed'] ??
false));
415 $this->forumThread->setImportName(
416 isset($this->threadArray[
'ImportName']) ?
420 $this->forumThread->setCreateDate($this->threadArray[
'CreateDate']);
421 $this->forumThread->setChangeDate($this->threadArray[
'UpdateDate']);
424 (
int) ($this->threadArray[
'UserId'] ?? 0),
428 $this->forumThread->setDisplayUserId($usr_data[
'usr_id']);
429 $this->forumThread->setUserAlias($usr_data[
'usr_alias']);
432 $this->threadArray[
'AuthorId'] = $this->threadArray[
'UserId'];
436 (
int) ($this->threadArray[
'AuthorId'] ?? 0)
438 $this->forumThread->setThrAuthorId($author_id_data[
'usr_id']);
440 $this->forumThread->insert();
442 $this->mapping[
'thr'][$this->threadArray[
'Id']] = $this->forumThread->getId();
443 $this->lastHandledThreadId = $this->forumThread->getId();
444 $this->threadArray = [];
455 case 'CensorshipMessage':
491 $this->entity ===
'post' &&
492 $this->lastHandledForumId &&
493 $this->postArray !== [] &&
494 $this->forumThread &&
495 $this->lastHandledThreadId
498 $this->forumPost->setThread($this->forumThread);
500 $this->forumPost->setId((
int) $this->postArray[
'Id']);
501 $this->forumPost->setCensorship((
bool) ($this->postArray[
'Censorship'] ??
false));
502 $this->forumPost->setCensorshipComment(
505 $this->forumPost->setNotification((
bool) ($this->postArray[
'Notification'] ??
false));
506 $this->forumPost->setStatus((
bool) ($this->postArray[
'Status'] ??
false));
508 $this->forumPost->setMessage($purifier->purify((
string) ($this->postArray[
'Message'] ??
'')));
509 $this->forumPost->setSubject(
ilUtil::stripSlashes((
string) ($this->postArray[
'Subject'] ??
'')));
510 $this->forumPost->setLft((
int) $this->postArray[
'Lft']);
511 $this->forumPost->setRgt((
int) $this->postArray[
'Rgt']);
512 $this->forumPost->setDepth((
int) $this->postArray[
'Depth']);
513 $this->forumPost->setParentId((
int) $this->postArray[
'ParentId']);
514 $this->forumPost->setThreadId($this->lastHandledThreadId);
515 $this->forumPost->setForumId($this->lastHandledForumId);
517 $this->forumPost->setImportName(
518 isset($this->postArray[
'ImportName']) ?
522 $this->forumPost->setCreateDate($this->postArray[
'CreateDate']);
523 $this->forumPost->setChangeDate($this->postArray[
'UpdateDate']);
526 (
int) ($this->postArray[
'UserId'] ?? 0),
530 (
int) ($this->postArray[
'UpdateUserId'] ?? 0)
532 $this->forumPost->setDisplayUserId($usr_data[
'usr_id']);
533 $this->forumPost->setUserAlias($usr_data[
'usr_alias']);
534 $this->forumPost->setUpdateUserId($update_usr_data[
'usr_id']);
537 $this->postArray[
'AuthorId'] = $this->postArray[
'UserId'];
540 (
int) ($this->postArray[
'AuthorId'] ?? 0)
542 $this->forumPost->setPosAuthorId((
int) $author_id_data[
'usr_id']);
544 if (isset($this->postArray[
'isAuthorModerator']) && strtoupper($this->postArray[
'isAuthorModerator']) ===
'NULL') {
545 $this->forumPost->setIsAuthorModerator(
false);
547 $this->forumPost->setIsAuthorModerator((
bool) $this->postArray[
'isAuthorModerator']);
550 $this->forumPost->insert();
552 if (isset($this->postArray[
'ParentId'], $this->mapping[
'pos'][$this->postArray[
'ParentId']])) {
553 $parentId = (
int) $this->mapping[
'pos'][$this->postArray[
'ParentId']];
558 $postTreeNodeId = $this->db->nextId(
'frm_posts_tree');
559 $this->db->insert(
'frm_posts_tree', [
560 'fpt_pk' => [
'integer', $postTreeNodeId],
561 'thr_fk' => [
'integer', $this->lastHandledThreadId],
562 'pos_fk' => [
'integer', $this->forumPost->getId()],
563 'parent_pos' => [
'integer', $parentId],
564 'lft' => [
'integer', $this->postArray[
'Lft']],
565 'rgt' => [
'integer', $this->postArray[
'Rgt']],
566 'depth' => [
'integer', $this->postArray[
'Depth']],
567 'fpt_date' => [
'timestamp', date(
'Y-m-d H:i:s')]
570 $this->mapping[
'pos'][($this->postArray[
'Id'] ?? 0)] = $this->forumPost->getId();
571 $this->lastHandledPostId = $this->forumPost->getId();
573 $media_objects_found =
false;
574 foreach ($this->mediaObjects as $mob_attr) {
576 if (is_file($importfile)) {
578 basename($importfile),
584 $this->forumPost->setMessage(
587 'src="' . $mob_attr[
'label'] .
'"',
588 'src="' . preg_replace(
589 "/(il)_[\d]+_(mob)_([\d]+)/",
594 'src="' .
'il_' .
IL_INST_ID .
'_mob_' . $mob->getId() .
'"',
595 $this->forumPost->getMessage()
598 $media_objects_found =
true;
602 if ($media_objects_found) {
603 $this->forumPost->update();
605 $this->postArray = [];
617 $import_path = $this->contentArray[
'content'];
618 if ($import_path !==
'') {
620 $filedata->
importPath($import_path, (
int) $this->lastHandledPostId);
634 $select =
'SELECT od.obj_id, ud.login FROM object_data od INNER JOIN usr_data ud ON od.obj_id = ud.usr_id';
635 if (
$param ===
'import') {
636 $where =
' WHERE od.import_id = ' . $this->db->quote(
637 'il_' . $this->import_install_id .
'_usr_' . $imp_usr_id,
643 $where =
' WHERE ud.usr_id = ' . $this->db->quote(
649 $query = $this->db->query($select . $where);
651 while (
$res = $this->db->fetchAssoc($query)) {
657 'usr_id' => (
int)
$res[
'obj_id'],
658 'usr_alias' => (
string)
$res[
'login']
671 'usr_id' => $this->aobject->getId(),
672 'usr_alias' => $this->aobject->getLogin()
681 if ($imp_usr_id <= 0) {
683 'usr_id' => $imp_usr_id,
684 'usr_alias' => $imp_usr_alias
690 if (isset($this->user_id_mapping[$imp_usr_id])) {
691 return $this->user_id_mapping[$imp_usr_id];
696 $this->user_id_mapping[$imp_usr_id] =
$res;
702 $this->user_id_mapping[$imp_usr_id] = $return_value;
704 return $return_value;
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;
720 if (isset($this->user_id_mapping[$imp_usr_id])) {
721 return $this->user_id_mapping[$imp_usr_id];
726 $this->user_id_mapping[$imp_usr_id] =
$res;
732 $this->user_id_mapping[$imp_usr_id] = $return_value;
734 return $return_value;
737 if (isset($this->user_id_mapping[$imp_usr_id])) {
738 return $this->user_id_mapping[$imp_usr_id];
743 $this->user_id_mapping[$imp_usr_id] =
$res;
749 $this->user_id_mapping[$imp_usr_id] = $return_value;
751 return $return_value;
756 $this->import_install_id =
$id;
761 $query =
'SELECT top_pk FROM frm_data WHERE top_frm_fk = ' . $this->db->quote(
762 $this->forum->getId(),
765 $res = $this->db->query($query);
768 return (
int)
$data[
'top_pk'];
773 if ($a_data !==
"\n") {
775 $a_data = preg_replace(
"/\t+/",
' ', $a_data);
777 $this->cdata .= $a_data;
ILIAS Style Content DomainService $content_style_domain
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
setSchemaVersion(?string $schema_version)
int $frm_last_mapped_top_usr_id
array readonly ilDBInterface $db
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)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
readonly ilObjUser $aobject
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
__construct(Container $dic, ilPlugin $plugin)
__construct(private readonly ilObjForum $forum, string $a_xml_data, private readonly ilImportMapping $importMapping)
ilForumTopic $forumThread
setXMLContent(string $a_xml_content)
setImportDirectory(?string $a_val)
handlerCharacterData(XMLParser $a_xml_parser, string $a_data)