ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  {
35  global $DIC;
36 
37  // Dirty configuration swap: Ilias differentiates between InnoDB and MyISAM.
38  // MyISAM is configured as mysql, InnoDB as innodb.
39  // The client config file only needs information about driver not engine
40  $type = $a_type = $DIC['ilClientIniFile']->readVariable('db', 'type');
41  if (in_array($type, array(
46  ''
47  ))) {
48  $type = 'mysql';
49  }
50 
51  $settings['database'] = array(
52  'type' => $type,
53  'host' => $DIC['ilClientIniFile']->readVariable('db', 'host'),
54  'port' => (int) $DIC['ilClientIniFile']->readVariable('db', 'port'),
55  'name' => $DIC['ilClientIniFile']->readVariable('db', 'name'),
56  'user' => $DIC['ilClientIniFile']->readVariable('db', 'user'),
57  'pass' => $DIC['ilClientIniFile']->readVariable('db', 'pass')
58  );
59 
60  return json_encode($settings, JSON_PRETTY_PRINT);
61  }
62 
69  protected function writeDataToFile($content, $filename)
70  {
72  $handle = fopen($path . $filename, 'w');
73 
74  if (!fwrite($handle, $content)) {
75  throw new Exception('Cannot write to file');
76  }
77 
78  fclose($handle);
79  }
80 
86  protected function createDataDirIfNotExists()
87  {
88  $path = ilUtil::getDataDir() . self::CHATROOM_DATA_DIR;
89 
90  if (!file_exists($path)) {
91  if (!ilUtil::makeDir($path)) {
92  throw new Exception('Directory cannot be created');
93  }
94  }
95 
96  return $path;
97  }
98 
104  public function createServerConfigFile(array $settings)
105  {
106  $content = $this->getServerFileContent($settings);
107  $this->writeDataToFile($content, self::CHATROOM_SERVER_CONFIG_FILENAME);
108  }
109 
115  protected function getServerFileContent(array $settings)
116  {
117  unset($settings['ilias_proxy']);
118  unset($settings['client_proxy']);
119  unset($settings['ilias_url']);
120  unset($settings['client_url']);
121 
122  return json_encode($settings, JSON_PRETTY_PRINT);
123  }
124 }
getServerFileContent(array $settings)
Get the server config file contetn as json encoded string.
$path
Definition: aliased.php:25
$type
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92
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...
$filename
Definition: buildRTE.php:89
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)
getClientFileContent(array $settings)
Get the client config file content as json encoded string.
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.