Elgg  Version 3.0
InstallCommand.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cli;
4 
5 use ElggInstaller;
9 
13 class InstallCommand extends BaseCommand {
14 
18  protected function configure() {
19  $this->setName('install')
20  ->setDescription('Install Elgg using a configuration file or interactive questions')
21  ->addOption('config', 'c', InputOption::VALUE_OPTIONAL,
22  'Path to php file that returns an array with installation configuration'
23  );
24  }
25 
29  protected function execute(InputInterface $input, OutputInterface $output) {
30 
31  $this->input = $input;
32  $this->output = $output;
33 
34  $config = $this->option('config');
35  if ($config && file_exists(realpath($config))) {
36  $params = include $config;
37  } else {
38  $params = [
42  'displayname' => 'Administrator',
43  'username' => $this->ask('Enter admin username [admin]: ', 'admin'),
44  'password' => $this->ask('Enter admin password: ', null, true),
45  'email' => $email = $this->ask('Enter admin email: '),
49  'dbhost' => $this->ask('Enter database host [localhost]: ', 'localhost'),
50  'dbuser' => $this->ask('Enter database username: '),
51  'dbpassword' => $this->ask('Enter database password: ', null, true),
52  'dbname' => $this->ask('Enter database name: '),
53  'dbprefix' => $this->ask('Enter database prefix [elgg_]: ', 'elgg_'),
57  'sitename' => $this->ask('Enter site name: '),
58  'siteemail' => $this->ask("Enter site email [$email]: ", $email),
59  'wwwroot' => $this->ask('Enter site URL (including protocol http|https and a trailing /): '),
60  'dataroot' => $this->ask('Enter data directory path: '),
61  'timezone' => 'UTC',
62  ];
63  }
64 
65  try {
66  $installer = new ElggInstaller();
67  $htaccess = !is_file(\Elgg\Application::projectDir()->getPath('.htaccess'));
68  $installer->batchInstall($params, $htaccess);
69  } catch (\InstallationException $ex) {
70  $this->dumpRegisters();
71  $this->error($ex);
72 
73  return 1;
74  }
75 
77 
78  $version = elgg_get_version(true);
79 
80  $this->notice("Elgg $version install successful");
81  $this->notice("wwwroot: " . elgg_get_site_url());
82  $this->notice("dataroot: " . elgg_get_data_path());
83  $this->notice("cacheroot: " . elgg_get_cache_path());
84  $this->notice("assetroot: " . elgg_get_asset_path());
85 
86  return 0;
87  }
88 }
elgg_get_asset_path()
Get the asset cache directory path for this installation, ending with slash.
$params
Saves global plugin settings.
Definition: save.php:13
ask($question, $default=null, $hidden=false, $required=true)
Ask a question.
Definition: BaseCommand.php:43
static projectDir()
Returns a directory that points to the project root, where composer is installed. ...
Adds interaction to a console command.
Definition: BaseCommand.php:17
error($message)
Print an error.
$email
Definition: register.php:18
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
notice($message)
Print a notce.
static start()
Start and boot the core.
dumpRegisters()
Dump and output system and error messages.
Configuration exception.
elgg_get_cache_path()
Get the cache directory path for this installation, ending with slash.
$installer
elgg_get_site_url()
Get the URL for the current (or specified) site, ending with "/".
elgg-cli install [–config]
elgg_get_version($human_readable=false)
Get the current Elgg version information.
Definition: elgglib.php:814
elgg_get_data_path()
Get the data directory path for this installation, ending with slash.
execute(InputInterface $input, OutputInterface $output)
{}
option($name)
Returns option value.
$version
Definition: version.php:14