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