ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilChatroomConfigFileHandler.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  const CHATROOM_DATA_DIR = '/chatroom/';
14  const CHATROOM_CLIENT_CONFIG_FILENAME = 'client.cfg';
15  const CHATROOM_SERVER_CONFIG_FILENAME = 'server.cfg';
16 
22  public function createClientConfigFile(array $settings)
23  {
24  $content = $this->getClientFileContent($settings);
25  $this->writeDataToFile($content, self::CHATROOM_CLIENT_CONFIG_FILENAME);
26  }
27 
33  protected function getClientFileContent(array $settings)
34  {
36  global $ilClientIniFile;
37 
38  // Dirty configuration swap: Ilias differentiates between InnoDB and MyISAM.
39  // MyISAM is configured as mysql, InnoDB as innodb.
40  // The client config file only needs information about driver not engine
41  $type = $a_type = $ilClientIniFile->readVariable('db', 'type');
42  if(in_array($type, array(
47  ''
48  )))
49  {
50  $type = 'mysql';
51  }
52 
53  $settings['database'] = array(
54  'type' => $type,
55  'host' => $ilClientIniFile->readVariable('db', 'host'),
56  'port' => (int)$ilClientIniFile->readVariable('db', 'port'),
57  'name' => $ilClientIniFile->readVariable('db', 'name'),
58  'user' => $ilClientIniFile->readVariable('db', 'user'),
59  'pass' => $ilClientIniFile->readVariable('db', 'pass')
60  );
61 
62  return json_encode($settings, JSON_PRETTY_PRINT);
63  }
64 
71  protected function writeDataToFile($content, $filename)
72  {
74  $handle = fopen($path . $filename, 'w');
75 
76  if(!fwrite($handle, $content))
77  {
78  throw new Exception('Cannot write to file');
79  }
80 
81  fclose($handle);
82  }
83 
89  protected function createDataDirIfNotExists()
90  {
91  $path = ilUtil::getDataDir() . self::CHATROOM_DATA_DIR;
92 
93  if(!file_exists($path))
94  {
96  {
97  throw new Exception('Directory cannot be created');
98  }
99  }
100 
101  return $path;
102  }
103 
109  public function createServerConfigFile(array $settings)
110  {
111  $content = $this->getServerFileContent($settings);
112  $this->writeDataToFile($content, self::CHATROOM_SERVER_CONFIG_FILENAME);
113  }
114 
120  protected function getServerFileContent(array $settings)
121  {
122  unset($settings['ilias_proxy']);
123  unset($settings['client_proxy']);
124  unset($settings['ilias_url']);
125  unset($settings['client_url']);
126 
127  return json_encode($settings, JSON_PRETTY_PRINT);
128  }
129 }
getServerFileContent(array $settings)
Get the server config file contetn as json encoded string.
$path
Definition: aliased.php:25
$a_type
Definition: workflow.php:93
writeDataToFile($content, $filename)
Writes $content to file named by $filename.
createDataDirIfNotExists()
Creates a data directory for configuration files, if the directory does not already exists...
Create styles array
The data for the language used.
static makeDir($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)
createClientConfigFile(array $settings)
Creates a client config file and saves it to the chatroom data directory.
createServerConfigFile(array $settings)
Creates a server config file and saves it to the chatroom data directory.