ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilDatabaseUpdatedObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
22 use ILIAS\DI;
23 
24 class ilDatabaseUpdatedObjective implements Setup\Objective
25 {
26  public function getHash(): string
27  {
28  return hash("sha256", self::class);
29  }
30 
31  public function getLabel(): string
32  {
33  return "The database is updated.";
34  }
35 
36  public function isNotable(): bool
37  {
38  return true;
39  }
40 
44  public function getPreconditions(Setup\Environment $environment): array
45  {
46  $preconditions = [];
47  $preconditions[] = new Setup\Objective\ClientIdReadObjective();
48  $preconditions[] = new ilIniFilesPopulatedObjective();
49  $preconditions[] = new ilDatabaseInitializedObjective();
50 
51  return $preconditions;
52  }
53 
54  public function achieve(Setup\Environment $environment): Setup\Environment
55  {
56  $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
57  $io = $environment->getResource(Setup\Environment::RESOURCE_ADMIN_INTERACTION);
58  $ini = $environment->getResource(Setup\Environment::RESOURCE_ILIAS_INI);
59  $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
60  $client_id = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_ID);
61 
62  // ATTENTION: This is a total abomination. It only exists to allow the db-
63  // update to run. This is a memento to the fact, that dependency injection
64  // is something we want. Currently, every component could just service
65  // locate the whole world via the global $DIC.
67  $DIC = $GLOBALS["DIC"] ?? [];
68  $GLOBALS["DIC"] = new DI\Container();
69  $GLOBALS["DIC"]["ilDB"] = $db;
70  $GLOBALS["ilDB"] = $db;
71  $GLOBALS["DIC"]["ilBench"] = null;
72  $GLOBALS["DIC"]["ilLog"] = new class ($io) {
73  protected $io;
74  public function __construct($io)
75  {
76  $this->io = $io;
77  }
78 
79  public function write(): void
80  {
81  }
82 
83  public function info(): void
84  {
85  }
86 
87  public function warning($msg): void
88  {
89  $this->io->inform($msg);
90  }
91 
92  public function error($msg): void
93  {
94  throw new Setup\UnachievableException(
95  "Problem in DB-Update: $msg"
96  );
97  }
98  };
99  $GLOBALS["ilLog"] = $GLOBALS["DIC"]["ilLog"];
100  $GLOBALS["DIC"]["ilLoggerFactory"] = new class () {
101  public function getRootLogger(): object
102  {
103  return new class () {
104  public function write(): void
105  {
106  }
107  };
108  }
109  };
110  $GLOBALS["ilCtrlStructureReader"] = new class () {
111  public function getStructure(): void
112  {
113  }
114 
115  public function setIniFile(): void
116  {
117  }
118  };
119  if (!defined("CLIENT_DATA_DIR")) {
120  define("CLIENT_DATA_DIR", $ini->readVariable("clients", "datadir") . "/" . $client_id);
121  }
122  if (!defined("CLIENT_WEB_DIR")) {
123  define("CLIENT_WEB_DIR", dirname(__DIR__, 4) . "/data/" . $client_id);
124  }
125  if (!defined("ILIAS_ABSOLUTE_PATH")) {
126  define("ILIAS_ABSOLUTE_PATH", dirname(__FILE__, 5));
127  }
128  if (!defined("ILIAS_LOG_ENABLED")) {
129  define("ILIAS_LOG_ENABLED", false);
130  }
131  if (!defined("ROOT_FOLDER_ID")) {
132  define("ROOT_FOLDER_ID", (int) $client_ini->readVariable("system", "ROOT_FOLDER_ID"));
133  }
134  if (!defined("ROLE_FOLDER_ID")) {
135  define("ROLE_FOLDER_ID", (int) $client_ini->readVariable("system", "ROLE_FOLDER_ID"));
136  }
137  if (!defined("SYSTEM_FOLDER_ID")) {
138  define("SYSTEM_FOLDER_ID", (int) $client_ini->readVariable("system", "SYSTEM_FOLDER_ID"));
139  }
140 
141  $db_update = new ilDBUpdate($db);
142  $db_update->applyCustomUpdates();
143 
144  $GLOBALS["DIC"] = $DIC;
145 
146  return $environment;
147  }
148 
152  public function isApplicable(Setup\Environment $environment): bool
153  {
154  return true;
155  }
156 }
getPreconditions(Setup\Environment $environment)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Container.php:19
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
$GLOBALS["DIC"]
Definition: wac.php:31
isApplicable(Setup\Environment $environment)
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
Database Update class.
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
$client_id
Definition: ltiauth.php:68
achieve(Setup\Environment $environment)
$ini
Definition: raiseError.php:4