ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilDatabaseCreatedObjective.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 is created 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  return [
32  new \ilDatabaseServerIsConnectableObjective($this->config)
33  ];
34  }
35 
36  public function achieve(Setup\Environment $environment) : Setup\Environment
37  {
38  $c = $this->config;
39  $db = \ilDBWrapperFactory::getWrapper($this->config->getType());
40  $db->initFromIniFile($c->toMockIniFile());
41 
42  $connect = $db->connect(true);
43  if ($connect) {
44  // Database seems to exist already.
45  return $environment;
46  }
47 
48  if (!$db->createDatabase($c->getDatabase(), "utf8", $c->getCollation())) {
49  throw new Setup\UnachievableException(
50  "Database cannot be created."
51  );
52  }
53 
54  return $environment;
55  }
56 }
achieve(Setup\Environment $environment)
getPreconditions(Setup\Environment $environment)
An environment holds resources to be used in the setup process.
Definition: Environment.php:11