3 namespace Friendica\Core\Console;
5 use Asika\SimpleConsole\Console;
9 require_once 'mod/install.php';
10 require_once 'include/dba.php';
12 class AutomaticInstallation extends Console
14 protected function getHelp()
17 Installation - Install Friendica automatically
19 bin/console autoinstall [-h|--help|-?] [-v] [-a]
22 Not checking .htaccess/URL-Rewrite during CLI installation.
25 -h|--help|-? Show help information
26 -v Show more debug information.
27 -a All setup checks are required (except .htaccess)
31 protected function doExecute()
34 $this->out("Initializing setup...\n");
41 require_once 'htconfig.php';
43 $this->out(" Complete!\n\n");
46 $this->out("Checking basic setup...\n");
49 $checkResults['basic'] = $this->runBasicChecks($a);
50 $errorMessage = $this->extractErrors($checkResults['basic']);
52 if ($errorMessage !== '') {
53 throw new \RuntimeException($errorMessage);
56 $this->out(" Complete!\n\n");
58 // Check database connection
59 $this->out("Checking database...\n");
61 $checkResults['db'] = array();
62 $checkResults['db'][] = $this->runDatabaseCheck($db_host, $db_user, $db_pass, $db_data);
63 $errorMessage = $this->extractErrors($checkResults['db']);
65 if ($errorMessage !== '') {
66 throw new \RuntimeException($errorMessage);
69 $this->out(" Complete!\n\n");
72 $this->out("Inserting data into database...\n");
74 $checkResults['data'] = load_database();
76 if ($checkResults['data'] !== '') {
77 throw new \RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n");
80 $this->out(" Complete!\n\n");
83 $this->out("Saving config file...\n");
84 if (!copy('htconfig.php', '.htconfig.php')) {
85 throw new \RuntimeException("ERROR: Saving config file failed. Please copy .htautoinstall.php to .htconfig.php manually.\n");
87 $this->out(" Complete!\n\n");
88 $this->out("\nInstallation is finished\n");
97 private function runBasicChecks($app)
101 check_funcs($checks);
102 check_imagik($checks);
103 check_htconfig($checks);
104 check_smarty3($checks);
107 if (!empty($app->config['php_path'])) {
108 check_php($app->config['php_path'], $checks);
110 throw new \RuntimeException(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n");
113 $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
125 private function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data)
128 'title' => 'MySQL Connection',
135 if (!dba::connect($db_host, $db_user, $db_pass, $db_data, true)) {
136 $result['status'] = false;
137 $result['help'] = 'Failed, please check your MySQL settings and credentials.';
144 * @param array $results
147 private function extractErrors($results)
150 $allChecksRequired = $this->getOption('a') !== null;
152 foreach ($results as $result) {
153 if (($allChecksRequired || $result['required'] === true) && $result['status'] === false) {
154 $errorMessage .= "--------\n";
155 $errorMessage .= $result['title'] . ': ' . $result['help'] . "\n";
159 return $errorMessage;