Elgg  Version 4.3
InstallCommand.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Cli;
4 
5 use ElggInstaller;
10 
14 class InstallCommand extends BaseCommand {
15 
19  protected function configure() {
20  $this->setName('install')
21  ->setDescription('Install Elgg using a configuration file or interactive questions')
22  ->addOption('config', 'c', InputOption::VALUE_OPTIONAL,
23  'Path to php file that returns an array with installation configuration'
24  );
25  }
26 
30  protected function execute(InputInterface $input, OutputInterface $output) {
31 
32  $this->input = $input;
33  $this->output = $output;
34 
35  $config = $this->option('config');
36  if ($config && file_exists(realpath($config))) {
37  $params = include $config;
38  } else {
39  $params = [
43  'displayname' => 'Administrator',
44  'username' => $this->ask('Enter admin username [admin]: ', 'admin'),
45  'password' => $this->ask('Enter admin password: ', null, true),
46  'email' => $email = $this->ask('Enter admin email: '),
50  'dbhost' => $this->ask('Enter database host [localhost]: ', 'localhost'),
51  'dbport' => $this->ask('Enter database port [3306]: ', '3306'),
52  'dbuser' => $this->ask('Enter database username: '),
53  'dbpassword' => $this->ask('Enter database password: ', null, true),
54  'dbname' => $this->ask('Enter database name: '),
55  'dbprefix' => $this->ask('Enter database prefix (for example: elgg_): ', '', false, false),
59  'sitename' => $this->ask('Enter site name: '),
60  'siteemail' => $this->ask("Enter site email [$email]: ", $email),
61  'wwwroot' => $this->ask('Enter site URL (including protocol http|https and a trailing /): '),
62  'dataroot' => $this->ask('Enter data directory path: '),
63  'timezone' => 'UTC',
64  ];
65  }
66 
67  try {
68  $installer = new ElggInstaller();
69  $htaccess = !is_file(\Elgg\Application::projectDir()->getPath('.htaccess'));
70  $installer->batchInstall($params, $htaccess);
71  } catch (InstallationException $ex) {
72  $this->dumpRegisters();
73  $this->error($ex);
74 
75  return 1;
76  }
77 
79 
80  $release = elgg_get_release();
81 
82  $this->notice("Elgg {$release} install successful");
83  $this->notice("wwwroot: " . elgg_get_site_url());
84  $this->notice("dataroot: " . elgg_get_data_path());
85  $this->notice("cacheroot: " . elgg_get_cache_path());
86  $this->notice("assetroot: " . elgg_get_asset_path());
87 
88  return 0;
89  }
90 }
elgg_get_release()
Get the current Elgg release.
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:44
static projectDir()
Returns a directory that points to the project root, where composer is installed. ...
Adds interaction to a console command.
Definition: BaseCommand.php:18
error($message)
Print an error.
$email
Definition: change_email.php:7
$config
Advanced site settings, debugging section.
Definition: debugging.php:6
notice($message)
Print a notce.
Updates the basic settings for the primary site object.
static start()
Start and boot the core.
dumpRegisters()
Dump and output system and error messages.
elgg_get_cache_path()
Get the cache directory path for this installation, ending with slash.
Thrown when there is a major problem with the installation.
$installer
elgg_get_site_url()
Get the URL for the current (or specified) site, ending with "/".
elgg-cli install [–config]
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.