Passed
Push — master ( f13f78...5c1b24 )
by Ismayil
04:22
created

engine/classes/Elgg/Cli/InstallCommand.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Elgg\Cli;
4
5
use ElggInstaller;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * elgg-cli install [--config]
12
 */
13
class InstallCommand extends \Symfony\Component\Console\Command\Command {
14
15
	use ConsoleInteractions;
16
17
	/**
18
	 * {@inheritdoc}
19
	 */
20
	protected function configure() {
21
		$this->setName('install')
22
			->setDescription('Install Elgg using a configuration file or interactive questions')
23
			->addOption('config', 'c', InputOption::VALUE_OPTIONAL, 'Path to php file that returns an array with installation configuration');
24
	}
25
26
	/**
27
	 * {@inheritdoc}
28
	 */
29
	protected function execute(InputInterface $input, OutputInterface $output) {
30
31
		$this->input = $input;
0 ignored issues
show
Documentation Bug introduced by
It seems like $input of type object<Symfony\Component...e\Input\InputInterface> is incompatible with the declared type object<Elgg\Cli\InputInterface> of property $input.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32
		$this->output = $output;
0 ignored issues
show
Documentation Bug introduced by
It seems like $output of type object<Symfony\Component...Output\OutputInterface> is incompatible with the declared type object<Elgg\Cli\OutputInterface> of property $output.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
33
34
		$config = $this->option('config');
35
		if ($config && file_exists(realpath($config))) {
36
			$params = include $config;
37
		} else {
38
			$params = [
39
				/**
40
				 * Admin account
41
				 */
42
				'displayname' => 'Administrator',
43
				'username' => $this->ask('Enter admin username: ', 'admin'),
44
				'password' => $this->ask('Enter admin password: ', null, true),
45
				'email' => $email = $this->ask('Enter admin email: '),
46
				/**
47
				 * Database parameters
48
				 */
49
				'dbuser' => $this->ask('Enter database username: '),
50
				'dbpassword' => $this->ask('Enter database password: ', null, true),
51
				'dbname' => $this->ask('Enter database name: '),
52
				'dbprefix' => $this->ask('Enter database prefix [elgg_]: ', 'elgg_'),
53
				/**
54
				 * Site settings
55
				 */
56
				'sitename' => $this->ask('Enter site name: '),
57
				'siteemail' => $this->ask("Enter site email [$email]: ", $email),
58
				'wwwroot' => $this->ask('Enter site URL: '),
59
				'dataroot' => $this->ask('Enter data directory path: '),
60
				'timezone' => 'UTC'
61
			];
62
		}
63
64
		try {
65
			$installer = new ElggInstaller();
66
			$htaccess = !is_file(\Elgg\Application::projectDir()->getPath('.htaccess'));
67
			$installer->batchInstall($params, $htaccess);
68
		} catch (\InstallationException $ex) {
69
			$this->dumpRegisters();
70
			$this->write(elgg_format_element('error', [], $ex->getMessage()));
71
72
			return 1;
73
		}
74
75
		\Elgg\Application::start();
76
77
		$version = elgg_get_version(true);
78
79
		$this->write("Elgg $version install successful");
80
		$this->write("wwwroot: " . elgg_get_config('wwwroot'));
81
		$this->write("dataroot: " . elgg_get_config('dataroot'));
82
		$this->write("cacheroot: " . elgg_get_config('cacheroot'));
83
84
	}
85
86
}
87