ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDatabaseConfigStoredObjective.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 use ILIAS\Setup;
22 
24 {
25  public function getHash(): string
26  {
27  return hash("sha256", self::class);
28  }
29 
30  public function getLabel(): string
31  {
32  return "Fill ini with settings for Services/Database";
33  }
34 
35  public function isNotable(): bool
36  {
37  return false;
38  }
39 
43  public function getPreconditions(Setup\Environment $environment): array
44  {
45  return [
47  new ilDatabaseExistsObjective($this->config)
48  ];
49  }
50 
51  public function achieve(Setup\Environment $environment): Setup\Environment
52  {
53  $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
54 
55  $type = $this->config->getType();
56 
57  if ($type === 'postgres' || $type === 'pdo-postgre') {
58  throw new Setup\NotExecutableException('ILIAS 8 no longer Supports POSTGRES');
59  }
60 
61  $client_ini->setVariable("db", "type", $type);
62  $client_ini->setVariable("db", "host", $this->config->getHost());
63  $client_ini->setVariable("db", "name", $this->config->getDatabase());
64  $client_ini->setVariable("db", "user", $this->config->getUser());
65  $client_ini->setVariable("db", "port", (string) ($this->config->getPort() ?? ""));
66  $pw = $this->config->getPassword();
67  $client_ini->setVariable("db", "pass", $pw !== null ? $pw->toString() : "");
68 
69  if (!$client_ini->write()) {
70  throw new Setup\UnachievableException("Could not write client.ini.php");
71  }
72 
73  return $environment;
74  }
75 
76  public function isApplicable(Setup\Environment $environment): bool
77  {
78  $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
79 
80  $port = $this->config->getPort() ?? "";
81  $pass = $this->config->getPassword() !== null ? $this->config->getPassword()->toString() : "";
82 
83  return
84  $client_ini->readVariable("db", "type") !== $this->config->getType() ||
85  $client_ini->readVariable("db", "host") !== $this->config->getHost() ||
86  $client_ini->readVariable("db", "name") !== $this->config->getDatabase() ||
87  $client_ini->readVariable("db", "user") !== $this->config->getUser() ||
88  $client_ini->readVariable("db", "port") !== $port ||
89  $client_ini->readVariable("dv", "pass") !== $pass
90  ;
91  }
92 }
$type
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