ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilDatabaseExistsObjective.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  return hash("sha256", implode("-", [
29  self::class,
30  $this->config->getHost(),
31  $this->config->getPort(),
32  $this->config->getDatabase()
33  ]));
34  }
35 
36  public function getLabel(): string
37  {
38  return "The database exists on the server.";
39  }
40 
41  public function isNotable(): bool
42  {
43  return true;
44  }
45 
49  public function getPreconditions(Environment $environment): array
50  {
51  $preconditions = [
52  new \ilDatabaseServerIsConnectableObjective($this->config)
53  ];
54  if ($this->config->getCreateDatabase()) {
55  $preconditions[] = new \ilDatabaseCreatedObjective($this->config);
56  }
57  return $preconditions;
58  }
59 
60  public function achieve(Environment $environment): Environment
61  {
62  $db = \ilDBWrapperFactory::getWrapper($this->config->getType());
63  $db->initFromIniFile($this->config->toMockIniFile());
64  $connect = $db->connect(true);
65  if (!$connect) {
66  throw new UnachievableException(
67  "Database cannot be connected. Please check the credentials."
68  );
69  }
70 
71  return $environment->withResource(Environment::RESOURCE_DATABASE, $db);
72  }
73 
77  public function isApplicable(Environment $environment): bool
78  {
79  return true;
80  }
81 }
isNotable()
Get to know if this is an interesting objective for a human.
achieve(Environment $environment)
Objectives can be achieved.
withResource(string $id, $resource)
getHash()
Get a hash for this objective.
static getWrapper(string $a_type)
Signals that some goal won&#39;t be achievable by actions of the system ever.
getPreconditions(Environment $environment)
getLabel()
Get a label that describes this objective.
An environment holds resources to be used in the setup process.
Definition: Environment.php:27