From 1dbe2d9eac31189d9981f27622ee65338a1d72d7 Mon Sep 17 00:00:00 2001 From: Taras Machyshyn Date: Fri, 15 Aug 2014 17:12:26 +0300 Subject: [PATCH] installer: missing files --- install/core/Installer.php | 35 +++++++++++++++++++++++++++-------- install/core/SystemHelper.php | 28 +++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/install/core/Installer.php b/install/core/Installer.php index b4987cf54e..d764e15e2a 100644 --- a/install/core/Installer.php +++ b/install/core/Installer.php @@ -148,7 +148,7 @@ class Installer */ public function saveData($database, $language) { - $initData = include('install/core/init/config.php'); + $initData = include('install/core/afterInstall/config.php'); $siteUrl = $this->getSystemHelper()->getBaseUrl(); @@ -194,9 +194,7 @@ class Installer if (isset($preferences['defaultCurrency']) && !in_array($preferences['defaultCurrency'], $currencyList)) { $preferences['currencyList'] = array($preferences['defaultCurrency']); - - $preferences['currency'] = $this->getConfig()->get('currency'); - $preferences['currency']['base'] = $preferences['defaultCurrency']; + $preferences['baseCurrency'] = $preferences['defaultCurrency']; } $res = $this->saveConfig($preferences); @@ -210,7 +208,7 @@ class Installer protected function createRecords() { - $records = include('install/core/init/records.php'); + $records = include('install/core/afterInstall/records.php'); $result = true; foreach ($records as $entityName => $recordList) { @@ -271,8 +269,6 @@ class Installer $result = $this->createRecord('User', $user); - $result &= $this->createRecords(); - return $result; } @@ -315,9 +311,16 @@ class Installer public function setSuccess() { + $this->auth(); + + /** afterInstall scripts */ + $result = $this->createRecords(); + $result &= $this->executeQueries(); + /** END: afterInstall scripts */ + $config = $this->app->getContainer()->get('config'); $config->set('isInstalled', true); - $result = $config->save(); + $result &= $config->save(); return $result; } @@ -379,5 +382,21 @@ class Installer return $this->getContainer()->get('scheduledJob')->getSetupMessage(); } + protected function executeQueries() + { + $queries = include('install/core/afterInstall/queries.php'); + + $pdo = $this->getEntityManager()->getPDO(); + + $result = true; + + foreach ($queries as $query) { + $sth = $pdo->prepare($query); + $result =& $sth->execute(); + } + + return $result; + } + } diff --git a/install/core/SystemHelper.php b/install/core/SystemHelper.php index 391a34b2e5..47c95e1cb1 100644 --- a/install/core/SystemHelper.php +++ b/install/core/SystemHelper.php @@ -76,7 +76,7 @@ class SystemHelper extends \Espo\Core\Utils\System return $result; } - public function checkDbConnection($hostName, $port ,$dbUserName, $dbUserPass, $dbName, $dbDriver = 'pdo_mysql') + public function checkDbConnection($hostName, $port, $dbUserName, $dbUserPass, $dbName, $dbDriver = 'pdo_mysql', $isCreateDatabase = true) { $result['success'] = true; @@ -104,6 +104,28 @@ class SystemHelper extends \Espo\Core\Utils\System $result['errors']['dbConnect']['errorMsg'] = $e->getMessage(); $result['success'] = false; } + + /** try to create a database */ + if ($isCreateDatabase && !$result['success'] && $result['errors']['dbConnect']['errorCode'] == '1049') { + + $dsn = "mysql:host={$hostName};" . ((!empty($port)) ? "port={$port}" : ''); + $pdo = new PDO($dsn, $dbUserName, $dbUserPass); + + $isCreated = true; + try { + $pdo->query("CREATE DATABASE IF NOT EXISTS `$dbName`"); + } catch (PDOException $e) { + $isCreated = false; + } + + if ($isCreated) { + return $this->checkDbConnection($hostName, $port, $dbUserName, $dbUserPass, $dbName, $dbDriver, false); + } + } + /** END: try to create a database */ + + + break; } @@ -185,8 +207,8 @@ class SystemHelper extends \Espo\Core\Utils\System $commands[] = $this->getCd(); } - $commands[] = 'find '.$path.' -type f -exec ' .$sudoStr.'chmod '.$bufPerm[0].' {} +'; - $commands[] = 'find '.$path.' -type d -exec ' .$sudoStr. 'chmod '.$bufPerm[1].' {} +'; + $commands[] = 'find '.$path.' -type f -exec ' .$sudoStr.'chmod '.$bufPerm[0].' {} +';//.'chmod '.$bufPerm[0].' $(find '.$path.' -type f)'; + $commands[] = 'find '.$path.' -type d -exec ' .$sudoStr. 'chmod '.$bufPerm[1].' {} +';//.'chmod '.$bufPerm[1].' $(find '.$path.' -type d)'; if (count($permissions) >= 2) { return implode(' ' . $this->combineOperator . ' ', $commands);