ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilGlossaryCollectionMigration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Setup;
24
29{
30 protected ilDBInterface $db;
31
32 public function getLabel(): string
33 {
34 return "Migration of collection glossaries due to revision";
35 }
36
38 {
39 return Migration::INFINITE;
40 }
41
42 public function getPreconditions(Environment $environment): array
43 {
44 return [
48 ];
49 }
50
51 public function prepare(Environment $environment): void
52 {
53 $this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
54 }
55
56 public function step(Environment $environment): void
57 {
58 $set = $this->db->query(
59 "SELECT glossary.id AS glossary_id, glossary.virtual, glossary_term.id AS term_id, glossary_term.glo_id " .
60 " FROM glossary LEFT JOIN glossary_term ON glossary.id = glossary_term.glo_id " .
61 " WHERE glossary.virtual = 'level' OR glossary.virtual = 'subtree' " .
62 " ORDER BY glossary.id"
63 );
64 $tmp_id = 0;
65 while ($rec = $this->db->fetchAssoc($set)) {
66 $glo_id = (int) $rec["glossary_id"];
67 $term_id = (int) $rec["term_id"];
68 if ($glo_id === $tmp_id) {
69 continue;
70 }
71 if ($term_id > 0) {
72 $this->db->manipulate(
73 "UPDATE glossary SET " .
74 " glossary.virtual = " . $this->db->quote("none", "text") .
75 " WHERE glossary.id = " . $this->db->quote($glo_id, "integer")
76 );
77 $this->log("Convert glossary with id " . $glo_id . " into Standard Glossary.");
78 } else {
79 $this->db->manipulate(
80 "UPDATE glossary SET " .
81 " glossary.virtual = " . $this->db->quote("coll", "text") .
82 " WHERE glossary.id = " . $this->db->quote($glo_id, "integer")
83 );
84 $this->log("Convert glossary with id " . $glo_id . " into Collection Glossary.");
85 }
86
87 $tmp_id = $glo_id;
88 }
89 }
90
91 protected function log(string $str): void
92 {
93 echo "\n" . $str;
94 }
95
96 public function getRemainingAmountOfSteps(): int
97 {
98 $set = $this->db->query(
99 "SELECT glossary.virtual FROM glossary " .
100 " WHERE glossary.virtual = 'level' OR glossary.virtual = 'subtree'"
101 );
102 if ($rec = $this->db->fetchAssoc($set)) {
103 return 1;
104 }
105
106 return 0;
107 }
108}
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
A migration is a potentially long lasting operation that can be broken into discrete steps.
Definition: Migration.php:29
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...