3 namespace Friendica\Core\Console;
5 use Asika\SimpleConsole\Console;
7 use Friendica\Core\Config;
8 use Friendica\Core\Install;
9 use Friendica\Core\Theme;
10 use Friendica\Database\DBA;
13 require_once 'mod/install.php';
14 require_once 'include/dba.php';
16 class AutomaticInstallation extends Console
18 protected function getHelp()
21 Installation - Install Friendica automatically
23 bin/console autoinstall [-h|--help|-?] [-v] [-a]
26 Installs Friendica with data based on the htconfig.php file
29 Not checking .htaccess/URL-Rewrite during CLI installation.
32 -h|--help|-? Show help information
33 -v Show more debug information.
34 -a All setup checks are required (except .htaccess)
35 -f prepared config file (e.g. ".htconfig.php" itself)
39 protected function doExecute()
42 $this->out("Initializing setup...\n");
50 $config_file = $this->getOption('f', 'htconfig.php');
52 $this->out("Using config $config_file...\n");
53 require_once $config_file;
55 Install::setInstallMode();
57 $this->out(" Complete!\n\n");
60 $this->out("Checking basic setup...\n");
63 $checkResults['basic'] = $this->runBasicChecks($a);
64 $errorMessage = $this->extractErrors($checkResults['basic']);
66 if ($errorMessage !== '') {
67 throw new RuntimeException($errorMessage);
70 $this->out(" Complete!\n\n");
72 // Check database connection
73 $this->out("Checking database...\n");
75 $checkResults['db'] = array();
76 $checkResults['db'][] = $this->runDatabaseCheck($db_host, $db_user, $db_pass, $db_data);
77 $errorMessage = $this->extractErrors($checkResults['db']);
79 if ($errorMessage !== '') {
80 throw new RuntimeException($errorMessage);
83 $this->out(" Complete!\n\n");
86 $this->out("Inserting data into database...\n");
88 $checkResults['data'] = Install::installDatabaseStructure();
90 if ($checkResults['data'] !== '') {
91 throw new RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n");
94 $this->out(" Complete!\n\n");
97 $this->out("Installing theme\n");
98 if (!empty(Config::get('system', 'theme'))) {
99 Theme::install(Config::get('system', 'theme'));
100 $this->out(" Complete\n\n");
102 $this->out(" Theme setting is empty. Please check the file htconfig.php\n\n");
106 $this->out("Saving config file...\n");
107 if ($config_file != '.htconfig.php' && !copy($config_file, '.htconfig.php')) {
108 throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '.htconfig.php' manually.\n");
110 $this->out(" Complete!\n\n");
111 $this->out("\nInstallation is finished\n");
120 private function runBasicChecks($app)
124 Install::checkFunctions($checks);
125 Install::checkImagick($checks);
126 Install::checkLocalIni($checks);
127 Install::checkSmarty3($checks);
128 Install::checkKeys($checks);
130 if (!empty(Config::get('config', 'php_path'))) {
131 Install::checkPHP(Config::get('config', 'php_path'), $checks);
133 throw new RuntimeException(" ERROR: The php_path is not set in the config.\n");
136 $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
148 private function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data)
151 'title' => 'MySQL Connection',
158 if (!DBA::connect($db_host, $db_user, $db_pass, $db_data)) {
159 $result['status'] = false;
160 $result['help'] = 'Failed, please check your MySQL settings and credentials.';
167 * @param array $results
170 private function extractErrors($results)
173 $allChecksRequired = $this->getOption('a') !== null;
175 foreach ($results as $result) {
176 if (($allChecksRequired || $result['required'] === true) && $result['status'] === false) {
177 $errorMessage .= "--------\n";
178 $errorMessage .= $result['title'] . ': ' . $result['help'] . "\n";
182 return $errorMessage;