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_object($a_xml_parser, $this);
105 xml_set_element_handler(
107 function (XMLParser $a_xml_parser,
string $a_name, array $a_attribs):
void {
110 function (XMLParser $a_xml_parser,
string $a_name):
void {
114 xml_set_character_data_handler($a_xml_parser,
function (XMLParser $a_xml_parser,
string $a_data):
void {
119 public function handlerBeginTag(XMLParser $a_xml_parser,
string $a_name, array $a_attribs): void
123 $this->entity =
'forum';
124 $this->forumArray = [];
128 $this->entity =
'thread';
129 $this->threadArray = [];
133 $this->entity =
'post';
134 $this->postArray = [];
135 $this->mediaObjects = [];
139 $this->entity =
'content';
140 $this->contentArray = [
146 $this->mediaObjects[] = $a_attribs;
150 if (isset($a_attribs[
'Style'])) {
151 $this->last_handled_style_id = (
int) $a_attribs[
'Style'];
155 public function handlerEndTag(XMLParser $a_xml_parser,
string $a_name): void
157 $this->cdata = trim($this->cdata);
158 $property = strtolower($this->entity) .
'Array';
160 if (!property_exists($this, $property)) {
164 $propertyValue = &$this->{$property};
168 $query_num_posts =
'SELECT COUNT(pos_pk) cnt FROM frm_posts WHERE pos_top_fk = ' . $this->db->quote(
169 $this->lastHandledForumId,
172 $res_pos = $this->db->query($query_num_posts);
173 $data_pos = $this->db->fetchAssoc($res_pos);
174 $num_posts = (
int) $data_pos[
'cnt'];
176 $query_num_threads =
'SELECT COUNT(thr_pk) cnt FROM frm_threads WHERE thr_top_fk = ' . $this->db->quote(
177 $this->lastHandledForumId,
180 $res_thr = $this->db->query($query_num_threads);
181 $data_thr = $this->db->fetchAssoc($res_thr);
182 $num_threads = (
int) $data_thr[
'cnt'];
185 if ($this->lastHandledPostId !== 0) {
186 $update_str = implode(
'#', [
187 (
string) $this->lastHandledForumId,
188 (
string) $this->lastHandledThreadId,
189 (
string) $this->lastHandledPostId
193 $this->db->manipulateF(
195 SET top_last_post = %s, 197 top_num_threads = %s, 199 WHERE top_frm_fk = %s',
200 [
'text',
'integer',
'integer',
'integer',
'integer'],
201 [$update_str, $num_posts, $num_threads, $this->frm_last_mapped_top_usr_id, $this->forum_obj_id]
235 case 'ThreadRatings':
239 case 'PostingActivation':
243 case 'PresetSubject':
251 case 'NotificationType':
255 case 'NotificationEvents':
259 case 'ForceNotification':
263 case 'ToggleNotification':
294 case 'isAuthorModerator':
300 if ($this->entity ===
'forum' && $this->forumArray !== []) {
304 $this->forum->createSettings();
307 (
int) ($this->forumArray[
'UserId'] ?? 0),
310 $this->frm_last_mapped_top_usr_id = $forum_array[
'usr_id'];
313 (
int) ($this->forumArray[
'UpdateUserId'] ?? 0),
321 $this->forum->setDescription(
324 $this->forum->update();
325 $this->forum->updateModificationUserId($update_forum_array[
'usr_id']);
328 $newObjProp->setDefaultView(
331 $newObjProp->setAnonymisation((
bool) ($this->forumArray[
'Pseudonyms'] ??
false));
332 $newObjProp->setStatisticsStatus((
bool) ($this->forumArray[
'Statistics'] ??
false));
333 $newObjProp->setIsThreadRatingEnabled((
bool) ($this->forumArray[
'ThreadRatings'] ??
false));
334 $newObjProp->setPostActivation((
bool) ($this->forumArray[
'PostingActivation'] ??
false));
335 $newObjProp->setPresetSubject((
bool) ($this->forumArray[
'PresetSubject'] ??
false));
336 $newObjProp->setAddReSubject((
bool) ($this->forumArray[
'PresetRe'] ??
false));
337 $newObjProp->setNotificationType(
338 NotificationType::tryFrom(
339 $this->forumArray[
'NotificationType'] ?? NotificationType::ALL_USERS->value
340 ) ?? NotificationType::ALL_USERS
342 $newObjProp->setInterestedEvents((
int) ($this->forumArray[
'NotificationEvents'] ?? 0));
343 $newObjProp->setAdminForceNoti((
bool) ($this->forumArray[
'ForceNotification'] ??
false));
344 $newObjProp->setUserToggleNoti((
bool) ($this->forumArray[
'ToggleNotification'] ??
false));
345 $newObjProp->setFileUploadAllowed((
bool) ($this->forumArray[
'FileUpload'] ??
false));
346 $newObjProp->setMarkModeratorPosts((
bool) ($this->forumArray[
'MarkModeratorPosts'] ??
false));
347 $newObjProp->update();
350 $this->forum_obj_id = $newObjProp->getObjId();
351 $this->mapping[
'frm'][$this->forumArray[
'Id']] =
$id;
352 $this->lastHandledForumId =
$id;
354 $this->importMapping->addMapping(
355 'components/ILIAS/COPage',
357 'frm:' . $this->forumArray[
'ObjId'],
358 'frm:' . $this->forum->getId()
361 if ($this->last_handled_style_id) {
363 $this->last_handled_style_id = null;
366 $this->forumArray = [];
372 if ($this->lastHandledPostId !== 0) {
373 $update_str = implode(
'#', [
374 (
string) $this->lastHandledForumId,
375 (
string) $this->lastHandledThreadId,
376 (
string) $this->lastHandledPostId
380 $this->db->manipulateF(
381 'UPDATE frm_threads SET thr_last_post = %s WHERE thr_pk = %s',
383 [$update_str, $this->lastHandledThreadId]
399 case 'MarkModeratorPosts':
406 if ($this->entity ===
'thread' && $this->lastHandledForumId && $this->threadArray !== []) {
408 $this->forumThread->setId((
int) ($this->threadArray[
'Id'] ?? 0));
409 $this->forumThread->setForumId($this->lastHandledForumId);
410 $this->forumThread->setSubject(
413 $this->forumThread->setSticky((
bool) ($this->threadArray[
'Sticky'] ??
false));
414 $this->forumThread->setClosed((
bool) ($this->threadArray[
'Closed'] ??
false));
416 $this->forumThread->setImportName(
417 isset($this->threadArray[
'ImportName']) ?
421 $this->forumThread->setCreateDate($this->threadArray[
'CreateDate']);
422 $this->forumThread->setChangeDate($this->threadArray[
'UpdateDate']);
425 (
int) ($this->threadArray[
'UserId'] ?? 0),
429 $this->forumThread->setDisplayUserId($usr_data[
'usr_id']);
430 $this->forumThread->setUserAlias($usr_data[
'usr_alias']);
433 $this->threadArray[
'AuthorId'] = $this->threadArray[
'UserId'];
437 (
int) ($this->threadArray[
'AuthorId'] ?? 0)
439 $this->forumThread->setThrAuthorId($author_id_data[
'usr_id']);
441 $this->forumThread->insert();
443 $this->mapping[
'thr'][$this->threadArray[
'Id']] = $this->forumThread->getId();
444 $this->lastHandledThreadId = $this->forumThread->getId();
445 $this->threadArray = [];
456 case 'CensorshipMessage':
492 $this->entity ===
'post' &&
493 $this->lastHandledForumId &&
494 $this->postArray !== [] &&
495 $this->forumThread &&
496 $this->lastHandledThreadId
499 $this->forumPost->setThread($this->forumThread);
501 $this->forumPost->setId((
int) $this->postArray[
'Id']);
502 $this->forumPost->setCensorship((
bool) ($this->postArray[
'Censorship'] ??
false));
503 $this->forumPost->setCensorshipComment(
506 $this->forumPost->setNotification((
bool) ($this->postArray[
'Notification'] ??
false));
507 $this->forumPost->setStatus((
bool) ($this->postArray[
'Status'] ??
false));
509 $this->forumPost->setMessage($purifier->purify((
string) ($this->postArray[
'Message'] ??
'')));
510 $this->forumPost->setSubject(
ilUtil::stripSlashes((
string) ($this->postArray[
'Subject'] ??
'')));
511 $this->forumPost->setLft((
int) $this->postArray[
'Lft']);
512 $this->forumPost->setRgt((
int) $this->postArray[
'Rgt']);
513 $this->forumPost->setDepth((
int) $this->postArray[
'Depth']);
514 $this->forumPost->setParentId((
int) $this->postArray[
'ParentId']);
515 $this->forumPost->setThreadId($this->lastHandledThreadId);
516 $this->forumPost->setForumId($this->lastHandledForumId);
518 $this->forumPost->setImportName(
519 isset($this->postArray[
'ImportName']) ?
523 $this->forumPost->setCreateDate($this->postArray[
'CreateDate']);
524 $this->forumPost->setChangeDate($this->postArray[
'UpdateDate']);
527 (
int) ($this->postArray[
'UserId'] ?? 0),
531 (
int) ($this->postArray[
'UpdateUserId'] ?? 0)
533 $this->forumPost->setDisplayUserId($usr_data[
'usr_id']);
534 $this->forumPost->setUserAlias($usr_data[
'usr_alias']);
535 $this->forumPost->setUpdateUserId($update_usr_data[
'usr_id']);
538 $this->postArray[
'AuthorId'] = $this->postArray[
'UserId'];
541 (
int) ($this->postArray[
'AuthorId'] ?? 0)
543 $this->forumPost->setPosAuthorId((
int) $author_id_data[
'usr_id']);
545 if (isset($this->postArray[
'isAuthorModerator']) && strtoupper($this->postArray[
'isAuthorModerator']) ===
'NULL') {
546 $this->forumPost->setIsAuthorModerator(
false);
548 $this->forumPost->setIsAuthorModerator((
bool) $this->postArray[
'isAuthorModerator']);
551 $this->forumPost->insert();
553 if (isset($this->postArray[
'ParentId'], $this->mapping[
'pos'][$this->postArray[
'ParentId']])) {
554 $parentId = (
int) $this->mapping[
'pos'][$this->postArray[
'ParentId']];
559 $postTreeNodeId = $this->db->nextId(
'frm_posts_tree');
560 $this->db->insert(
'frm_posts_tree', [
561 'fpt_pk' => [
'integer', $postTreeNodeId],
562 'thr_fk' => [
'integer', $this->lastHandledThreadId],
563 'pos_fk' => [
'integer', $this->forumPost->getId()],
564 'parent_pos' => [
'integer', $parentId],
565 'lft' => [
'integer', $this->postArray[
'Lft']],
566 'rgt' => [
'integer', $this->postArray[
'Rgt']],
567 'depth' => [
'integer', $this->postArray[
'Depth']],
568 'fpt_date' => [
'timestamp', date(
'Y-m-d H:i:s')]
571 $this->mapping[
'pos'][($this->postArray[
'Id'] ?? 0)] = $this->forumPost->getId();
572 $this->lastHandledPostId = $this->forumPost->getId();
574 $media_objects_found =
false;
575 foreach ($this->mediaObjects as $mob_attr) {
577 if (is_file($importfile)) {
579 basename($importfile),
585 $this->forumPost->setMessage(
588 'src="' . $mob_attr[
'label'] .
'"',
589 'src="' . preg_replace(
590 "/(il)_[\d]+_(mob)_([\d]+)/",
595 'src="' .
'il_' .
IL_INST_ID .
'_mob_' . $mob->getId() .
'"',
596 $this->forumPost->getMessage()
599 $media_objects_found =
true;
603 if ($media_objects_found) {
604 $this->forumPost->update();
606 $this->postArray = [];
618 $import_path = $this->contentArray[
'content'];
619 if ($import_path !==
'') {
621 $filedata->
importPath($import_path, (
int) $this->lastHandledPostId);
635 $select =
'SELECT od.obj_id, ud.login FROM object_data od INNER JOIN usr_data ud ON od.obj_id = ud.usr_id';
636 if (
$param ===
'import') {
637 $where =
' WHERE od.import_id = ' . $this->db->quote(
638 'il_' . $this->import_install_id .
'_usr_' . $imp_usr_id,
644 $where =
' WHERE ud.usr_id = ' . $this->db->quote(
650 $query = $this->db->query($select . $where);
652 while (
$res = $this->db->fetchAssoc($query)) {
658 'usr_id' => (
int)
$res[
'obj_id'],
659 'usr_alias' => (
string)
$res[
'login']
672 'usr_id' => $this->aobject->getId(),
673 'usr_alias' => $this->aobject->getLogin()
682 if ($imp_usr_id <= 0) {
684 'usr_id' => $imp_usr_id,
685 'usr_alias' => $imp_usr_alias
691 if (isset($this->user_id_mapping[$imp_usr_id])) {
692 return $this->user_id_mapping[$imp_usr_id];
697 $this->user_id_mapping[$imp_usr_id] =
$res;
703 $this->user_id_mapping[$imp_usr_id] = $return_value;
705 return $return_value;
710 if (isset($this->user_id_mapping[$imp_usr_id])) {
711 return $this->user_id_mapping[$imp_usr_id];
716 $this->user_id_mapping[$imp_usr_id] =
$res;
721 if (isset($this->user_id_mapping[$imp_usr_id])) {
722 return $this->user_id_mapping[$imp_usr_id];
727 $this->user_id_mapping[$imp_usr_id] =
$res;
733 $this->user_id_mapping[$imp_usr_id] = $return_value;
735 return $return_value;
738 if (isset($this->user_id_mapping[$imp_usr_id])) {
739 return $this->user_id_mapping[$imp_usr_id];
744 $this->user_id_mapping[$imp_usr_id] =
$res;
750 $this->user_id_mapping[$imp_usr_id] = $return_value;
752 return $return_value;
757 $this->import_install_id =
$id;
762 $query =
'SELECT top_pk FROM frm_data WHERE top_frm_fk = ' . $this->db->quote(
763 $this->forum->getId(),
766 $res = $this->db->query($query);
769 return (
int)
$data[
'top_pk'];
774 if ($a_data !==
"\n") {
776 $a_data = preg_replace(
"/\t+/",
' ', $a_data);
778 $this->cdata .= $a_data;
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
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)
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)