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 Installs Friendica with data based on the htconfig.php file
25 Not checking .htaccess/URL-Rewrite during CLI installation.
28 -h|--help|-? Show help information
29 -v Show more debug information.
30 -a All setup checks are required (except .htaccess)
34 protected function doExecute()
37 $this->out("Initializing setup...\n");
44 require_once 'htconfig.php';
46 $this->out(" Complete!\n\n");
49 $this->out("Checking basic setup...\n");
52 $checkResults['basic'] = $this->runBasicChecks($a);
53 $errorMessage = $this->extractErrors($checkResults['basic']);
55 if ($errorMessage !== '') {
56 throw new \RuntimeException($errorMessage);
59 $this->out(" Complete!\n\n");
61 // Check database connection
62 $this->out("Checking database...\n");
64 $checkResults['db'] = array();
65 $checkResults['db'][] = $this->runDatabaseCheck($db_host, $db_user, $db_pass, $db_data);
66 $errorMessage = $this->extractErrors($checkResults['db']);
68 if ($errorMessage !== '') {
69 throw new \RuntimeException($errorMessage);
72 $this->out(" Complete!\n\n");
75 $this->out("Inserting data into database...\n");
77 $checkResults['data'] = load_database();
79 if ($checkResults['data'] !== '') {
80 throw new \RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n");
83 $this->out(" Complete!\n\n");
86 $this->out("Saving config file...\n");
87 if (!copy('htconfig.php', '.htconfig.php')) {
88 throw new \RuntimeException("ERROR: Saving config file failed. Please copy .htautoinstall.php to .htconfig.php manually.\n");
90 $this->out(" Complete!\n\n");
91 $this->out("\nInstallation is finished\n");
100 private function runBasicChecks($app)
104 check_funcs($checks);
105 check_imagik($checks);
106 check_htconfig($checks);
107 check_smarty3($checks);
110 if (!empty($app->config['php_path'])) {
111 check_php($app->config['php_path'], $checks);
113 throw new \RuntimeException(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n");
116 $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
128 private function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data)
131 'title' => 'MySQL Connection',
138 if (!dba::connect($db_host, $db_user, $db_pass, $db_data, true)) {
139 $result['status'] = false;
140 $result['help'] = 'Failed, please check your MySQL settings and credentials.';
147 * @param array $results
150 private function extractErrors($results)
153 $allChecksRequired = $this->getOption('a') !== null;
155 foreach ($results as $result) {
156 if (($allChecksRequired || $result['required'] === true) && $result['status'] === false) {
157 $errorMessage .= "--------\n";
158 $errorMessage .= $result['title'] . ': ' . $result['help'] . "\n";
162 return $errorMessage;