ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDatabaseInitializedObjective.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 use ILIAS\Setup;
6 
7 class ilDatabaseInitializedObjective implements Setup\Objective
8 {
9  public function getHash() : string
10  {
11  return hash("sha256", self::class);
12  }
13 
14  public function getLabel() : string
15  {
16  return "The database object is initialized.";
17  }
18 
19  public function isNotable() : bool
20  {
21  return true;
22  }
23 
24  public function getPreconditions(Setup\Environment $environment) : array
25  {
26  // If there is no config for the database the existing config seems
27  // to be ok, and we can just connect.
28  if (!$environment->hasConfigFor("database")) {
29  return [
31  ];
32  }
33 
34  $config = $environment->getConfigFor("database");
35  return [
38  ];
39  }
40 
41  public function achieve(Setup\Environment $environment) : Setup\Environment
42  {
43  if ($environment->getResource(Setup\Environment::RESOURCE_DATABASE)) {
44  return $environment;
45  }
46 
47  $client_ini = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI);
48 
49  $type = $client_ini->readVariable("db", "type");
50  if ($type == "") {
51  $type = "mysql";
52  }
53 
55  $db->initFromIniFile($client_ini);
56  $connect = $db->connect(true);
57  if (!$connect) {
58  throw new Setup\UnachievableException(
59  "Database cannot be connected."
60  );
61  }
62  return $environment->withResource(Setup\Environment::RESOURCE_DATABASE, $db);
63  }
64 
68  public function isApplicable(Setup\Environment $environment) : bool
69  {
70  return $environment->getResource(Setup\Environment::RESOURCE_CLIENT_INI) !== null;
71  }
72 }
$type
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
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:11