Test Failed
Push — CI ( 02428e...3e0292 )
by Adam
55:43
created

InstallCommand::setupSugarSessionVars()   B

Complexity

Conditions 4
Paths 2

Size

Total Lines 30
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 30
rs 8.5806
cc 4
eloc 21
nc 2
nop 1
1
<?php
2
/**
3
 * Created by Adam Jakab.
4
 * Date: 08/03/16
5
 * Time: 9.03
6
 */
7
8
namespace SuiteCrm\Install;
9
10
use SuiteCrm\Command\Command;
11
use SuiteCrm\Command\CommandInterface;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
use Symfony\Component\Filesystem\Filesystem;
16
17
class InstallCommand extends Command implements CommandInterface
18
{
19
    const COMMAND_NAME = 'app:install';
20
    const COMMAND_DESCRIPTION = 'Install the SuiteCrm application';
21
22
    /** @var bool */
23
    private $logToConsole = TRUE;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
24
25
    public function __construct() {
26
        $this->enableConsoleLogging($this->logToConsole);
27
        parent::__construct(NULL);
28
    }
29
30
    /**
31
     * Configure command
32
     */
33
    protected function configure() {
34
        $this->setName(static::COMMAND_NAME);
35
        $this->setDescription(static::COMMAND_DESCRIPTION);
36
    }
37
38
    /**
39
     * @param InputInterface $input
40
     * @param OutputInterface $output
41
     * @return bool
42
     */
43
    protected function execute(InputInterface $input, OutputInterface $output) {
44
        parent::_execute($input, $output);
45
        $this->log("Starting command " . static::COMMAND_NAME . "...");
46
        $this->doPhpVersionCheck();
47
        $this->setupSugarGlobals();
48
        $this->setupSugarSessionVars([]);
49
        $this->setupSugarLogger();
50
        $this->executeInstallation();
51
52
53
54
        $this->log("Command " . static::COMMAND_NAME . " done.");
55
    }
56
57
58
    /**
59
     *
60
     */
61
    protected function executeInstallation() {
62
        define('sugarEntry', true);
63
        //require_once(PROJECT_ROOT . '/include/SugarLogger/LoggerManager.php');
64
        require_once(PROJECT_ROOT . '/sugar_version.php');
65
        require_once(PROJECT_ROOT . '/suitecrm_version.php');
66
        require_once(PROJECT_ROOT . '/include/utils.php');
67
        require_once(PROJECT_ROOT . '/install/install_utils.php');
68
        require_once(PROJECT_ROOT . '/install/install_defaults.php');
69
        require_once(PROJECT_ROOT . '/include/TimeDate.php');
70
        require_once(PROJECT_ROOT . '/include/Localization/Localization.php');
71
        require_once(PROJECT_ROOT . '/include/SugarTheme/SugarTheme.php');
72
        require_once(PROJECT_ROOT . '/include/utils/LogicHook.php');
73
        require_once(PROJECT_ROOT . '/data/SugarBean.php');
74
        require_once(PROJECT_ROOT . '/include/entryPoint.php');
75
        //
76
        $timedate = \TimeDate::getInstance();
77
        setPhpIniSettings();
78
        $locale = new \Localization();
79
        /** @var  string $suitecrm_version */
80
        $setup_sugar_version = $suitecrm_version;
81
        $install_script = true;
82
        $current_language = 'en_us';
83
84
        SystemChecker::runChecks();
85
        DatabaseChecker::runChecks();
86
87
88
        $this->log("SESSION VARS: " . json_encode($_SESSION));
89
90
    }
91
92
93
    /**
94
     *  Set up a custom logger for the installation
95
     */
96
    protected function setupSugarLogger() {
97
        $GLOBALS['log'] = new LoggerManager($this->cmdOutput, 'debug');
98
    }
99
100
    /**
101
     * Setup Session variables prior to executing installation
102
     *
103
     * @param array $data
104
     */
105
    protected function setupSugarSessionVars($data) {
106
        if((function_exists('session_status') && session_status() == PHP_SESSION_NONE) || session_id() == '') {
107
            session_start();
108
        }
109
        //$_SESSION['setup_db_type'], array("db_manager" => $_SESSION['setup_db_manager'])
110
111
        $databaseConfigData = [
112
            /*BASIC*/
113
            'setup_db_type' => 'mysql',
114
            'setup_db_admin_user_name' => 'jack',
115
            'setup_db_admin_user_password' => '02203505',
116
            'setup_db_database_name' => 'suitecrm_bradipo_tests',
117
            'setup_db_host_name' => 'localhost',
118
            'setup_db_port_num' => '',
119
            'setup_db_host_instance' => '',//SQLEXPRESS
120
            'setup_db_manager' => '',//'MysqliManager',
121
            /*FTS SUPPORT*/
122
            'setup_fts_type' => '',
123
            'setup_fts_host' => '',
124
            'setup_fts_port' => '',
125
            /* INTERNAL */
126
            'setup_db_create_sugarsales_user' => false,
127
            'setup_db_create_database' => false,
128
            'setup_db_drop_tables' => false,
129
            'demoData' => 'no',
130
        ];
131
132
        $data = array_merge_recursive($data, $databaseConfigData);
133
        $_SESSION = array_merge_recursive($_SESSION, $data);
134
    }
135
136
    /**
137
     * Setup Globals prior to requiring Sugar application files
138
     */
139
    protected function setupSugarGlobals() {
140
        $GLOBALS['installing'] = true;
141
        define('SUGARCRM_IS_INSTALLING', $GLOBALS['installing']);
142
143
        $GLOBALS['sql_queries'] = 0;
144
145
    }
146
147
    /**
148
     * @throws \Exception
149
     */
150
    protected function doPhpVersionCheck() {
151
        if (version_compare(phpversion(),'5.2.0') < 0) {
152
            throw new \Exception('Minimum PHP version required is 5.2.0.  You are using PHP version  '. phpversion());
153
        }
154
    }
155
}