ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilGlossaryDefinitionMigration Class Reference
+ Inheritance diagram for ilGlossaryDefinitionMigration:
+ Collaboration diagram for ilGlossaryDefinitionMigration:

Public Member Functions

 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 
 getPreconditions (Environment $environment)
 
 prepare (Environment $environment)
 
 step (Environment $environment)
 
 getRemainingAmountOfSteps ()
 

Protected Member Functions

 log (string $str)
 
 manipulate (string $query)
 

Protected Attributes

ilDBInterface $db
 

Detailed Description

Member Function Documentation

◆ getDefaultAmountOfStepsPerRun()

ilGlossaryDefinitionMigration::getDefaultAmountOfStepsPerRun ( )

Definition at line 37 of file class.ilGlossaryDefinitionMigration.php.

37  : int
38  {
39  return Migration::INFINITE;
40  }

◆ getLabel()

ilGlossaryDefinitionMigration::getLabel ( )

Definition at line 32 of file class.ilGlossaryDefinitionMigration.php.

32  : string
33  {
34  return "Migration of glossary definitions after abolition of multiple definitions";
35  }

◆ getPreconditions()

ilGlossaryDefinitionMigration::getPreconditions ( Environment  $environment)

◆ getRemainingAmountOfSteps()

ilGlossaryDefinitionMigration::getRemainingAmountOfSteps ( )

Definition at line 145 of file class.ilGlossaryDefinitionMigration.php.

145  : int
146  {
147  $set = $this->db->query(
148  "SELECT glossary_definition.id AS glo_def_id, glossary_definition.term_id AS glo_def_term_id, " .
149  " glossary_definition.short_text, glossary_definition.short_text_dirty, " .
150  " glossary_term.id AS glo_term_id, glossary_term.glo_id, glossary_term.term, glossary_term.language, " .
151  " glossary_term.create_date, glossary_term.last_update " .
152  " FROM glossary_definition JOIN glossary_term " .
153  " WHERE glossary_definition.term_id = glossary_term.id " .
154  " ORDER BY glossary_term.glo_id, glossary_term.id, glossary_definition.id"
155  );
156  $tmp = [];
157  while ($rec = $this->db->fetchAssoc($set)) {
158  // check if there are multiple definitions for a term
159  if (!empty($tmp)
160  && $tmp["glo_id"] == $rec["glo_id"]
161  && $tmp["glo_term_id"] == $rec["glo_term_id"]
162  ) {
163  return 1;
164  }
165  $tmp["glo_id"] = $rec["glo_id"];
166  $tmp["glo_term_id"] = $rec["glo_term_id"];
167  }
168 
169  $set = $this->db->query("SELECT * FROM glossary_definition WHERE migration = " . $this->db->quote("0", "integer"));
170  if ($rec = $this->db->fetchAssoc($set)) {
171  return 1;
172  }
173 
174  $set = $this->db->query("SELECT parent_type FROM copg_pobj_def WHERE parent_type = " . $this->db->quote("gdf", "text"));
175  if ($rec = $this->db->fetchAssoc($set)) {
176  return 1;
177  }
178 
179  return 0;
180  }

◆ log()

ilGlossaryDefinitionMigration::log ( string  $str)
protected

Definition at line 134 of file class.ilGlossaryDefinitionMigration.php.

Referenced by manipulate(), and step().

134  : void
135  {
136  echo "\n" . $str;
137  }
+ Here is the caller graph for this function:

◆ manipulate()

ilGlossaryDefinitionMigration::manipulate ( string  $query)
protected

Definition at line 139 of file class.ilGlossaryDefinitionMigration.php.

References log().

139  : void
140  {
141  $this->db->manipulate($query);
142  $this->log($query);
143  }
+ Here is the call graph for this function:

◆ prepare()

ilGlossaryDefinitionMigration::prepare ( Environment  $environment)

Definition at line 51 of file class.ilGlossaryDefinitionMigration.php.

References ILIAS\Setup\Environment\getResource().

51  : void
52  {
53  $this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
54  }
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
+ Here is the call graph for this function:

◆ step()

ilGlossaryDefinitionMigration::step ( Environment  $environment)

Definition at line 56 of file class.ilGlossaryDefinitionMigration.php.

References log().

