ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
DeliveryMethodObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28
33{
34 public const SETTINGS = 'delivery_method';
35 public const SETTINGS_EXTERNAL_DATA_DIR = 'ext_data_dir';
36 public const XSENDFILE = 'xsendfile';
37 public const XACCEL = 'xaccel';
38 public const PHP = 'php';
39
40 private ?string $ext_data_dir = null;
41 private ?IOWrapper $io = null;
42
43 public function getArtifactName(): string
44 {
45 return 'delivery_method';
46 }
47
48 public function getPreconditions(Environment $environment): array
49 {
50 return array_merge(
51 parent::getPreconditions($environment),
52 [
54 ]
55 );
56 }
57
58 public function achieve(Environment $environment): Environment
59 {
62 if ($ini instanceof \ilIniFile && $ini->variableExists('clients', 'datadir')) {
63 $this->ext_data_dir = $ini->readVariable('clients', 'datadir');
64 } else {
65 throw new UnachievableException(
66 'Could not determine external data directory from ILIAS ini file'
67 );
68 }
69
71 if ($io instanceof IOWrapper) {
72 $this->io = $io;
73 }
74
75 return parent::achieve($environment);
76 }
77
78 public function build(): Artifact
79 {
80 $delivery_method = self::PHP;
81
82 if (file_exists(self::PATH())) {
83 $settings = (@include self::PATH()) ?? [];
84 $delivery_method = $settings[self::SETTINGS] ?? self::PHP;
85 }
86
87 if ($this->isModXSendFileLoaded()) {
88 $delivery_method = self::XSENDFILE;
89 }
90
91 return new ArrayArtifact(array_filter([
92 self::SETTINGS => $delivery_method,
93 self::SETTINGS_EXTERNAL_DATA_DIR => $this->ext_data_dir
94 ]));
95 }
96
97 private function isModXSendFileLoaded(): bool
98 {
99 if (\function_exists('apache_get_modules') && \in_array('mod_xsendfile', apache_get_modules(), true)) {
100 return true;
101 }
102
103 try {
104 $command_exists = shell_exec('which apache2ctl');
105 if (empty($command_exists)) {
106 return false;
107 }
108
109 $loaded_modules = array_map(
110 static fn(string $module): string => explode(' ', trim($module))[0] ?? '',
111 explode("\n", shell_exec('apache2ctl -M 2>/dev/null') ?? '')
112 );
113 } catch (\Throwable $e) {
114 $this->io?->error($e->getMessage());
115 $this->io?->error($e->getTraceAsString());
116 $loaded_modules = [];
117 }
118
119 return \in_array('xsendfile_module', $loaded_modules, true);
120 }
121
122 #[\Override]
123 public function isApplicable(Environment $environment): bool
124 {
125 return true;
126 }
127}
achieve(Environment $environment)
Objectives can be achieved.
isApplicable(Environment $environment)
Get to know whether the objective is applicable.
getPreconditions(Environment $environment)
Objectives might depend on other objectives.
An array as an artifact.
Wrapper around symfonies input and output facilities to provide just the functionality required for t...
Definition: IOWrapper.php:33
Signals that some goal won't be achievable by actions of the system ever.
INIFile Parser Early access in init proceess! Avoid further dependencies like logging or other servic...
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:28
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.