ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilFileSystemDirectoriesCreatedObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28
30{
31 public function __construct(protected \ilFileSystemSetupConfig $config)
32 {
33 }
34
35 public function getHash(): string
36 {
37 return hash("sha256", self::class);
38 }
39
40 public function getLabel(): string
41 {
42 return "ILIAS directories are created";
43 }
44
45 public function isNotable(): bool
46 {
47 return true;
48 }
49
53 public function getPreconditions(Environment $environment): array
54 {
55 $client_id = $environment->getResource(Environment::RESOURCE_CLIENT_ID);
56 $data_dir = $this->config->getDataDir();
57 $web_dir = dirname(__DIR__, 5) . "/public/data";
58 $root = dirname(__DIR__, 5);
59
60 $client_data_dir = $data_dir . '/' . $client_id;
61 $client_web_dir = $web_dir . '/' . $client_id;
62
63 $web_dir_objective = new DirectoryCreatedObjective($client_web_dir);
64 $data_dir_objective = new DirectoryCreatedObjective($client_data_dir);
65 $customizing_dir_objective = new NullObjective();
66
67 if ($environment->hasConfigFor(InstallCommand::IMPORT)) {
68 $tmp_dir = $environment->getConfigFor("tmp_dir");
69
70 $web_dir_objective = new ObjectiveWithPreconditions(
72 $web_dir
73 ),
75 $tmp_dir . DIRECTORY_SEPARATOR . "web_data",
76 $web_dir,
77 false,
78 true
79 )
80 );
81 $data_dir_objective = new ObjectiveWithPreconditions(
84 ),
86 $tmp_dir . DIRECTORY_SEPARATOR . "data",
88 false,
89 true
90 )
91 );
92 $customizing_dir_objective = new ilFileSystemDirectoryCopiedRecursivelyObjective(
93 $tmp_dir . DIRECTORY_SEPARATOR . "Customizing",
94 $root . "/public/Customizing",
95 false,
96 true
97 );
98 }
99
100 return [
103 new DirectoryCreatedObjective($web_dir),
104 $web_dir_objective,
105 $data_dir_objective,
106 $customizing_dir_objective
107 ];
108 }
109
110 public function achieve(Environment $environment): Environment
111 {
112 $ini = $environment->getResource(Environment::RESOURCE_ILIAS_INI);
113
114 $ini->setVariable("clients", "datadir", $this->config->getDataDir());
115 if (!$ini->write()) {
116 throw new UnachievableException("Could not write ilias.ini.php");
117 }
118
119 if ($environment->hasConfigFor("tmp_dir")) {
120 $tmp_dir = $environment->getConfigFor("tmp_dir");
121 if (!is_null($tmp_dir)) {
122 $this->deleteRecursive($tmp_dir, true);
123 }
124 }
125
126 return $environment;
127 }
128
132 public function isApplicable(Environment $environment): bool
133 {
134 if ($environment->hasConfigFor(InstallCommand::IMPORT)) {
135 return true;
136 }
137
138 $ini = $environment->getResource(Environment::RESOURCE_ILIAS_INI);
139
140 return $ini->readVariable("clients", "datadir") !== $this->config->getDataDir();
141 }
142
143 protected function deleteRecursive(string $path, bool $delete_base_dir = false): void
144 {
145 if (is_file($path)) {
146 unlink($path);
147 return;
148 }
149
150 $files = new RecursiveIteratorIterator(
151 new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS),
152 RecursiveIteratorIterator::CHILD_FIRST
153 );
154
155 foreach ($files as $file_info) {
156 if ($file_info->isDir()) {
157 rmdir($file_info->getRealPath());
158 continue;
159 }
160 unlink($file_info->getRealPath());
161 }
162
163 if ($delete_base_dir) {
164 rmdir($path);
165 }
166 }
167}
A non-objective, nothing to do to achieve it...
A wrapper around an objective that adds some preconditions.
Signals that some goal won't be achievable by actions of the system ever.
isNotable()
Get to know if this is an interesting objective for a human.
achieve(Environment $environment)
Objectives can be achieved.
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
hasConfigFor(string $component)
getConfigFor(string $component)
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31
$client_id
Definition: ltiauth.php:67
$path
Definition: ltiservices.php:30
$ini
Definition: raiseError.php:20