ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDatabaseInitializedObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
22 
23 class ilDatabaseInitializedObjective implements Setup\Objective
24 {
25  public function getHash(): string
26  {
27  return hash("sha256", self::class);
28  }
29 
30  public function getLabel(): string
31  {
32  return "The database object is initialized.";
33  }
34 
35  public function isNotable(): bool
36  {
37  return true;
38  }
39 
43  public function getPreconditions(Setup\Environment $environment): array
44  {
45  // If there is no config for the database the existing config seems
46  // to be ok, and we can just connect.
47  if (!$environment->hasConfigFor("database")) {
48  return [
50  ];
51  }
52 
53  $config = $environment->getConfigFor("database");
54  return [
57  ];
58  }
59 
60  public function achieve(Setup\Environment $environment): Setup\Environment
61  {
62  if ($environment->getResource(Setup\Environment::RESOURCE_DATABASE)) {
63  return $environment;
64  }
65 
66  $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
67 
68  $type = $client_ini->readVariable("db", "type");
69  if ($type === "") {
71  }
72 
74  $db->initFromIniFile($client_ini);
75  $connect = $db->connect(true);
76  if (!$connect) {
77  throw new Setup\UnachievableException(
78  "Database cannot be connected."
79  );
80  }
81 
82  return $environment->withResource(Setup\Environment::RESOURCE_DATABASE, $db);
83  }
84 
88  public function isApplicable(Setup\Environment $environment): bool
89  {
90  return $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI) !== null;
91  }
92 }
$type
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85
static getWrapper(string $a_type)
getPreconditions(Setup\Environment $environment)
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27