ILIAS  release_7 Revision v7.30-3-g800a261c036
ClientIdReadObjective.php
Go to the documentation of this file.
1 <?php
2 
3 
4 /* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de>, Fabian Schmid <fs@studer-raimann.ch> Extended GPL, see docs/LICENSE */
5 
6 namespace ILIAS\Setup\Objective;
7 
8 use ILIAS\Setup;
9 
18 {
24  public function getHash() : string
25  {
26  return hash("sha256", self::class);
27  }
28 
32  public function getLabel() : string
33  {
34  return "Read client-id from data-directory.";
35  }
36 
42  public function isNotable() : bool
43  {
44  return false;
45  }
46 
50  public function getPreconditions(Setup\Environment $environment) : array
51  {
52  return [];
53  }
54 
58  public function achieve(Setup\Environment $environment) : Setup\Environment
59  {
60  $dir = $this->getDataDirectoryPath();
61  $candidates = array_filter(
62  $this->scanDirectory($dir),
63  function ($c) use ($dir) {
64  if ($c == "." || $c == "..") {
65  return false;
66  }
67  return $this->isDirectory($dir . "/" . $c);
68  }
69  );
70 
71  if (count($candidates) == 0) {
73  "There are no directories in the webdata-dir at '$dir'. " .
74  "Probably ILIAS is not installed."
75  );
76  }
77 
78  if (count($candidates) != 1) {
79  $ilias_version = ILIAS_VERSION_NUMERIC;
80 
82  "There is more than one directory in the webdata-dir at '$dir'. " .
83  "Probably this is an ILIAS installation that uses clients. Clients " .
84  "are not supported anymore since ILIAS $ilias_version " .
85  "(see: https://docu.ilias.de/goto.php?target=wiki_1357_Setup_-_Abandon_Multi_Client)"
86  );
87  }
88 
89  $client_id = array_shift($candidates);
90  return $environment->withResource(Setup\Environment::RESOURCE_CLIENT_ID, $client_id);
91  }
92 
93  protected function getDataDirectoryPath() : string
94  {
95  return dirname(__DIR__, 3) . "/data";
96  }
97 
98  protected function scanDirectory(string $path) : array
99  {
100  return scandir($path);
101  }
102 
103  protected function isDirectory(string $path) : bool
104  {
105  return is_dir($path);
106  }
107 
111  public function isApplicable(Setup\Environment $environment) : bool
112  {
113  return $environment->getResource(Setup\Environment::RESOURCE_CLIENT_ID) === null;
114  }
115 }
getPreconditions(Setup\Environment $environment)
An objective is a desired state of the system that is supposed to be created by the setup...
Definition: Objective.php:14
$c
Definition: cli.php:37
const ILIAS_VERSION_NUMERIC
$client_id
Definition: webdav.php:17
Signals that some goal won&#39;t be achievable by actions of the system ever.
Read the client id of the installation from the data directory.
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