ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDatabaseExistsObjective.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 
8 {
9  public function getHash() : string
10  {
11  return hash("sha256", implode("-", [
12  self::class,
13  $this->config->getHost(),
14  $this->config->getPort(),
15  $this->config->getDatabase()
16  ]));
17  }
18 
19  public function getLabel() : string
20  {
21  return "The database exists on the server.";
22  }
23 
24  public function isNotable() : bool
25  {
26  return true;
27  }
28 
29  public function getPreconditions(Setup\Environment $environment) : array
30  {
31  $preconditions = [
32  new \ilDatabaseServerIsConnectableObjective($this->config)
33  ];
34  if ($this->config->getCreateDatabase()) {
35  $preconditions[] = new \ilDatabaseCreatedObjective($this->config);
36  }
37  return $preconditions;
38  }
39 
40  public function achieve(Setup\Environment $environment) : Setup\Environment
41  {
42  $db = \ilDBWrapperFactory::getWrapper($this->config->getType());
43  $db->initFromIniFile($this->config->toMockIniFile());
44  $connect = $db->connect(true);
45  if (!$connect) {
46  throw new Setup\UnachievableException(
47  "Database cannot be connected. Please check the credentials."
48  );
49  }
50  return $environment->withResource(Setup\Environment::RESOURCE_DATABASE, $db);
51  }
52 
56  public function isApplicable(Setup\Environment $environment) : bool
57  {
58  return true;
59  }
60 }
isApplicable(Setup\Environment $environment)
achieve(Setup\Environment $environment)
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
getPreconditions(Setup\Environment $environment)