]> git.mxchange.org Git - friendica.git/blobdiff - src/Core/Console/AutomaticInstallation.php
Bugfixings
[friendica.git] / src / Core / Console / AutomaticInstallation.php
index 9cdb8a0ae233187c34c6dbed173e4ba681aa6977..294009ada015e5939955c550dbdc2b257de8d309 100644 (file)
@@ -3,15 +3,14 @@
 namespace Friendica\Core\Console;
 
 use Asika\SimpleConsole\Console;
-use Friendica\App;
 use Friendica\BaseObject;
 use Friendica\Core\Config;
-use Friendica\Core\Install;
+use Friendica\Core\Installer;
 use Friendica\Core\Theme;
 use Friendica\Database\DBA;
+use Friendica\Database\DBStructure;
 use RuntimeException;
 
-require_once 'mod/install.php';
 require_once 'include/dba.php';
 
 class AutomaticInstallation extends Console
@@ -77,6 +76,22 @@ HELP;
 
                $a = BaseObject::getApp();
 
+               $installer = new Installer();
+
+               $this->out(" Complete!\n\n");
+
+               // Check Environment
+               $this->out("Checking environment...\n");
+
+               $installer->resetChecks();
+
+               if (!$this->runBasicChecks($installer)) {
+                       $errorMessage = $this->extractErrors($installer->getChecks());
+                       throw new RuntimeException($errorMessage);
+               }
+
+               $this->out(" Complete!\n\n");
+
                // if a config file is set,
                $config_file = $this->getOption(['f', 'file']);
 
@@ -105,47 +120,38 @@ HELP;
                        $db_user = $this->getOption(['U', 'dbuser'], ($save_db) ? getenv('MYSQL_USER') . getenv('MYSQL_USERNAME') : '');
                        $db_pass = $this->getOption(['P', 'dbpass'], ($save_db) ? getenv('MYSQL_PASSWORD') : '');
                        $url_path = $this->getOption(['u', 'urlpath'], (!empty('FRIENDICA_URL_PATH')) ? getenv('FRIENDICA_URL_PATH') : null);
-                       $php_path = $this->getOption(['b', 'phppath'], (!empty('FRIENDICA_PHP_PATH')) ? getenv('FRIENDICA_PHP_PATH') : '');
+                       $php_path = $this->getOption(['b', 'phppath'], (!empty('FRIENDICA_PHP_PATH')) ? getenv('FRIENDICA_PHP_PATH') : null);
                        $admin_mail = $this->getOption(['A', 'admin'], (!empty('FRIENDICA_ADMIN_MAIL')) ? getenv('FRIENDICA_ADMIN_MAIL') : '');
                        $tz = $this->getOption(['T', 'tz'], (!empty('FRIENDICA_TZ')) ? getenv('FRIENDICA_TZ') : '');
                        $lang = $this->getOption(['L', 'lang'], (!empty('FRIENDICA_LANG')) ? getenv('FRIENDICA_LANG') : '');
 
-                       Install::createConfig(
+                       if (empty($php_path)) {
+                               $php_path = $installer->getPHPPath();
+                       }
+
+                       $installer->createConfig(
+                               $php_path,
                                $url_path,
                                ((!empty($db_port)) ? $db_host . ':' . $db_port : $db_host),
                                $db_user,
                                $db_pass,
                                $db_data,
-                               $php_path,
                                $tz,
                                $lang,
-                               $admin_mail
+                               $admin_mail,
+                               $a->getBasePath()
                        );
                }
 
                $this->out(" Complete!\n\n");
 
-               // Check basic setup
-               $this->out("Checking basic setup...\n");
-
-               $checkResults = [];
-               $checkResults['basic'] = $this->runBasicChecks($a);
-               $errorMessage = $this->extractErrors($checkResults['basic']);
-
-               if ($errorMessage !== '') {
-                       throw new RuntimeException($errorMessage);
-               }
-
-               $this->out(" Complete!\n\n");
-
                // Check database connection
                $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']);
+               $installer->resetChecks();
 
-               if ($errorMessage !== '') {
+               if (!$installer->checkDB($db_host, $db_user, $db_pass, $db_data)) {
+                       $errorMessage = $this->extractErrors($installer->getChecks());
                        throw new RuntimeException($errorMessage);
                }
 
@@ -154,10 +160,11 @@ HELP;
                // Install database
                $this->out("Inserting data into database...\n");
 
-               $checkResults['data'] = Install::installDatabaseStructure();
+               $installer->resetChecks();
 
-               if ($checkResults['data'] !== '') {
-                       throw new RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n");
+               if (!$installer->installDatabase()) {
+                       $errorMessage = $this->extractErrors($installer->getChecks());
+                       throw new RuntimeException($errorMessage);
                }
 
                $this->out(" Complete!\n\n");
@@ -177,53 +184,43 @@ HELP;
        }
 
        /**
-        * @param App $app
-        * @return array
+        * @param Installer $installer the Installer instance
+        *
+        * @return bool true if checks were successfully, otherwise false
         */
-       private function runBasicChecks($app)
+       private function runBasicChecks(Installer $installer)
        {
-               $checks = [];
+               $checked = true;
 
-               Install::checkFunctions($checks);
-               Install::checkImagick($checks);
-               Install::checkLocalIni($checks);
-               Install::checkSmarty3($checks);
-               Install::checkKeys($checks);
+               $installer->resetChecks();
+               if (!$installer->checkFunctions())              {
+                       $checked = false;
+               }
+               if (!$installer->checkImagick()) {
+                       $checked = false;
+               }
+               if (!$installer->checkLocalIni()) {
+                       $checked = false;
+               }
+               if (!$installer->checkSmarty3()) {
+                       $checked = false;
+               }
+               if (!$installer->checkKeys()) {
+                       $checked = false;
+               }
 
+               $php_path = null;
                if (!empty(Config::get('config', 'php_path'))) {
-                       Install::checkPHP(Config::get('config', 'php_path'), $checks);
-               } else {
-                       throw new RuntimeException(" ERROR: The php_path is not set in the config.\n");
+                       $php_path = Config::get('config', 'php_path');
                }
 
-               $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
-
-               return $checks;
-       }
-
-       /**
-        * @param $db_host
-        * @param $db_user
-        * @param $db_pass
-        * @param $db_data
-        * @return array
-        */
-       private function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data)
-       {
-               $result = array(
-                       'title' => 'MySQL Connection',
-                       'required' => true,
-                       'status' => true,
-                       'help' => '',
-               );
-
-
-               if (!DBA::connect($db_host, $db_user, $db_pass, $db_data)) {
-                       $result['status'] = false;
-                       $result['help'] = 'Failed, please check your MySQL settings and credentials.';
+               if (!$installer->checkPHP($php_path, true)) {
+                       $checked = false;
                }
 
-               return $result;
+               $this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
+
+               return $checked;
        }
 
        /**