ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilWikiDataSet.php
Go to the documentation of this file.
1<?php
2
29{
30 protected \ILIAS\Wiki\InternalRepoService $wiki_repo;
31 protected \ILIAS\Wiki\Navigation\ImportantPageDBRepository $imp_page_repo;
32 protected ?ilObjWiki $current_obj = null;
34
35 public function __construct()
36 {
37 global $DIC;
38
39 $this->db = $DIC->database();
41 $this->wiki_log = ilLoggerFactory::getLogger('wiki');
42 $this->imp_page_repo = $DIC->wiki()->internal()->repo()->importantPage();
43 $this->wiki_repo = $DIC->wiki()->internal()->repo();
44 }
45
46 public function getSupportedVersions(): array
47 {
48 return array("4.1.0", "4.3.0", "4.4.0", "5.1.0", "5.4.0", "8.0");
49 }
50
51 protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
52 {
53 return "https://www.ilias.de/xml/Modules/Wiki/" . $a_entity;
54 }
55
56 protected function getTypes(string $a_entity, string $a_version): array
57 {
58 if ($a_entity === "wiki") {
59 switch ($a_version) {
60 case "4.1.0":
61 return array(
62 "Id" => "integer",
63 "Title" => "text",
64 "Description" => "text",
65 "StartPage" => "text",
66 "Short" => "text",
67 "Introduction" => "text",
68 "Rating" => "integer");
69
70 case "4.3.0":
71 return array(
72 "Id" => "integer",
73 "Title" => "text",
74 "Description" => "text",
75 "StartPage" => "text",
76 "Short" => "text",
77 "Introduction" => "text",
78 "Rating" => "integer",
79 "PublicNotes" => "integer",
80 // "ImpPages" => "integer",
81 "PageToc" => "integer",
82 "RatingSide" => "integer",
83 "RatingNew" => "integer",
84 "RatingExt" => "integer");
85
86 case "4.4.0":
87 return array(
88 "Id" => "integer",
89 "Title" => "text",
90 "Description" => "text",
91 "StartPage" => "text",
92 "Short" => "text",
93 "Introduction" => "text",
94 "Rating" => "integer",
95 "PublicNotes" => "integer",
96 // "ImpPages" => "integer",
97 "PageToc" => "integer",
98 "RatingSide" => "integer",
99 "RatingNew" => "integer",
100 "RatingExt" => "integer",
101 "RatingOverall" => "integer");
102
103 case "5.1.0":
104 return array(
105 "Id" => "integer",
106 "Title" => "text",
107 "Description" => "text",
108 "StartPage" => "text",
109 "Short" => "text",
110 "Introduction" => "text",
111 "Rating" => "integer",
112 "PublicNotes" => "integer",
113 // "ImpPages" => "integer",
114 "PageToc" => "integer",
115 "RatingSide" => "integer",
116 "RatingNew" => "integer",
117 "RatingExt" => "integer",
118 "RatingOverall" => "integer",
119 "LinkMdValues" => "integer"
120 );
121
122 case "5.4.0":
123 case "8.0":
124 return array(
125 "Id" => "integer",
126 "Title" => "text",
127 "Description" => "text",
128 "StartPage" => "text",
129 "Short" => "text",
130 "Introduction" => "text",
131 "Rating" => "integer",
132 "PublicNotes" => "integer",
133 // "ImpPages" => "integer",
134 "PageToc" => "integer",
135 "RatingSide" => "integer",
136 "RatingNew" => "integer",
137 "RatingExt" => "integer",
138 "RatingOverall" => "integer",
139 "LinkMdValues" => "integer",
140 "EmptyPageTempl" => "integer"
141 );
142 }
143 }
144
145 if ($a_entity === "wpg") {
146 switch ($a_version) {
147 case "4.1.0":
148 return array(
149 "Id" => "integer",
150 "Title" => "text",
151 "WikiId" => "integer");
152
153 case "4.3.0":
154 case "4.4.0":
155 case "5.1.0":
156 return array(
157 "Id" => "integer",
158 "Title" => "text",
159 "WikiId" => "integer",
160 "Blocked" => "integer",
161 "Rating" => "integer");
162
163 case "5.4.0":
164 return array(
165 "Id" => "integer",
166 "Title" => "text",
167 "WikiId" => "integer",
168 "Blocked" => "integer",
169 "Rating" => "integer",
170 "TemplateNewPages" => "integer",
171 "TemplateAddToPage" => "integer"
172 );
173
174 case "8.0":
175 return array(
176 "Id" => "integer",
177 "Title" => "text",
178 "WikiId" => "integer",
179 "Blocked" => "integer",
180 "Rating" => "integer",
181 "TemplateNewPages" => "integer",
182 "TemplateAddToPage" => "integer",
183 "Lang" => "text",
184 "ImportId" => "text"
185 );
186 }
187 }
188
189 if ($a_entity === "wiki_imp_page") {
190 switch ($a_version) {
191 case "5.1.0":
192 case "5.4.0":
193 case "8.0":
194 return array(
195 "WikiId" => "integer",
196 "PageId" => "integer",
197 "Ord" => "integer",
198 "Indent" => "integer");
199 }
200 }
201 return array();
202 }
203
204 public function readData(string $a_entity, string $a_version, array $a_ids): void
205 {
207 if (!is_array($a_ids)) {
208 $a_ids = array($a_ids);
209 }
210
211 if ($a_entity === "wiki") {
212 switch ($a_version) {
213 case "4.1.0":
214 $this->getDirectDataFromQuery("SELECT id, title, description," .
215 " startpage start_page, short, rating, introduction" .
216 " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
217 " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
218 break;
219
220 case "4.3.0":
221 $this->getDirectDataFromQuery("SELECT id, title, description," .
222 " startpage start_page, short, rating, introduction," . // imp_pages,
223 " public_notes, page_toc, rating_side, rating_new, rating_ext" .
224 " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
225 " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
226 break;
227
228 case "4.4.0":
229 $this->getDirectDataFromQuery("SELECT id, title, description," .
230 " startpage start_page, short, rating, rating_overall, introduction," . // imp_pages,
231 " public_notes, page_toc, rating_side, rating_new, rating_ext" .
232 " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
233 " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
234 break;
235
236 case "5.1.0":
237 $this->getDirectDataFromQuery("SELECT id, title, description," .
238 " startpage start_page, short, rating, rating_overall, introduction," . // imp_pages,
239 " public_notes, page_toc, rating_side, rating_new, rating_ext, link_md_values" .
240 " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
241 " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
242 break;
243
244 case "5.4.0":
245 case "8.0":
246 $this->getDirectDataFromQuery("SELECT id, title, description," .
247 " startpage start_page, short, rating, rating_overall, introduction," . // imp_pages,
248 " public_notes, page_toc, rating_side, rating_new, rating_ext, link_md_values, empty_page_templ" .
249 " FROM il_wiki_data JOIN object_data ON (il_wiki_data.id = object_data.obj_id)" .
250 " WHERE " . $ilDB->in("id", $a_ids, false, "integer"));
251 break;
252 }
253 }
254
255 if ($a_entity === "wpg") {
256 switch ($a_version) {
257 case "4.1.0":
258 $this->getDirectDataFromQuery("SELECT id, title, wiki_id" .
259 " FROM il_wiki_page" .
260 " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
261 break;
262
263 case "4.3.0":
264 case "4.4.0":
265 case "5.1.0":
266 $this->getDirectDataFromQuery("SELECT id, title, wiki_id," .
267 " blocked, rating" .
268 " FROM il_wiki_page" .
269 " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
270 break;
271
272 case "5.4.0":
273 $this->getDirectDataFromQuery("SELECT id, title, wiki_id," .
274 " blocked, rating" .
275 " FROM il_wiki_page" .
276 " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
277 foreach ($this->data as $k => $v) {
278 $set = $ilDB->queryF(
279 "SELECT * FROM wiki_page_template " .
280 " WHERE wiki_id = %s " .
281 " AND wpage_id = %s ",
282 ["integer", "integer"],
283 [$v["WikiId"], $v["Id"]]
284 );
285 if ($rec = $ilDB->fetchAssoc($set)) {
286 $this->data[$k]["TemplateNewPages"] = $rec["new_pages"];
287 $this->data[$k]["TemplateAddToPage"] = $rec["add_to_page"];
288 }
289 }
290 break;
291
292 case "8.0":
293 $this->getDirectDataFromQuery("SELECT id, title, wiki_id," .
294 " blocked, rating, lang" .
295 " FROM il_wiki_page" .
296 " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
297 foreach ($this->data as $k => $v) {
298 $set = $ilDB->queryF(
299 "SELECT * FROM wiki_page_template " .
300 " WHERE wiki_id = %s " .
301 " AND wpage_id = %s ",
302 ["integer", "integer"],
303 [$v["WikiId"], $v["Id"]]
304 );
305 if ($rec = $ilDB->fetchAssoc($set)) {
306 $this->data[$k]["TemplateNewPages"] = $rec["new_pages"];
307 $this->data[$k]["TemplateAddToPage"] = $rec["add_to_page"];
308 }
309 $this->data[$k]["ImportId"] = "il_" . IL_INST_ID . "_wpage_" . $v["Id"];
310 }
311 break;
312 }
313 }
314
315 if ($a_entity === "wiki_imp_page") {
316 switch ($a_version) {
317 case "5.1.0":
318 case "5.4.0":
319 case "8.0":
320 $this->getDirectDataFromQuery("SELECT wiki_id, page_id, ord, indent " .
321 " FROM il_wiki_imp_pages " .
322 " WHERE " . $ilDB->in("wiki_id", $a_ids, false, "integer"));
323 break;
324 }
325 }
326 }
327
328 protected function getDependencies(
329 string $a_entity,
330 string $a_version,
331 ?array $a_rec = null,
332 ?array $a_ids = null
333 ): array {
334 switch ($a_entity) {
335 case "wiki":
336 return array(
337 "wpg" => array("ids" => $a_rec["Id"] ?? null),
338 "wiki_imp_page" => array("ids" => $a_rec["Id"] ?? null)
339 );
340 }
341
342 return [];
343 }
344
345 public function importRecord(
346 string $a_entity,
347 array $a_types,
348 array $a_rec,
349 ilImportMapping $a_mapping,
350 string $a_schema_version
351 ): void {
352 $a_rec = $this->stripTags($a_rec);
353 switch ($a_entity) {
354 case "wiki":
355
356 if ($new_id = $a_mapping->getMapping('components/ILIAS/Container', 'objs', $a_rec['Id'])) {
357 $newObj = ilObjectFactory::getInstanceByObjId($new_id, false);
358 } else {
359 $newObj = new ilObjWiki();
360 $newObj->setType("wiki");
361 $newObj->create(true);
362 }
363
364 $newObj->setTitle($a_rec["Title"]);
365 $newObj->setDescription($a_rec["Description"]);
366 $newObj->setShortTitle($a_rec["Short"]);
367 $newObj->setStartPage($a_rec["StartPage"]);
368 $newObj->setRatingOverall($a_rec["RatingOverall"]);
369 $newObj->setRatingPages($a_rec["Rating"]);
370 $newObj->setIntroduction($a_rec["Introduction"]);
371 $newObj->setPublicNotes($a_rec["PublicNotes"]);
372
373 // >= 4.3
374 if (isset($a_rec["PageToc"])) {
375 $newObj->setPageToc($a_rec["PageToc"]);
376 $newObj->setRatingAsBlock($a_rec["RatingSide"]);
377 $newObj->setRatingForNewPages($a_rec["RatingNew"]);
378 $newObj->setRatingCategories($a_rec["RatingExt"]);
379 }
380 $newObj->setLinkMetadataValues($a_rec["LinkMdValues"]);
381 $newObj->setEmptyPageTemplate((int) $a_rec["EmptyPageTempl"]);
382
383 $newObj->update(true);
384 $this->current_obj = $newObj;
385 $a_mapping->addMapping("components/ILIAS/Wiki", "wiki", $a_rec["Id"], $newObj->getId());
386 $a_mapping->addMapping("components/ILIAS/ILIASObject", "obj", $a_rec["Id"], $newObj->getId());
387 $a_mapping->addMapping("components/ILIAS/Rating", "rating_category_parent_id", $a_rec["Id"], $newObj->getId());
388 $a_mapping->addMapping("components/ILIAS/AdvancedMetaData", "parent", $a_rec["Id"], $newObj->getId());
389 $a_mapping->addMapping(
390 "components/ILIAS/MetaData",
391 "md",
392 $a_rec["Id"] . ":0:wiki",
393 $newObj->getId() . ":0:wiki"
394 );
395 break;
396
397 case "wpg":
398 $wiki_id = $a_mapping->getMapping("components/ILIAS/Wiki", "wiki", $a_rec["WikiId"]);
399 $lang = ($a_rec["Lang"] ?? "");
400 $wpage = new ilWikiPage();
401 if (!in_array($lang, ["", "-"])) {
402 $wpage->setLanguage($lang);
403 }
404 $wpage->setWikiId($wiki_id);
405 $wpage->setTitle($a_rec["Title"]);
406
407 // >= 4.3
408 if (isset($a_rec["Blocked"])) {
409 $wpage->setBlocked($a_rec["Blocked"]);
410 $wpage->setRating($a_rec["Rating"]);
411 }
412
413 $wpage->create(true);
414
415 if (isset($a_rec["ImportId"])) {
416 $this->wiki_repo->page()->writeImportId(
417 $wpage->getId(),
418 ($lang === "") ? "-" : $lang,
419 (string) $a_rec["ImportId"]
420 );
421 }
422
423 if (isset($a_rec["TemplateNewPages"]) || isset($a_rec["TemplateAddToPage"])) {
424 $wtpl = new ilWikiPageTemplate($wiki_id);
425 $wtpl->save($wpage->getId(), (int) $a_rec["TemplateNewPages"], (int) $a_rec["TemplateAddToPage"]);
426 }
427
428 $a_mapping->addMapping("components/ILIAS/Wiki", "wpg", $a_rec["Id"], $wpage->getId());
429 $a_mapping->addMapping("components/ILIAS/COPage", "pg", "wpg:" . $a_rec["Id"], "wpg:" . $wpage->getId());
430 $a_mapping->addMapping("components/ILIAS/AdvancedMetaData", "advmd_sub_item", "advmd:wpg:" . $a_rec["Id"], $wpage->getId());
431 break;
432
433 case "wiki_imp_page":
434 $wiki_id = $a_mapping->getMapping("components/ILIAS/Wiki", "wiki", $a_rec["WikiId"]);
435 $page_id = $a_mapping->getMapping("components/ILIAS/Wiki", "wpg", $a_rec["PageId"]);
436 if ($wiki_id > 0 && $page_id > 0 && is_object($this->current_obj) && $this->current_obj->getId() === (int) $wiki_id) {
437 $this->imp_page_repo->add($this->current_obj->getId(), (int) $page_id, (int) $a_rec["Ord"], (int) $a_rec["Indent"]);
438 }
439 break;
440 }
441 }
442}
A dataset contains in data in a common structure that can be shared and transformed for different pur...
getDirectDataFromQuery(string $a_query, bool $a_convert_to_leading_upper=true, bool $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
ilDBInterface $db
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readData(string $a_entity, string $a_version, array $a_ids)
Read data from DB.
getDependencies(string $a_entity, string $a_version, ?array $a_rec=null, ?array $a_ids=null)
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
Needs to be overwritten for import use case.
ILIAS Wiki Navigation ImportantPageDBRepository $imp_page_repo
getXmlNamespace(string $a_entity, string $a_schema_version)
getTypes(string $a_entity, string $a_version)
Get (abstract) types for (abstract) field names.
ILIAS Wiki InternalRepoService $wiki_repo
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_INST_ID
Definition: constants.php:40
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26