ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilDatabaseServerIsConnectableObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
25 {
26  public function getHash(): string
27  {
28  $pw = $this->config->getPassword();
29  return hash("sha256", implode("-", [
30  self::class,
31  $this->config->getHost(),
32  $this->config->getPort(),
33  $this->config->getUser(),
34  $pw !== null ? $pw->toString() : ""
35  ]));
36  }
37 
38  public function getLabel(): string
39  {
40  return "The database server is connectable with the supplied configuration.";
41  }
42 
43  public function isNotable(): bool
44  {
45  return true;
46  }
47 
48  public function getPreconditions(Environment $environment): array
49  {
50  return [];
51  }
52 
53  public function achieve(Environment $environment): Environment
54  {
55  $db = \ilDBWrapperFactory::getWrapper($this->config->getType());
56  $db->initFromIniFile($this->config->toMockIniFile());
57  try {
58  $connect = $db->connect();
59  } catch (PDOException $e) {
60  // 1049 is "unknown database", which is ok because we propably didn't
61  // install the db yet,.
62  if ($e->getCode() !== 1049) {
63  throw $e;
64  }
65 
66  $connect = true;
67  }
68  if (!$connect) {
69  throw new UnachievableException(
70  "Database cannot be reached. Please check the credentials."
71  );
72  }
73 
74  return $environment;
75  }
76 
80  public function isApplicable(Environment $environment): bool
81  {
82  return true;
83  }
84 }
getPreconditions(Environment $environment)
Objectives might depend on other objectives.
achieve(Environment $environment)
Objectives can be achieved.
static getWrapper(string $a_type)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Signals that some goal won&#39;t be achievable by actions of the system ever.
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
isNotable()
Get to know if this is an interesting objective for a human.