ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDatabaseInitializedObjective.php
Go to the documentation of this file.
1<?php
2
19declare(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 [
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}
Signals that some goal won't be achievable by actions of the system ever.
static getWrapper(string $a_type)
isNotable()
Get to know if this is an interesting objective for a human.
achieve(Environment $environment)
Objectives can be achieved.
getLabel()
Get a label that describes this objective.
isApplicable(Environment $environment)
@inheritDoc
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
hasConfigFor(string $component)
getConfigFor(string $component)
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
withResource(string $id, $resource)
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31