ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDatabaseConfigStoredObjective.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
7
9{
10 public function getHash() : string
11 {
12 return hash("sha256", self::class);
13 }
14
15 public function getLabel() : string
16 {
17 return "Fill ini with settings for Services/Database";
18 }
19
20 public function isNotable() : bool
21 {
22 return false;
23 }
24
25 public function getPreconditions(Setup\Environment $environment) : array
26 {
27 return [
29 new ilDatabaseExistsObjective($this->config)
30 ];
31 }
32
33 public function achieve(Setup\Environment $environment) : Setup\Environment
34 {
35 $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
36
37 $client_ini->setVariable("db", "type", $this->config->getType());
38 $client_ini->setVariable("db", "host", $this->config->getHost());
39 $client_ini->setVariable("db", "name", $this->config->getDatabase());
40 $client_ini->setVariable("db", "user", $this->config->getUser());
41 $client_ini->setVariable("db", "port", $this->config->getPort() ?? "");
42 $pw = $this->config->getPassword();
43 $client_ini->setVariable("db", "pass", $pw ? $pw->toString() : "");
44
45 if (!$client_ini->write()) {
46 throw new Setup\UnachievableException("Could not write client.ini.php");
47 }
48
49 return $environment;
50 }
51
52 public function isApplicable(Setup\Environment $environment) : bool
53 {
54 $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
55
56 $port = $this->config->getPort() ?? "";
57 $pass = $this->config->getPassword() ? $this->config->getPassword()->toString() : "";
58
59 return
60 $client_ini->readVariable("db", "type") !== $this->config->getType() ||
61 $client_ini->readVariable("db", "host") !== $this->config->getHost() ||
62 $client_ini->readVariable("db", "name") !== $this->config->getDatabase() ||
63 $client_ini->readVariable("db", "user") !== $this->config->getUser() ||
64 $client_ini->readVariable("db", "port") !== $port ||
65 $client_ini->readVariable("dv", "pass") !== $pass
66 ;
67 }
68}
An exception for terminatinating execution or to throw for unit testing.
Signals that some goal won't be achievable by actions of the system ever.
An environment holds resources to be used in the setup process.
Definition: Environment.php:12
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...