ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDatabaseServerIsConnectableObjective.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
6
8{
9 public function getHash() : string
10 {
11 $pw = $this->config->getPassword();
12 return hash("sha256", implode("-", [
13 self::class,
14 $this->config->getHost(),
15 $this->config->getPort(),
16 $this->config->getUser(),
17 $pw ? $pw->toString() : ""
18 ]));
19 }
20
21 public function getLabel() : string
22 {
23 return "The database server is connectable with the supplied configuration.";
24 }
25
26 public function isNotable() : bool
27 {
28 return true;
29 }
30
31 public function getPreconditions(Setup\Environment $environment) : array
32 {
33 return [];
34 }
35
36 public function achieve(Setup\Environment $environment) : Setup\Environment
37 {
38 $db = \ilDBWrapperFactory::getWrapper($this->config->getType());
39 $db->initFromIniFile($this->config->toMockIniFile());
40 try {
41 $connect = $db->connect();
42 } catch (PDOException $e) {
43 // 1049 is "unknown database", which is ok because we propably didn't
44 // install the db yet,.
45 if ($e->getCode() != 1049) {
46 throw $e;
47 } else {
48 $connect = true;
49 }
50 }
51 if (!$connect) {
53 "Database cannot be reached. Please check the credentials."
54 );
55 }
56 return $environment;
57 }
58
62 public function isApplicable(Setup\Environment $environment) : bool
63 {
64 return true;
65 }
66}
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...