3 namespace Friendica\Core\Console;
5 use Asika\SimpleConsole\Console;
8 use Friendica\Core\Install;
9 use Friendica\Core\Theme;
11 require_once 'mod/install.php';
12 require_once 'include/dba.php';
14 class AutomaticInstallation extends Console
16 protected function getHelp()
19 Installation - Install Friendica automatically
21 bin/console autoinstall [-h|--help|-?] [-v] [-a]
24 Installs Friendica with data based on the htconfig.php file
27 Not checking .htaccess/URL-Rewrite during CLI installation.
30 -h|--help|-? Show help information
31 -v Show more debug information.
32 -a All setup checks are required (except .htaccess)
33 -f prepared config file (e.g. ".htconfig.php" itself)
37 protected function doExecute()
40 $this->out("Initializing setup...\n");
48 $config_file = $this->getOption('f', 'htconfig.php');
50 $this->out("Using config $config_file...\n");
51 require_once $config_file;
53 Install::setInstallMode();
55 $this->out(" Complete!\n\n");
58 $this->out("Checking basic setup...\n");
61 $checkResults['basic'] = $this->runBasicChecks($a);
62 $errorMessage = $this->extractErrors($checkResults['basic']);
64 if ($errorMessage !== '') {
65 throw new \RuntimeException($errorMessage);
68 $this->out(" Complete!\n\n");
70 // Check database connection
71 $this->out("Checking database...\n");
73 $checkResults['db'] = array();
74 $checkResults['db'][] = $this->runDatabaseCheck($db_host, $db_user, $db_pass, $db_data);
75 $errorMessage = $this->extractErrors($checkResults['db']);
77 if ($errorMessage !== '') {
78 throw new \RuntimeException($errorMessage);
81 $this->out(" Complete!\n\n");
84 $this->out("Inserting data into database...\n");
86 $checkResults['data'] = Install::installDatabaseStructure();
88 if ($checkResults['data'] !== '') {
89 throw new \RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n");
92 $this->out(" Complete!\n\n");
95 $this->out("Installing theme\n");
96 if (!empty($a->config['system']['theme'])) {
97 Theme::install($a->config['system']['theme']);
98 $this->out(" Complete\n\n");
100 $this->out(" Theme setting is empty. Please check the file htconfig.php\n\n");
104 $this->out("Saving config file...\n");
105 if ($config_file != '.htconfig.php' && !copy($config_file, '.htconfig.php')) {
106 throw new \RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '.htconfig.php' manually.\n");
108 $this->out(" Complete!\n\n");
109 $this->out("\nInstallation is finished\n");
118 private function runBasicChecks($app)
122 Install::checkFunctions($checks);
123 Install::checkImagick($checks);
124 Install::checkHtConfig($checks);
125 Install::checkSmarty3($checks);
126 Install::checkKeys($checks);
128 if (!empty($app->config['php_path'])) {
129 Install::checkPHP($app->config['php_path'], $checks);
131 throw new \RuntimeException(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n");
134 $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
146 private function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data)
149 'title' => 'MySQL Connection',
156 if (!dba::connect($db_host, $db_user, $db_pass, $db_data)) {
157 $result['status'] = false;
158 $result['help'] = 'Failed, please check your MySQL settings and credentials.';
165 * @param array $results
168 private function extractErrors($results)
171 $allChecksRequired = $this->getOption('a') !== null;
173 foreach ($results as $result) {
174 if (($allChecksRequired || $result['required'] === true) && $result['status'] === false) {
175 $errorMessage .= "--------\n";
176 $errorMessage .= $result['title'] . ': ' . $result['help'] . "\n";
180 return $errorMessage;