ILIAS  release_8 Revision v8.24
class.ilDatabaseServerIsConnectableObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Setup;
22
24{
25 public function getHash(): string
26 {
27 $pw = $this->config->getPassword();
28 return hash("sha256", implode("-", [
29 self::class,
30 $this->config->getHost(),
31 $this->config->getPort(),
32 $this->config->getUser(),
33 $pw !== null ? $pw->toString() : ""
34 ]));
35 }
36
37 public function getLabel(): string
38 {
39 return "The database server is connectable with the supplied configuration.";
40 }
41
42 public function isNotable(): bool
43 {
44 return true;
45 }
46
47 public function getPreconditions(Setup\Environment $environment): array
48 {
49 return [];
50 }
51
52 public function achieve(Setup\Environment $environment): Setup\Environment
53 {
54 $db = \ilDBWrapperFactory::getWrapper($this->config->getType());
55 $db->initFromIniFile($this->config->toMockIniFile());
56 try {
57 $connect = $db->connect();
58 } catch (PDOException $e) {
59 // 1049 is "unknown database", which is ok because we propably didn't
60 // install the db yet,.
61 if ($e->getCode() !== 1049) {
62 throw $e;
63 }
64
65 $connect = true;
66 }
67 if (!$connect) {
69 "Database cannot be reached. Please check the credentials."
70 );
71 }
72
73 return $environment;
74 }
75
79 public function isApplicable(Setup\Environment $environment): bool
80 {
81 return true;
82 }
83}
Signals that some goal won't be achievable by actions of the system ever.
static getWrapper(string $a_type)
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...