ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilFileSystemComponentDataDirectoryCreatedObjective.php
Go to the documentation of this file.
1 <?php
2 
19 use ILIAS\Setup;
20 
21 class ilFileSystemComponentDataDirectoryCreatedObjective extends Setup\Objective\DirectoryCreatedObjective implements Setup\Objective
22 {
23  public const DATADIR = 1;
24  public const WEBDIR = 2;
25 
26  protected string $component_dir;
27 
28  protected int $base_location;
29 
30  public function __construct(
31  string $component_dir,
32  int $base_location = self::DATADIR
33  ) {
34  parent::__construct($component_dir);
35 
36  $this->component_dir = $component_dir;
37  $this->base_location = $base_location;
38  }
39 
40  public function getHash(): string
41  {
42  return hash("sha256", self::class . "::" . $this->component_dir . $this->base_location);
43  }
44 
45  protected function buildPath(Setup\Environment $environment): string
46  {
47  $ini = $environment->getResource(Setup\Environment::RESOURCE_ILIAS_INI);
48  $client_id = $environment->getResource(Setup\Environment::RESOURCE_CLIENT_ID);
49 
50  if ($this->base_location === self::DATADIR) {
51  $data_dir = $ini->readVariable('clients', 'datadir');
52  } elseif ($this->base_location === self::WEBDIR) {
53  $data_dir = dirname(__DIR__, 4) . "/data";
54  }
55  if (!isset($data_dir)) {
56  throw new LogicException('cannot determine base directory');
57  }
58 
59  $client_data_dir = $data_dir . '/' . $client_id;
60 
61  return $client_data_dir . '/' . $this->component_dir;
62  }
63 
67  public function getPreconditions(Setup\Environment $environment): array
68  {
69  // case if it is a fresh ILIAS installation
70  if ($environment->hasConfigFor("filesystem")) {
71  $config = $environment->getConfigFor("filesystem");
72  return [
74  ];
75  }
76 
77  // case if ILIAS is already installed
78  return [
80  ];
81  }
82 
83  public function achieve(Setup\Environment $environment): Setup\Environment
84  {
85  if (!$this->checkEnvironment($environment)) {
86  throw new Setup\UnachievableException("Environment is not ready for this objective");
87  }
88  $this->path = $this->buildPath($environment);
89  return parent::achieve($environment);
90  }
91 
95  public function isApplicable(Setup\Environment $environment): bool
96  {
97  if (!$this->checkEnvironment($environment)) {
98  return false;
99  }
100  $this->path = $this->buildPath($environment);
101  return parent::isApplicable($environment);
102  }
103 
104  private function checkEnvironment(Setup\Environment $environment): bool
105  {
106  if (null === $environment->getResource(Setup\Environment::RESOURCE_ILIAS_INI)) {
107  return false;
108  }
109  if (null === $environment->getResource(Setup\Environment::RESOURCE_CLIENT_ID)) {
110  return false;
111  }
112  return true;
113  }
114 }
__construct(VocabulariesInterface $vocabularies)
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:68
$ini
Definition: raiseError.php:4