ILIAS  release_8 Revision v8.24
class.ilChatroomConfigFileHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29{
30 private const CHATROOM_DATA_DIR = '/chatroom/';
31 private const CHATROOM_CLIENT_CONFIG_FILENAME = 'client.cfg';
32 private const CHATROOM_SERVER_CONFIG_FILENAME = 'server.cfg';
33
39 public function createClientConfigFile(array $settings): void
40 {
41 $content = $this->getClientFileContent($settings);
42 $this->writeDataToFile($content, self::CHATROOM_CLIENT_CONFIG_FILENAME);
43 }
44
50 protected function getClientFileContent(array $settings): string
51 {
52 global $DIC;
53
54 // Dirty configuration swap: Ilias differentiates between InnoDB and MyISAM.
55 // MyISAM is configured as mysql, InnoDB as innodb.
56 // The client config file only needs information about driver not engine
57 $type = $DIC['ilClientIniFile']->readVariable('db', 'type');
58 if (in_array($type, [
61 ''
62 ], true)) {
63 $type = 'mysql';
64 }
65
66 $settings['database'] = [
67 'type' => $type,
68 'host' => $DIC['ilClientIniFile']->readVariable('db', 'host'),
69 'port' => (int) $DIC['ilClientIniFile']->readVariable('db', 'port'),
70 'name' => $DIC['ilClientIniFile']->readVariable('db', 'name'),
71 'user' => $DIC['ilClientIniFile']->readVariable('db', 'user'),
72 'pass' => $DIC['ilClientIniFile']->readVariable('db', 'pass')
73 ];
74
75 return json_encode($settings, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
76 }
77
84 protected function writeDataToFile(string $content, string $filename): void
85 {
87 $handle = fopen($path . $filename, 'wb');
88
89 if (!fwrite($handle, $content)) {
90 throw new RuntimeException('Cannot write to file');
91 }
92
93 fclose($handle);
94 }
95
101 protected function createDataDirIfNotExists(): string
102 {
104
105 if (!is_dir($path) && !ilFileUtils::makeDir($path)) {
106 throw new RuntimeException('Directory cannot be created');
107 }
108
109 return $path;
110 }
111
117 public function createServerConfigFile(array $settings): void
118 {
119 $content = $this->getServerFileContent($settings);
120 $this->writeDataToFile($content, self::CHATROOM_SERVER_CONFIG_FILENAME);
121 }
122
128 protected function getServerFileContent(array $settings): string
129 {
130 unset($settings['ilias_proxy'], $settings['client_proxy'], $settings['ilias_url'], $settings['client_url']);
131
132 return json_encode($settings, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
133 }
134}
$filename
Definition: buildRTE.php:78
readVariable(string $a_group, string $a_var_name)
reads a single variable from a group
writeDataToFile(string $content, string $filename)
Writes $content to file named by $filename.
createDataDirIfNotExists()
Creates a data directory for configuration files, if the directory does not already exists.
getServerFileContent(array $settings)
Get the server config file contetn as json encoded string.
createClientConfigFile(array $settings)
Creates a client config file and saves it to the chatroom data directory.
getClientFileContent(array $settings)
Get the client config file content as json encoded string.
createServerConfigFile(array $settings)
Creates a server config file and saves it to the chatroom data directory.
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static getDataDir()
get data directory (outside webspace)
global $DIC
Definition: feed.php:28
$path
Definition: ltiservices.php:32
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
$type