ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilFileSystemDirectoriesCreatedObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
23 
24 class ilFileSystemDirectoriesCreatedObjective implements Setup\Objective
25 {
26  protected \ilFileSystemSetupConfig $config;
27 
28  public function __construct(
30  ) {
31  $this->config = $config;
32  }
33 
34  public function getHash(): string
35  {
36  return hash("sha256", self::class);
37  }
38 
39  public function getLabel(): string
40  {
41  return "ILIAS directories are created";
42  }
43 
44  public function isNotable(): bool
45  {
46  return true;
47  }
48 
52  public function getPreconditions(Setup\Environment $environment): array
53  {
54  $client_id = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_ID);
55  $data_dir = $this->config->getDataDir();
56  $web_dir = dirname(__DIR__, 5) . "/public/data";
57  $root = dirname(__DIR__, 5);
58 
59  $client_data_dir = $data_dir . '/' . $client_id;
60  $client_web_dir = $web_dir . '/' . $client_id;
61 
62  $web_dir_objective = new Setup\Objective\DirectoryCreatedObjective($client_web_dir);
63  $data_dir_objective = new Setup\Objective\DirectoryCreatedObjective($client_data_dir);
64  $customizing_dir_objective = new Setup\Objective\NullObjective();
65 
66  if ($environment->hasConfigFor(Setup\CLI\InstallCommand::IMPORT)) {
67  $tmp_dir = $environment->getConfigFor("tmp_dir");
68 
69  $web_dir_objective = new ObjectiveWithPreconditions(
71  $web_dir
72  ),
74  $tmp_dir . DIRECTORY_SEPARATOR . "web_data",
75  $web_dir,
76  false,
77  true
78  )
79  );
80  $data_dir_objective = new ObjectiveWithPreconditions(
82  $data_dir
83  ),
85  $tmp_dir . DIRECTORY_SEPARATOR . "data",
86  $data_dir,
87  false,
88  true
89  )
90  );
91  $customizing_dir_objective = new ilFileSystemDirectoryCopiedRecursivelyObjective(
92  $tmp_dir . DIRECTORY_SEPARATOR . "Customizing",
93  $root . "/public/Customizing",
94  false,
95  true
96  );
97  }
98 
99  return [
101  new Setup\Objective\DirectoryCreatedObjective($data_dir),
102  new Setup\Objective\DirectoryCreatedObjective($web_dir),
103  $web_dir_objective,
104  $data_dir_objective,
105  $customizing_dir_objective
106  ];
107  }
108 
109  public function achieve(Setup\Environment $environment): Setup\Environment
110  {
111  $ini = $environment->getResource(Setup\Environment::RESOURCE_ILIAS_INI);
112 
113  $ini->setVariable("clients", "datadir", $this->config->getDataDir());
114  if (!$ini->write()) {
115  throw new Setup\UnachievableException("Could not write ilias.ini.php");
116  }
117 
118  if ($environment->hasConfigFor("tmp_dir")) {
119  $tmp_dir = $environment->getConfigFor("tmp_dir");
120  if (!is_null($tmp_dir)) {
121  $this->deleteRecursive($tmp_dir, true);
122  }
123  }
124 
125  return $environment;
126  }
127 
131  public function isApplicable(Setup\Environment $environment): bool
132  {
133  if ($environment->hasConfigFor(Setup\CLI\InstallCommand::IMPORT)) {
134  return true;
135  }
136 
137  $ini = $environment->getResource(Setup\Environment::RESOURCE_ILIAS_INI);
138 
139  return $ini->readVariable("clients", "datadir") !== $this->config->getDataDir();
140  }
141 
142  protected function deleteRecursive(string $path, bool $delete_base_dir = false): void
143  {
144  if (is_file($path)) {
145  unlink($path);
146  return;
147  }
148 
149  $files = new RecursiveIteratorIterator(
150  new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS),
151  RecursiveIteratorIterator::CHILD_FIRST
152  );
153 
154  foreach ($files as $file_info) {
155  if ($file_info->isDir()) {
156  rmdir($file_info->getRealPath());
157  continue;
158  }
159  unlink($file_info->getRealPath());
160  }
161 
162  if ($delete_base_dir) {
163  rmdir($path);
164  }
165  }
166 }
$path
Definition: ltiservices.php:30
A wrapper around an objective that adds some preconditions.
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
$client_id
Definition: ltiauth.php:67
$ini
Definition: raiseError.php:4