ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDatabaseCreatedObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
22 
24 {
25  public function getHash(): string
26  {
27  return hash("sha256", implode("-", [
28  self::class,
29  $this->config->getHost(),
30  $this->config->getPort(),
31  $this->config->getDatabase()
32  ]));
33  }
34 
35  public function getLabel(): string
36  {
37  return "The database is created on the server.";
38  }
39 
40  public function isNotable(): bool
41  {
42  return true;
43  }
44 
48  public function getPreconditions(Setup\Environment $environment): array
49  {
50  return [
51  new \ilDatabaseServerIsConnectableObjective($this->config)
52  ];
53  }
54 
55  public function achieve(Setup\Environment $environment): Setup\Environment
56  {
57  $c = $this->config;
58  $db = \ilDBWrapperFactory::getWrapper($this->config->getType());
59  $db->initFromIniFile($c->toMockIniFile());
60 
61  if (!$db->createDatabase($c->getDatabase(), "utf8", $c->getCollation())) {
62  throw new Setup\UnachievableException(
63  "Database cannot be created."
64  );
65  }
66 
67  return $environment;
68  }
69 
73  public function isApplicable(Setup\Environment $environment): bool
74  {
75  $c = $this->config;
76  $db = \ilDBWrapperFactory::getWrapper($this->config->getType());
77  $db->initFromIniFile($c->toMockIniFile());
78 
79  $connect = $db->connect(true);
80  return !$connect;
81  }
82 }
isApplicable(Setup\Environment $environment)
achieve(Setup\Environment $environment)
$c
Definition: cli.php:38
ilDatabaseSetupConfig $config
getPreconditions(Setup\Environment $environment)
static getWrapper(string $a_type)
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