ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilDatabaseInitializedObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
26 {
27  public function getHash(): string
28  {
29  return hash("sha256", self::class);
30  }
31 
32  public function getLabel(): string
33  {
34  return "The database object is initialized.";
35  }
36 
37  public function isNotable(): bool
38  {
39  return true;
40  }
41 
45  public function getPreconditions(Environment $environment): array
46  {
47  // If there is no config for the database the existing config seems
48  // to be ok, and we can just connect.
49  if (!$environment->hasConfigFor("database")) {
50  return [
52  ];
53  }
54 
55  $config = $environment->getConfigFor("database");
56  return [
57  new ilDatabasePopulatedObjective($config),
59  ];
60  }
61 
62  public function achieve(Environment $environment): Environment
63  {
64  if ($environment->getResource(Environment::RESOURCE_DATABASE)) {
65  return $environment;
66  }
67 
68  $client_ini = $environment->getResource(Environment::RESOURCE_CLIENT_INI);
69 
70  $type = $client_ini->readVariable("db", "type");
71  if ($type === "") {
73  }
74 
76  $db->initFromIniFile($client_ini);
77  $connect = $db->connect(true);
78  if (!$connect) {
79  throw new UnachievableException(
80  "Database cannot be connected."
81  );
82  }
83 
84  return $environment->withResource(Environment::RESOURCE_DATABASE, $db);
85  }
86 
90  public function isApplicable(Environment $environment): bool
91  {
92  return $environment->getResource(Environment::RESOURCE_CLIENT_INI) !== null;
93  }
94 }
An objective is a desired state of the system that is supposed to be created by the setup...
Definition: Objective.php:30
achieve(Environment $environment)
Objectives can be achieved.
withResource(string $id, $resource)
getLabel()
Get a label that describes this objective.
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.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
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.
hasConfigFor(string $component)
getConfigFor(string $component)