]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Console/AutomaticInstallation.php
Rename Friendica\Database\dba to Friendica\Database\DBA
[friendica.git] / src / Core / Console / AutomaticInstallation.php
index a847b4a1bca259d2a1787ae91313f416e4d6761e..43c79bfb5712d5c3847c2537ba8e11615d20c05f 100644 (file)
@@ -3,8 +3,12 @@
 namespace Friendica\Core\Console;
 
 use Asika\SimpleConsole\Console;
-use dba;
 use Friendica\App;
+use Friendica\Core\Config;
+use Friendica\Core\Install;
+use Friendica\Core\Theme;
+use Friendica\Database\DBA;
+use RuntimeException;
 
 require_once 'mod/install.php';
 require_once 'include/dba.php';
@@ -16,11 +20,10 @@ class AutomaticInstallation extends Console
                return <<<HELP
 Installation - Install Friendica automatically
 Synopsis
-       bin/console install [-h|--help|-?] [-v] [-a] 
+       bin/console autoinstall [-h|--help|-?] [-v] [-a]
 
 Description
-       bin/console install
-               Installs Friendica with data based on the htconfig.php file
+    Installs Friendica with data based on the htconfig.php file
 
 Notes:
     Not checking .htaccess/URL-Rewrite during CLI installation.
@@ -29,72 +32,83 @@ Options
     -h|--help|-? Show help information
     -v           Show more debug information.
     -a           All setup checks are required (except .htaccess)
+    -f           prepared config file (e.g. ".htconfig.php" itself)
 HELP;
        }
 
        protected function doExecute()
        {
-               // remove die and copy config file
-               $fileContent = file_get_contents('./htconfig.php');
-               $fileContent = str_replace('die', '//die', $fileContent);
-               file_put_contents('.htautoinstall.php', $fileContent);
-
                // Initialise the app
-               $this->output("Initializing setup...\n");
+               $this->out("Initializing setup...\n");
 
                $a = get_app();
                $db_host = '';
                $db_user = '';
                $db_pass = '';
                $db_data = '';
-               require_once '.htautoinstall.php';
 
-               $this->output(" Complete!\n\n");
+               $config_file = $this->getOption('f', 'htconfig.php');
+
+               $this->out("Using config $config_file...\n");
+               require_once $config_file;
+
+               Install::setInstallMode();
+
+               $this->out(" Complete!\n\n");
 
                // Check basic setup
-               $this->output("Checking basic setup...\n");
+               $this->out("Checking basic setup...\n");
 
                $checkResults = [];
                $checkResults['basic'] = $this->runBasicChecks($a);
                $errorMessage = $this->extractErrors($checkResults['basic']);
 
                if ($errorMessage !== '') {
-                       die($errorMessage);
+                       throw new RuntimeException($errorMessage);
                }
 
-               $this->output(" Complete!\n\n");
+               $this->out(" Complete!\n\n");
 
                // Check database connection
-               $this->output("Checking database...\n");
+               $this->out("Checking database...\n");
 
                $checkResults['db'] = array();
                $checkResults['db'][] = $this->runDatabaseCheck($db_host, $db_user, $db_pass, $db_data);
                $errorMessage = $this->extractErrors($checkResults['db']);
 
                if ($errorMessage !== '') {
-                       die($errorMessage);
+                       throw new RuntimeException($errorMessage);
                }
 
-               $this->output(" Complete!\n\n");
+               $this->out(" Complete!\n\n");
 
                // Install database
-               $this->output("Inserting data into database...\n");
+               $this->out("Inserting data into database...\n");
 
-               $checkResults['data'] = load_database();
+               $checkResults['data'] = Install::installDatabaseStructure();
 
                if ($checkResults['data'] !== '') {
-                       die("ERROR: DB Database creation error. Is the DB empty?\n");
+                       throw new RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n");
                }
 
-               $this->output(" Complete!\n\n");
+               $this->out(" Complete!\n\n");
+
+               // Install theme
+               $this->out("Installing theme\n");
+               if (!empty(Config::get('system', 'theme'))) {
+                       Theme::install(Config::get('system', 'theme'));
+                       $this->out(" Complete\n\n");
+               } else {
+                       $this->out(" Theme setting is empty. Please check the file htconfig.php\n\n");
+               }
 
                // Copy config file
-               $this->output("Saving config file...\n");
-               if (!copy('.htautoinstall.php', '.htconfig.php')) {
-                       die("ERROR: Saving config file failed. Please copy .htautoinstall.php to .htconfig.php manually.\n");
+               $this->out("Saving config file...\n");
+               if ($config_file != '.htconfig.php' && !copy($config_file, '.htconfig.php')) {
+                       throw new RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '.htconfig.php' manually.\n");
                }
-               $this->output(" Complete!\n\n");
-               $this->output("\nInstallation is finished\n");
+               $this->out(" Complete!\n\n");
+               $this->out("\nInstallation is finished\n");
 
                return 0;
        }
@@ -103,23 +117,23 @@ HELP;
         * @param App $app
         * @return array
         */
-       public function runBasicChecks($app)
+       private function runBasicChecks($app)
        {
                $checks = [];
 
-               check_funcs($checks);
-               check_imagik($checks);
-               check_htconfig($checks);
-               check_smarty3($checks);
-               check_keys($checks);
+               Install::checkFunctions($checks);
+               Install::checkImagick($checks);
+               Install::checkLocalIni($checks);
+               Install::checkSmarty3($checks);
+               Install::checkKeys($checks);
 
-               if (!empty($app->config['php_path'])) {
-                       check_php($app->config['php_path'], $checks);
+               if (!empty(Config::get('config', 'php_path'))) {
+                       Install::checkPHP(Config::get('config', 'php_path'), $checks);
                } else {
-                       die(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n");
+                       throw new RuntimeException(" ERROR: The php_path is not set in the config.\n");
                }
 
-               $this->output(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
+               $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
 
                return $checks;
        }
@@ -131,7 +145,7 @@ HELP;
         * @param $db_data
         * @return array
         */
-       public function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data)
+       private function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data)
        {
                $result = array(
                        'title' => 'MySQL Connection',
@@ -141,7 +155,7 @@ HELP;
                );
 
 
-               if (!dba::connect($db_host, $db_user, $db_pass, $db_data, true)) {
+               if (!DBA::connect($db_host, $db_user, $db_pass, $db_data)) {
                        $result['status'] = false;
                        $result['help'] = 'Failed, please check your MySQL settings and credentials.';
                }
@@ -153,7 +167,7 @@ HELP;
         * @param array $results
         * @return string
         */
-       public function extractErrors($results)
+       private function extractErrors($results)
        {
                $errorMessage = '';
                $allChecksRequired = $this->getOption('a') !== null;
@@ -167,15 +181,4 @@ HELP;
 
                return $errorMessage;
        }
-
-       /**
-        * @param string $text
-        */
-       public function output($text)
-       {
-               $debugInfo = $this->getOption('v') !== null;
-               if ($debugInfo) {
-                       echo $text;
-               }
-       }
 }