56  : void
57  {
58  $set = $this->db->query(
59  "SELECT glossary_definition.id AS glo_def_id, glossary_definition.term_id AS glo_def_term_id, " .
60  " glossary_definition.short_text, glossary_definition.short_text_dirty, " .
61  " glossary_term.id AS glo_term_id, glossary_term.glo_id, glossary_term.term, glossary_term.language, " .
62  " glossary_term.create_date, glossary_term.last_update " .
63  " FROM glossary_definition JOIN glossary_term " .
64  " WHERE glossary_definition.term_id = glossary_term.id " .
65  " ORDER BY glossary_term.glo_id, glossary_term.id, glossary_definition.id"
66  );
67  $tmp = [];
68  while ($rec = $this->db->fetchAssoc($set)) {
69  // check if there are multiple definitions for a term
70  if (!empty($tmp)
71  && $tmp["glo_id"] == $rec["glo_id"]
72  && $tmp["glo_term_id"] == $rec["glo_term_id"]
73  ) {
74  $new_term_id = $this->db->nextId('glossary_term');
75  // create new term with same values, but new id
76  $this->log("Create new glossary term with id: " . $new_term_id);
77  $this->db->manipulate("INSERT INTO glossary_term (id, glo_id, term, language, import_id, create_date, last_update)" .
78  " VALUES (" .
79  $this->db->quote($new_term_id, "integer") . ", " .
80  $this->db->quote($rec["glo_id"], "integer") . ", " .
81  $this->db->quote($rec["term"], "text") . ", " .
82  $this->db->quote($rec["language"], "text") . "," .
83  $this->db->quote("", "text") . "," .
84  $this->db->quote($rec["create_date"], "text") . ", " .
85  $this->db->quote($rec["last_update"], "text") . ")");
86  // change definition with new term id
87  $this->db->manipulate(
88  "UPDATE glossary_definition SET " .
89  " term_id = " . $this->db->quote($new_term_id, "integer") .
90  " WHERE id = " . $this->db->quote($rec["glo_def_id"], "integer")
91  );
92  }
93  $tmp["glo_id"] = $rec["glo_id"];
94  $tmp["glo_term_id"] = $rec["glo_term_id"];
95  }
96 
97  $set = $this->db->query("SELECT * FROM glossary_definition WHERE migration = " . $this->db->quote("0", "integer"));
98  while ($rec = $this->db->fetchAssoc($set)) {
99  // merge glossary_term and glossary_definition table
100  $this->log("Add short text ('" . $rec["short_text"] . "') and short text dirty ('" .
101  $rec["short_text_dirty"] . "') to glossary term with id: " . $rec["term_id"]);
102  $this->db->manipulate(
103  "UPDATE glossary_term SET " .
104  " short_text = " . $this->db->quote($rec["short_text"], "text") . ", " .
105  " short_text_dirty = " . $this->db->quote($rec["short_text_dirty"], "integer") .
106  " WHERE id = " . $this->db->quote($rec["term_id"], "integer")
107  );
108  // update id and type in page objects
109  $this->log("Update id and type ('gdf' to 'term') for page object with id: " . $rec["id"]);
110  $this->db->manipulate(
111  "UPDATE page_object SET " .
112  " page_id = " . $this->db->quote($rec["term_id"], "integer") . ", " .
113  " parent_type = " . $this->db->quote("term", "text") .
114  " WHERE parent_type = " . $this->db->quote("gdf", "text") .
115  " AND page_id = " . $this->db->quote($rec["id"], "integer")
116  );
117  // set migration marker to 1 when it's done
118  $this->db->manipulate(
119  "UPDATE glossary_definition SET " .
120  " migration = " . $this->db->quote("1", "integer") .
121  " WHERE id = " . $this->db->quote($rec["id"], "integer")
122  );
123  }
124 
125  // update type in page object definition
126  $this->log("Update type ('gdf' to 'term') for page object definition.");
127  $this->db->manipulate(
128  "UPDATE copg_pobj_def SET " .
129  " parent_type = " . $this->db->quote("term", "text") .
130  " WHERE parent_type = " . $this->db->quote("gdf", "text")
131  );
132  }
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilGlossaryDefinitionMigration::$db
protected

Definition at line 30 of file class.ilGlossaryDefinitionMigration.php.


The documentation for this class was generated from the following file: