ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDatabaseConfigStoredObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
26{
27 public function getHash(): string
28 {
29 return hash("sha256", self::class);
30 }
31
32 public function getLabel(): string
33 {
34 return "Fill ini with settings for Services/Database";
35 }
36
37 public function isNotable(): bool
38 {
39 return false;
40 }
41
45 public function getPreconditions(Environment $environment): array
46 {
47 return [
49 new ilDatabaseExistsObjective($this->config)
50 ];
51 }
52
53 public function achieve(Environment $environment): Environment
54 {
55 $client_ini = $environment->getResource(Environment::RESOURCE_CLIENT_INI);
56
57 $type = $this->config->getType();
58
59 if ($type === 'postgres' || $type === 'pdo-postgre') {
60 throw new NotExecutableException('ILIAS 8 no longer Supports POSTGRES');
61 }
62
63 $client_ini->setVariable("db", "type", $type);
64 $client_ini->setVariable("db", "host", $this->config->getHost());
65 $client_ini->setVariable("db", "name", $this->config->getDatabase());
66 $client_ini->setVariable("db", "user", $this->config->getUser());
67 $client_ini->setVariable("db", "port", (string) ($this->config->getPort() ?? ""));
68 $pw = $this->config->getPassword();
69 $client_ini->setVariable("db", "pass", $pw !== null ? $pw->toString() : "");
70
71 if (!$client_ini->write()) {
72 throw new UnachievableException("Could not write client.ini.php");
73 }
74
75 return $environment;
76 }
77
78 public function isApplicable(Environment $environment): bool
79 {
80 $client_ini = $environment->getResource(Environment::RESOURCE_CLIENT_INI);
81
82 $port = $this->config->getPort() ?? "";
83 $pass = $this->config->getPassword() !== null ? $this->config->getPassword()->toString() : "";
84 if ($client_ini->readVariable("db", "type") !== $this->config->getType()) {
85 return true;
86 }
87 if ($client_ini->readVariable("db", "host") !== $this->config->getHost()) {
88 return true;
89 }
90 if ($client_ini->readVariable("db", "name") !== $this->config->getDatabase()) {
91 return true;
92 }
93 if ($client_ini->readVariable("db", "user") !== $this->config->getUser()) {
94 return true;
95 }
96 if ($client_ini->readVariable("db", "port") !== $port) {
97 return true;
98 }
99 return $client_ini->readVariable("dv", "pass") !== $pass;
100 }
101}
Signals that the setup is not executable at all.
Signals that some goal won't be achievable by actions of the system ever.
achieve(Environment $environment)
Objectives can be achieved.
getLabel()
Get a label that describes this objective.
isNotable()
Get to know if this is an interesting objective for a human.
isApplicable(Environment $environment)
Get to know whether the objective is applicable.
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.