ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilDatabaseUpdatedObjective.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 use ILIAS\Setup;
6 use ILIAS\DI;
7 
9 {
13  protected $config;
14 
18  protected $populate_before;
19 
21  {
22  parent::__construct($config);
23  $this->populate_before = $populate_before;
24  }
25 
26  public function getHash() : string
27  {
28  return hash("sha256", implode("-", [
29  self::class,
30  $this->config->getHost(),
31  $this->config->getPort(),
32  $this->config->getDatabase()
33  ]));
34  }
35 
36  public function getLabel() : string
37  {
38  return "The database is updated.";
39  }
40 
41  public function isNotable() : bool
42  {
43  return true;
44  }
45 
46  public function getPreconditions(Setup\Environment $environment) : array
47  {
48  $common_config = $environment->getConfigFor("common");
49  if (!$this->populate_before) {
50  return [
51  new \ilIniFilesLoadedObjective($common_config),
52  new \ilDatabaseExistsObjective($this->config)
53  ];
54  }
55  return [
56  new \ilIniFilesPopulatedObjective($common_config),
57  new \ilDatabasePopulatedObjective($this->config)
58  ];
59  }
60 
61  public function achieve(Setup\Environment $environment) : Setup\Environment
62  {
63  $db = $environment->getResource(Setup\Environment::RESOURCE_DATABASE);
64  $io = $environment->getResource(Setup\Environment::RESOURCE_ADMIN_INTERACTION);
65  $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
66  $common_config = $environment->getConfigFor("common");
67  $filesystem_config = $environment->getConfigFor("filesystem");
68 
69  // ATTENTION: This is a total abomination. It only exists to allow the db-
70  // update to run. This is a memento to the fact, that dependency injection
71  // is something we want. Currently, every component could just service
72  // locate the whole world via the global $DIC.
73  $DIC = $GLOBALS["DIC"] ?? [];
74  $GLOBALS["DIC"] = new DI\Container();
75  $GLOBALS["DIC"]["ilDB"] = $db;
76  $GLOBALS["ilDB"] = $db;
77  $GLOBALS["DIC"]["ilBench"] = null;
78  $GLOBALS["DIC"]["ilLog"] = new class($io) {
79  public function __construct($io)
80  {
81  $this->io = $io;
82  }
83  public function write()
84  {
85  }
86  public function info()
87  {
88  }
89  public function warning($msg)
90  {
91  $this->io->inform($msg);
92  }
93  public function error($msg)
94  {
95  throw new Setup\UnachievableException(
96  "Problem in DB-Update: $msg"
97  );
98  }
99  };
100  $GLOBALS["ilLog"] = $GLOBALS["DIC"]["ilLog"];
101  $GLOBALS["DIC"]["ilLoggerFactory"] = new class() {
102  public function getRootLogger()
103  {
104  return new class() {
105  public function write()
106  {
107  }
108  };
109  }
110  };
111  $GLOBALS["ilCtrlStructureReader"] = new class() {
112  public function getStructure()
113  {
114  }
115  public function setIniFile()
116  {
117  }
118  };
119  define("CLIENT_DATA_DIR", $filesystem_config->getDataDir() . "/" . $common_config->getClientId());
120  define("CLIENT_WEB_DIR", $filesystem_config->getWebDir() . "/" . $common_config->getClientId());
121  if (!defined("ILIAS_ABSOLUTE_PATH")) {
122  define("ILIAS_ABSOLUTE_PATH", dirname(__FILE__, 5));
123  }
124  if (!defined("ILIAS_LOG_ENABLED")) {
125  define("ILIAS_LOG_ENABLED", false);
126  }
127  define("ROOT_FOLDER_ID", $client_ini->readVariable("system", "ROOT_FOLDER_ID"));
128  define("ROLE_FOLDER_ID", $client_ini->readVariable("system", "ROLE_FOLDER_ID"));
129  define("SYSTEM_FOLDER_ID", $client_ini->readVariable("system", "SYSTEM_FOLDER_ID"));
130 
131 
132  $db_update = new class($db, $client_ini) extends ilDBUpdate {
133  public function loadXMLInfo()
134  {
135  }
136  };
137 
138  $db_update->applyUpdate();
139  $db_update->applyHotfix();
140  $db_update->applyCustomUpdates();
141 
142  return $environment;
143  }
144 }
getPreconditions(Setup\Environment $environment)
Class HTTPServicesTest.
__construct(\ilDatabaseSetupConfig $config, bool $populate_before=false)
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
Database Update class.
An environment holds resources to be used in the setup process.
Definition: Environment.php:11
__construct(Container $dic, ilPlugin $plugin)
info()
Definition: info.php:2
$DIC
Definition: xapitoken.php:46
achieve(Setup\Environment $environment)
applyUpdate($a_break=0)
Apply update.