Open Journal Systems  3.3.0
InstallTool.inc.php
1 <?php
2 
17 import('classes.install.Install');
18 import('lib.pkp.classes.install.form.InstallForm');
19 import('lib.pkp.classes.site.Version');
20 import('lib.pkp.classes.site.VersionCheck');
21 
23 
25  var $params;
26 
31  function __construct($argv = array()) {
32  parent::__construct($argv);
33  }
34 
38  function usage() {
39  echo "Install tool\n"
40  . "Usage: {$this->scriptName}\n";
41  }
42 
46  function execute() {
47  if ($this->readParams()) {
48  $this->install();
49  }
50  }
51 
55  function install() {
56  $installer = new Install($this->params);
57  $installer->setLogger($this);
58 
59  if ($installer->execute()) {
60  if (count($installer->getNotes()) > 0) {
61  printf("\nRelease Notes\n");
62  printf("----------------------------------------\n");
63  foreach ($installer->getNotes() as $note) {
64  printf("%s\n\n", $note);
65  }
66  }
67 
68  if (!$installer->wroteConfig()) {
69  printf("\nNew config.inc.php:\n");
70  printf("----------------------------------------\n");
71  echo $installer->getConfigContents();
72  printf("----------------------------------------\n");
73  }
74 
75  $newVersion = $installer->getNewVersion();
76  printf("Successfully installed version %s\n", $newVersion->getVersionString(false));
77 
78  } else {
79  printf("ERROR: Installation failed: %s\n", $installer->getErrorString());
80  }
81  }
82 
88  function readParams() {
89  $installForm = new InstallForm(null); // Request object not available to CLI
90 
91  // Locale Settings
92  $this->printTitle('installer.localeSettings');
93  $this->readParamOptions('locale', 'locale.primary', $installForm->supportedLocales, 'en_US');
94  $this->readParamOptions('additionalLocales', 'installer.additionalLocales', $installForm->supportedLocales, '', true);
95  $this->readParamOptions('clientCharset', 'installer.clientCharset', $installForm->supportedClientCharsets, 'utf-8');
96  $this->readParamOptions('connectionCharset', 'installer.connectionCharset', $installForm->supportedConnectionCharsets, '');
97 
98  // File Settings
99  $this->printTitle('installer.fileSettings');
100  $this->readParam('filesDir', 'installer.filesDir');
101 
102  // Administrator Account
103  $this->printTitle('installer.administratorAccount');
104  $this->readParam('adminUsername', 'user.username');
105  @`/bin/stty -echo`;
106  do {
107  $this->readParam('adminPassword', 'user.password');
108  printf("\n");
109  $this->readParam('adminPassword2', 'user.repeatPassword');
110  printf("\n");
111  } while ($this->params['adminPassword'] != $this->params['adminPassword2']);
112  @`/bin/stty echo`;
113  $this->readParam('adminEmail', 'user.email');
114 
115  // Database Settings
116  $this->printTitle('installer.databaseSettings');
117  $this->readParamOptions('databaseDriver', 'installer.databaseDriver', $installForm->checkDBDrivers());
118  $this->readParam('databaseHost', 'installer.databaseHost', '');
119  $this->readParam('databaseUsername', 'installer.databaseUsername', '');
120  $this->readParam('databasePassword', 'installer.databasePassword', '');
121  $this->readParam('databaseName', 'installer.databaseName');
122  $this->readParamBoolean('createDatabase', 'installer.createDatabase', 'Y');
123 
124  // Miscellaneous Settings
125  $this->printTitle('installer.miscSettings');
126  $this->readParam('oaiRepositoryId', 'installer.oaiRepositoryId');
127 
128  $this->readParamBoolean('enableBeacon', 'installer.beacon.enable', 'Y');
129 
130  printf("\n*** ");
131  }
132 
137  function printTitle($title) {
138  printf("\n%s\n%s\n%s\n", str_repeat('-', 80), __($title), str_repeat('-', 80));
139  }
140 
145  function readInput() {
146  $value = trim(fgets(STDIN));
147  if ($value === false || feof(STDIN)) {
148  printf("\n");
149  exit(0);
150  }
151  return $value;
152  }
153 
160  function readParam($name, $prompt, $defaultValue = null) {
161  do {
162  if (isset($defaultValue)) {
163  printf("%s (%s): ", __($prompt), $defaultValue !== '' ? $defaultValue : __('common.none'));
164  } else {
165  printf("%s: ", __($prompt));
166  }
167 
168  $value = $this->readInput();
169 
170  if ($value === '' && isset($defaultValue)) {
171  $value = $defaultValue;
172  }
173  } while ($value === '' && $defaultValue !== '');
174  $this->params[$name] = $value;
175  }
176 
183  function readParamBoolean($name, $prompt, $default = 'N') {
184  if ($default == 'N') {
185  printf("%s [y/N] ", __($prompt));
186  $value = $this->readInput();
187  $this->params[$name] = (int)(strtolower(substr(trim($value), 0, 1)) == 'y');
188  } else {
189  printf("%s [Y/n] ", __($prompt));
190  $value = $this->readInput();
191  $this->params[$name] = (int)(strtolower(substr(trim($value), 0, 1)) != 'n');
192  }
193  }
194 
202  function readParamOptions($name, $prompt, $options, $defaultValue = null, $allowMultiple = false) {
203  do {
204  printf("%s\n", __($prompt));
205  foreach ($options as $k => $v) {
206  printf(" %-10s %s\n", '[' . $k . ']', $v);
207  }
208  if ($allowMultiple) {
209  printf(" (%s)\n", __('installer.form.separateMultiple'));
210  }
211  if (isset($defaultValue)) {
212  printf("%s (%s): ", __('common.select'), $defaultValue !== '' ? $defaultValue : __('common.none'));
213  } else {
214  printf("%s: ", __('common.select'));
215  }
216 
217  $value = $this->readInput();
218 
219  if ($value === '' && isset($defaultValue)) {
220  $value = $defaultValue;
221  }
222 
223  $values = array();
224  if ($value !== '') {
225  if ($allowMultiple) {
226  $values = ($value === '' ? array() : preg_split('/\s*,\s*/', $value));
227  } else {
228  $values = array($value);
229  }
230  foreach ($values as $k) {
231  if (!isset($options[$k])) {
232  $value = '';
233  break;
234  }
235  }
236  }
237  } while ($value === '' && $defaultValue !== '');
238 
239  if ($allowMultiple) {
240  $this->params[$name] = $values;
241  } else {
242  $this->params[$name] = $value;
243  }
244  }
245 
250  function log($message) {
251  printf("[%s]\n", $message);
252  }
253 
254 }
255 
256 
InstallTool\execute
execute()
Definition: InstallTool.inc.php:49
InstallTool\__construct
__construct($argv=array())
Definition: InstallTool.inc.php:34
InstallTool\usage
usage()
Definition: InstallTool.inc.php:41
CommandLineTool
Initialization code for command-line scripts.
Definition: CliTool.inc.php:44
InstallTool\printTitle
printTitle($title)
Definition: InstallTool.inc.php:140
InstallTool\readParamBoolean
readParamBoolean($name, $prompt, $default='N')
Definition: InstallTool.inc.php:186
InstallTool\log
log($message)
Definition: InstallTool.inc.php:253
InstallTool\$params
$params
Definition: InstallTool.inc.php:28
InstallForm
Form for system installation.
Definition: InstallForm.inc.php:20
InstallTool
Definition: InstallTool.inc.php:22
Install
Perform system installation.
Definition: Install.inc.php:28
InstallTool\readInput
readInput()
Definition: InstallTool.inc.php:148
InstallTool\readParams
readParams()
Definition: InstallTool.inc.php:91
InstallTool\install
install()
Definition: InstallTool.inc.php:58
InstallTool\readParam
readParam($name, $prompt, $defaultValue=null)
Definition: InstallTool.inc.php:163
CommandLineTool\$argv
$argv
Definition: CliTool.inc.php:53
InstallTool\readParamOptions
readParamOptions($name, $prompt, $options, $defaultValue=null, $allowMultiple=false)
Definition: InstallTool.inc.php:205