ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilFileSystemComponentDataDirectoryCreatedObjective.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2020 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
7
9{
10 const DATADIR = 1;
11 const WEBDIR = 2;
13
17 protected $component_dir;
18
22 protected $base_location;
23
27 protected $permissions;
28
29 public function __construct(
30 string $component_dir,
31 int $base_location = self::DATADIR,
32 int $permissions = self::DEFAULT_DIRECTORY_PERMISSIONS
33 ) {
34 $this->component_dir = $component_dir;
35 $this->base_location = $base_location;
36 $this->permissions = $permissions;
37 }
38
42 public function getHash() : string
43 {
44 return hash("sha256", self::class . "::" . $this->component_dir . (string) $this->base_location);
45 }
46
50 public function getLabel() : string
51 {
52 $dir = '';
53 if ($this->base_location === self::DATADIR) {
54 $dir = 'data';
55 }
56 if ($this->base_location === self::WEBDIR) {
57 $dir = 'web';
58 }
59
60 return "Create $dir directory in component directory $this->component_dir";
61 }
62
66 public function isNotable() : bool
67 {
68 return true;
69 }
70
71 public function getPreconditions(Setup\Environment $environment) : array
72 {
73 $config = $environment->getConfigFor("filesystem");
74 return [
76 ];
77 }
78
79 public function achieve(Setup\Environment $environment) : Setup\Environment
80 {
81 $path = $this->buildPath($environment);
82
83 if (!file_exists($path)) {
84 mkdir($path, $this->permissions);
85 }
86 if (!is_dir($path)) {
87 throw new UnachievableException(
88 "Could not create directory '{$path}'"
89 );
90 }
91 return $environment;
92 }
93
94 protected function buildPath(Setup\Environment $environment) : string
95 {
96 $common_config = $environment->getConfigFor("common");
97 $fs_config = $environment->getConfigFor("filesystem");
98
99 if ($this->base_location === self::DATADIR) {
100 $data_dir = $fs_config->getDataDir();
101 }
102
103 if ($this->base_location === self::WEBDIR) {
104 $data_dir = $fs_config->getWebDir();
105 }
106
107 $client_data_dir = $data_dir . '/' . $common_config->getClientId();
108 $new_dir = $client_data_dir . '/' . $this->component_dir;
109
110 return $new_dir;
111 }
112}
An exception for terminatinating execution or to throw for unit testing.
Signals that some goal won't be achievable by actions of the system ever.
__construct(string $component_dir, int $base_location=self::DATADIR, int $permissions=self::DEFAULT_DIRECTORY_PERMISSIONS)
An environment holds resources to be used in the setup process.
Definition: Environment.php:12
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:15
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68