Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
install.php
1 <?php
2 /**
3  *
4  */
5 
6 define('CLIENT_CONFIG_LOCATION', '../custom/runtime/client_main.php');
7 
8 $settings = array();
9 
10 require '../framework/yii.php';
11 require '../framework/db/CDbConnection.php';
12 
13 $ClientMainConfiguration = include '../custom/config/client_main.php';
14 
15 /* This should be done by the shell-installer
16 $dirs = array('/common/runtime', '/custom/runtime', '/tests/runtime', '/frontend/runtime', '/frontend/www/assets');
17 $notWritable = array();
18 foreach ($dirs as $d) {
19  $rd = realpath('../' . $d);
20  if (is_writable($rd)) {
21  continue;
22  } else {
23  $notWritable[] = $rd;
24  }
25 }
26 if (!empty($notWritable)) {
27  write('Below directories should be writable');
28  write(implode($notWritable, "\n"));
29  if (prompt('Change directory access?')) {
30  foreach ($notWritable as $d) {
31  if (@chmod($d, 755)) {
32  write("$d now is writable");
33  } else {
34  write('You don`t have access for changing folder access mode. Run script as root');
35  }
36  }
37  }
38 }
39 */
40 
41 $settings['components']['db'] = array();
42 
43 if (prompt('Do you use a database?')) {
44  sql:
45  do {
46  $n = ask("What database:\n1) MySQL \n2) Postgres \n3) Oracle");
47  } while (!in_array($n, array(1, 2, 3)));
48  $host = ask('Host (i.e. localhost):');
49  $port = ask('Port (i.e. 3306, you can also leave it blank):');
50  $database = ask('Database name:');
51  $settings['components']['db']['username'] = ask('Username:');
52  $settings['components']['db']['password'] = ask('Password:');
53  switch ($n) {
54  case 1:
55  $settings['components']['db']['connectionString'] = "mysql:host=$host" . ($port ? ":$port" : '') . ";dbname=$database";
56  break;
57  case 2:
58  $settings['components']['db']['connectionString'] = "pgsql:host=$host;" . ($port ? "port=$port;" : '') . "dbname=$database";
59  break;
60  case 3:
61  $settings['components']['db']['connectionString'] = "oci:dbname=$host" . ($port ? ":$port" : '') . "/$database;charset=UTF8";
62  break;
63  }
64  $connection = new CDbConnection($settings['components']['db']['connectionString'], $settings['components']['db']['username'], $settings['components']['db']['password']);
65  try {
66  $connection->setActive(true);
67  write('Connection success!');
68  } catch (Exception $e) {
69  write($e->getMessage());
70  if (yes(ask('Try again?'))) {
71  goto sql;
72  } else {
73  write("You can configure it manually. In client_main.php set 'db' component settings. ");
74  ask('');
75  }
76  }
77 }
78 
79 //contentSource
80 if (prompt('Will you use Dynamic Content Renderer (DCR) (recommended) (you must have a Gentics Content Connector running)?')) {
81  $sett = &$settings['modules']['contentSource']['sourceSettings']['DynamicContentSource'];
82  $sett['cacheFolder'] = ask('Location of your cache folder (i.e. /var/www/DCR/), must be writeable for webserver-user:');
83  $sett['usePersonalisation'] = false;
84  $sett['personalisationFields'] = array();
85  if (prompt('Will you use personalisation?')) {
86  $sett['usePersonalisation'] = true;
87  $personalisationFields = ask('Enter personalisation attributes (multivalue) requested by Gentics Content Connector - must be defined in CMS (Tagmap) (i.e. permissions):');
88  $sett['personalisationFields'] = array_map('trim', explode(',', $personalisationFields));
89  }
90  $settings['modules']['contentSource']['sourceClass'] = 'DynamicContentSource';
91 }
92 
93 if (prompt('Will you use File System Content Renderer (FSCR) alternatively?')) {
94  $sett = &$settings['modules']['contentSource']['sourceSettings']['FileSystemContentSource'];
95  $sett['contentFolder'] = ask('Location of your published CMS files (i.e. /var/www/FSCR/):');
96  $sett['usePersonalisation'] = false;
97  $sett['personalisationFields'] = array();
98  if (prompt('Will you use personalisation?')) {
99  $sett['usePersonalisation'] = true;
100  $personalisationFields = ask('Enter personalisation attributes (multivalue) requested by Gentics Content Connector - must be defined in CMS (Tagmap) (i.e. permissions):');
101  if (!empty($personalisationFields)) {
102  $sett['personalisationFields'] = array_map('trim', explode(',', $personalisationFields));
103  }
104  }
105  $settings['modules']['contentSource']['sourceClass'] = 'FileSystemContentSource';
106 }
107 
108 //$settings['modules']['contentSource']['homePage'] = ask('Portal startpage, eg. /Content.Node/index.html:');
109 
110 //memcached
111 if (prompt('Will you use memcached as caching system (recommended, is necessary for session)?')) {
112  $settings['components']['cache']['servers']['server1'] = array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 60);
113 }
114 
115 //eauth
116 $settings['components']['eauth']['services']['standard'] = array(
117  'title' => 'Use default login with username and password?'
118 );
119 if (prompt('Google authentication?')) {
120  $settings['components']['eauth']['services']['google'] = array(
121  'class' => 'site.common.modules.user.services.GoogleService',
122  'title' => 'Use login with Google Open ID?'
123  );
124 }
125 
126 if (prompt('Facebook Authentication (you need a Facebook App)?')) {
127  $settings['components']['eauth']['services']['facebook'] = array(
128  'title' => 'Use login with Facebook?',
129  'class' => 'site.common.modules.user.services.FacebookService',
130  );
131 }
132 
133 file_put_contents(CLIENT_CONFIG_LOCATION, '<?php return ' . var_export(CMap::mergeArray($ClientMainConfiguration, $settings), true) . ' ; ?>');
134 
135 write('Configuration finished! Settings are in file ' . realpath(CLIENT_CONFIG_LOCATION));
136 
137 // update the client_console.php-file
138 $myOldConsole = include '../custom/config/client_console.php';
139 file_put_contents('../custom/config/client_console.php', '<?php Yii::setPathOfAlias(\'site\', dirname(__FILE__) . DIRECTORY_SEPARATOR . \'..\' . DIRECTORY_SEPARATOR . \'..\'); return ' .
140  var_export(CMap::mergeArray($myOldConsole, array('components' => array('db' => $settings['components']['db']))), true) . ' ; ?>');
141 
142 function write($text)
143 {
144  fwrite(STDOUT, $text . "\n");
145 }
146 
147 function prompt($question)
148 {
149  $answer = ask("\n" . $question . "\n[y|n]");
150  if (yes($answer))
151  return true;
152  elseif (no($answer)) {
153  return false;
154  } else {
155  return prompt($question);
156  }
157 }
158 
159 function ask($text)
160 {
161  fwrite(STDOUT, $text . "\n");
162  return trim(fgets(STDIN));
163 }
164 
165 function yes($string)
166 {
167  return substr($string, 0, 1) == 'y';
168 }
169 
170 function no($string)
171 {
172  return substr($string, 0, 1) == 'n';
173 }
174