ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilContentStyle9Migration.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
25 {
26  protected ilDBInterface $db;
27 
28  public function getLabel(): string
29  {
30  return "Migrate content styles to ILIAS 9.";
31  }
32 
34  {
35  return 50000;
36  }
37 
38  public function getPreconditions(Environment $environment): array
39  {
40  return [
45  ];
46  }
47 
48  public function prepare(Environment $environment): void
49  {
50  $this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
51  /*
52  $ilias_ini = $environment->getResource(Environment::RESOURCE_ILIAS_INI);
53  $client_id = $environment->getResource(Environment::RESOURCE_CLIENT_ID);
54  $data_dir = $ilias_ini->readVariable('clients', 'datadir');
55  $client_data_dir = "{$data_dir}/{$client_id}";
56  if (!defined("CLIENT_WEB_DIR")) {
57  define("CLIENT_WEB_DIR", dirname(__DIR__, 4) . "/data/" . $client_id);
58  }
59  if (!defined("ILIAS_WEB_DIR")) {
60  define("ILIAS_WEB_DIR", dirname(__DIR__, 4));
61  }
62  if (!defined("CLIENT_ID")) {
63  define("CLIENT_ID", $client_id);
64  }
65  if (!defined("ILIAS_DATA_DIR")) {
66  define("ILIAS_DATA_DIR", $data_dir);
67  }*/
68  }
69 
70  public function step(Environment $environment): void
71  {
72  $set = $this->db->queryF(
73  "SELECT * FROM style_parameter " .
74  " WHERE type = %s AND tag = %s LIMIT 1",
75  ["text", "text"],
76  ["text_block", "div"]
77  );
78  if ($rec = $this->db->fetchAssoc($set)) {
79  // check, if a similar parameter is not already been set
80  $set2 = $this->db->queryF(
81  "SELECT * FROM style_parameter " .
82  " WHERE style_id = %s AND tag = %s AND class = %s AND type = %s AND parameter = %s",
83  ["integer", "text", "text", "text", "text"],
84  [$rec["style_id"], "p", $rec["class"], "text_block", $rec["parameter"]]
85  );
86  if (!$this->db->fetchAssoc($set2)) {
87  $this->db->update(
88  "style_parameter",
89  [
90  "tag" => ["text", "p"]
91  ],
92  [ // where
93  "id" => ["integer", $rec["id"]]
94  ]
95  );
96 
97  $this->db->update(
98  "style_data",
99  [
100  "uptodate" => ["integer", 0]
101  ],
102  [ // where
103  "id" => ["integer", $rec["style_id"]]
104  ]
105  );
106  } else {
107  $this->db->manipulateF(
108  "DELETE FROM style_parameter WHERE " .
109  " id = %s",
110  ["integer"],
111  [$rec["id"]]
112  );
113  }
114  }
115  }
116 
117  public function getRemainingAmountOfSteps(): int
118  {
119  $set = $this->db->queryF(
120  "SELECT count(*) as amount FROM style_parameter " .
121  " WHERE type = %s AND tag = %s",
122  ["text", "text"],
123  ["text_block", "div"]
124  );
125  if ($rec = $this->db->fetchAssoc($set)) {
126  return (int) $rec["amount"];
127  }
128 
129  return 0;
130  }
131 }
prepare(Environment $environment)
Prepare the migration by means of some environment.
Class ilResourceStorageDB90.
A migration is a potentially long lasting operation that can be broken into discrete steps...
Definition: Migration.php:28
getPreconditions(Environment $environment)
Objectives the migration depend on.
step(Environment $environment)
Run one step of the migration.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.