ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilFileSystemComponentDataDirectoryCreatedObjective.php
Go to the documentation of this file.
1<?php
2
23
25{
26 public const DATADIR = 1;
27 public const WEBDIR = 2;
28
29 protected string $component_dir;
30
31 public function __construct(
32 string $component_dir,
33 protected int $base_location = self::DATADIR
34 ) {
36
37 $this->component_dir = $component_dir;
38 }
39
40 #[\Override]
41 public function getHash(): string
42 {
43 return hash("sha256", self::class . "::" . $this->component_dir . $this->base_location);
44 }
45
46 protected function buildPath(Environment $environment): string
47 {
48 $ini = $environment->getResource(Environment::RESOURCE_ILIAS_INI);
49 $client_id = $environment->getResource(Environment::RESOURCE_CLIENT_ID);
50
51 if ($this->base_location === self::DATADIR) {
52 $data_dir = $ini->readVariable('clients', 'datadir');
53 } elseif ($this->base_location === self::WEBDIR) {
54 $data_dir = dirname(__DIR__, 5) . "/public/data";
55 }
56 if (!isset($data_dir)) {
57 throw new LogicException('cannot determine base directory');
58 }
59
60 $client_data_dir = $data_dir . '/' . $client_id;
61
62 return $client_data_dir . '/' . $this->component_dir;
63 }
64
68 #[\Override]
69 public function getPreconditions(Environment $environment): array
70 {
71 // case if it is a fresh ILIAS installation
72 if ($environment->hasConfigFor("filesystem")) {
73 $config = $environment->getConfigFor("filesystem");
74 return [
76 ];
77 }
78
79 // case if ILIAS is already installed
80 return [
82 ];
83 }
84
85 #[\Override]
86 public function achieve(Environment $environment): Environment
87 {
88 if (!$this->checkEnvironment($environment)) {
89 throw new UnachievableException("Environment is not ready for this objective");
90 }
91 $this->path = $this->buildPath($environment);
92 return parent::achieve($environment);
93 }
94
98 #[\Override]
99 public function isApplicable(Environment $environment): bool
100 {
101 if (!$this->checkEnvironment($environment)) {
102 return false;
103 }
104 $this->path = $this->buildPath($environment);
105 return parent::isApplicable($environment);
106 }
107
108 private function checkEnvironment(Environment $environment): bool
109 {
110 if (null === $environment->getResource(Environment::RESOURCE_ILIAS_INI)) {
111 return false;
112 }
113 return null !== $environment->getResource(Environment::RESOURCE_CLIENT_ID);
114 }
115}
Signals that some goal won't be achievable by actions of the system ever.
__construct(string $component_dir, protected int $base_location=self::DATADIR)
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
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ini
Definition: raiseError.php:20