ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ClientIdReadObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Setup\Objective;
22
23use ILIAS\Setup;
24
33{
39 public function getHash(): string
40 {
41 return hash("sha256", self::class);
42 }
43
47 public function getLabel(): string
48 {
49 return "Read client-id from data-directory.";
50 }
51
57 public function isNotable(): bool
58 {
59 return false;
60 }
61
65 public function getPreconditions(Setup\Environment $environment): array
66 {
67 return [];
68 }
69
73 public function achieve(Setup\Environment $environment): Setup\Environment
74 {
75 $dir = $this->getDataDirectoryPath();
76 $candidates = array_filter(
77 $this->scanDirectory($dir),
78 function ($c) use ($dir): bool {
79 if ($c === "." || $c === "..") {
80 return false;
81 }
82 return $this->isDirectory($dir . "/" . $c);
83 }
84 );
85
86 if (count($candidates) === 0) {
88 "There are no directories in the webdata-dir at '$dir'. " .
89 "Probably ILIAS is not installed."
90 );
91 }
92
93 if (count($candidates) !== 1) {
94 $ilias_version = ILIAS_VERSION_NUMERIC;
95
97 "There is more than one directory in the webdata-dir at '$dir'. " .
98 "Probably this is an ILIAS installation that uses clients. Clients " .
99 "are not supported anymore since ILIAS $ilias_version " .
100 "(see: https://docu.ilias.de/goto.php?target=wiki_1357_Setup_-_Abandon_Multi_Client)"
101 );
102 }
103
104 $client_id = array_shift($candidates);
105 return $environment->withResource(Setup\Environment::RESOURCE_CLIENT_ID, $client_id);
106 }
107
108 protected function getDataDirectoryPath(): string
109 {
110 return dirname(__DIR__, 5) . "/public/data";
111 }
112
113 protected function scanDirectory(string $path): array
114 {
115 if (!$this->isDirectory($path)) {
116 return [];
117 }
118
119 return scandir($path);
120 }
121
122 protected function isDirectory(string $path): bool
123 {
124 return is_dir($path);
125 }
126
130 public function isApplicable(Setup\Environment $environment): bool
131 {
132 return $environment->getResource(Setup\Environment::RESOURCE_CLIENT_ID) === null;
133 }
134}
Read the client id of the installation from the data directory.
achieve(Setup\Environment $environment)
@inheritdocs
getPreconditions(Setup\Environment $environment)
@inheritdocs
isApplicable(Setup\Environment $environment)
@inheritDoc
Signals that some goal won't be achievable by actions of the system ever.
string $client_id
Definition: class.ilias.php:36
$c
Definition: deliver.php:25
const ILIAS_VERSION_NUMERIC
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31
$path
Definition: ltiservices.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...