ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilIniFilesPopulatedObjective.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 ilIniFilesPopulatedObjective 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 ilias.ini.php and client.ini.php are populated.";
17  }
18 
19  public function isNotable() : bool
20  {
21  return true;
22  }
23 
24  public function getPreconditions(Setup\Environment $environment) : array
25  {
26  $client_id = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_ID);
27  if ($client_id === null) {
28  throw new \LogicException(
29  "Expected a client_id in the environment."
30  );
31  }
32  $client_dir = $this->getClientDir($client_id);
33 
34  // TODO: This shows an unfortunate connection between the webdir and the
35  // client.ini.php. Why does the client.ini reside in the webdir? If we
36  // remove the client-feature, the client-ini will go away...
37  return [
38  new Setup\Objective\DirectoryCreatedObjective(dirname(__DIR__, 2) . "/data"),
39  new Setup\Objective\DirectoryCreatedObjective($client_dir),
40  new Setup\Condition\CanCreateFilesInDirectoryCondition($client_dir),
41  new Setup\Condition\CanCreateFilesInDirectoryCondition(dirname(__DIR__, 2))
42  ];
43  }
44 
45  public function achieve(Setup\Environment $environment) : Setup\Environment
46  {
47  $client_id = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_ID);
48 
49  $path = $this->getILIASIniPath();
50  if (!file_exists($path)) {
51  $ini = new ilIniFile($path);
52  $ini->GROUPS = parse_ini_file(__DIR__ . "/../ilias.master.ini.php", true);
53  $ini->write();
54  $environment = $environment
55  ->withResource(Setup\Environment::RESOURCE_ILIAS_INI, $ini);
56  }
57 
58  $path = $this->getClientIniPath($client_id);
59  if (!file_exists($path)) {
60  $client_ini = new ilIniFile($path);
61  $client_ini->GROUPS = parse_ini_file(__DIR__ . "/../client.master.ini.php", true);
62  $client_ini->write();
63  $environment = $environment
64  ->withResource(Setup\Environment::RESOURCE_CLIENT_INI, $client_ini);
65  }
66 
67  return $environment;
68  }
69 
73  public function isApplicable(Setup\Environment $environment) : bool
74  {
75  $client_id = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_ID);
76 
77  return !file_exists($this->getILIASIniPath())
78  || !file_exists($this->getClientIniPath($client_id));
79  }
80 
81  protected function getClientDir(string $client_id) : string
82  {
83  return dirname(__DIR__, 2) . "/data/" . $client_id;
84  }
85 
86  protected function getClientIniPath(string $client_id) : string
87  {
88  return $this->getClientDir($client_id) . "/client.ini.php";
89  }
90 
91  protected function getILIASIniPath() : string
92  {
93  return dirname(__DIR__, 2) . "/ilias.ini.php";
94  }
95 }
getPreconditions(Setup\Environment $environment)
$client_id
Definition: webdav.php:17
isApplicable(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
INIFile Parser.
$ini
Definition: raiseError.php:4