Conditions | 6 |
Paths | 8 |
Total Lines | 84 |
Code Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
55 | public function execute(InputInterface $input, OutputInterface $output) |
||
56 | { |
||
57 | // check if installation is locked |
||
58 | if (File::exist('/Private/Install/install.lock')) { |
||
59 | $output->writeln('Installation is locked! Please delete /Private/Install/install.lock'); |
||
60 | return; |
||
61 | } |
||
62 | // show license agreement |
||
63 | $license = File::read('/LICENSE'); |
||
64 | $output->write($license, PHP_EOL); |
||
65 | |||
66 | // check if user agree with license terms |
||
67 | if ($input->getOption('mit') !== 'yes') { |
||
68 | if (!$this->confirm('Are you accept this license terms?', false)) { |
||
69 | $output->writeln('You are deny license agreement, installation is rejected'); |
||
70 | return; |
||
71 | } |
||
72 | } |
||
73 | |||
74 | // read old & try to get newest configs |
||
75 | $configs = Console::$Properties->get('database'); |
||
76 | $newConfigs = []; |
||
77 | $newConfigs['driver'] = $this->optionOrAsk('driver', 'Database driver(mysql|pgsql)', 'mysql'); |
||
78 | $newConfigs['host'] = $this->optionOrAsk('host', 'Database host', '127.0.0.1'); |
||
79 | $newConfigs['username'] = $this->optionOrAsk('user', 'Database user', 'root'); |
||
80 | $newConfigs['password'] = $this->optionOrAsk('password', 'Database password', 'rootpwd'); |
||
81 | $newConfigs['database'] = $this->optionOrAsk('dbname', 'Database name', 'ffcms'); |
||
82 | $newConfigs['prefix'] = $this->optionOrAsk('prefix', 'Database table prefix', 'ffcms_'); |
||
83 | |||
84 | // merge configs and add new connection |
||
85 | $dbConf = Arr::merge($configs, $newConfigs); |
||
86 | Console::$Database->addConnection($dbConf, 'install'); |
||
87 | |||
88 | // check if connection is established |
||
89 | try { |
||
90 | Console::$Database->getConnection('install')->getPdo(); |
||
91 | } catch (\Exception $e) { |
||
92 | $output->writeln('Test database connection with new data is FAILED! Please, try to make it with right connection data'); |
||
93 | return; |
||
94 | } |
||
95 | |||
96 | $output->writeln('=== Merge migrations and prepare installation'); |
||
97 | |||
98 | // implement migrations |
||
99 | $migrationInstall = $this->getApplication()->find('migration:install'); |
||
100 | $migrationInstall->setDbConnection('install'); |
||
101 | $migrationInstall->run(new ArrayInput([]), $output); |
||
102 | |||
103 | $migrationManager = new MigrationsManager(null, 'install'); |
||
104 | $search = $migrationManager->search(null, false); |
||
105 | $migrationManager->makeUp($search); |
||
106 | |||
107 | // add system info about current install version |
||
108 | $system = new System(); |
||
109 | $system->setConnection('install'); |
||
110 | $system->var = 'version'; |
||
111 | $system->data = Version::VERSION; |
||
112 | $system->save(); |
||
113 | |||
114 | $email = $this->optionOrAsk('email', 'Website email', '[email protected]'); |
||
115 | $domain = $this->optionOrAsk('domain', 'Website domain', 'localhost.ltd'); |
||
116 | |||
117 | // save configurations to /Private/Default.php |
||
118 | $output->writeln('=== Writing configurations'); |
||
119 | $chmod = $this->getApplication()->find('main:chmod'); |
||
120 | $chmod->run(new ArrayInput([]), $output); |
||
121 | /** @var array $allCfg */ |
||
122 | $allCfg = Console::$Properties->getAll('default'); |
||
123 | $allCfg['database'] = $dbConf; |
||
124 | $allCfg['adminEmail'] = $email; |
||
125 | $allCfg['baseDomain'] = $domain; |
||
126 | $output->writeln('Generate security cookies for debug panel'); |
||
127 | $allCfg['debug']['cookie']['key'] = 'fdebug_' . Crypt::randomString(mt_rand(8, 32)); |
||
128 | $allCfg['debug']['cookie']['value'] = Crypt::randomString(mt_rand(32, 128)); |
||
129 | // write config data |
||
130 | $writeCfg = Console::$Properties->writeConfig('default', $allCfg); |
||
131 | if ($writeCfg !== true) { |
||
132 | $output->writeln('File /Private/Config/Default.php is unavailable to write data!'); |
||
133 | return; |
||
134 | } |
||
135 | File::write('/Private/Install/install.lock', 'Install is locked'); |
||
136 | $output->writeln('Congratulations! FFCMS are successful installed. Used version: ' . Version::VERSION . ' since ' . Version::DATE); |
||
137 | $output->writeln(''); |
||
138 | $output->writeln('> Please, use "php console.php main:adduser" to add admin account(set role=4) or you are unavailable to manage cms.'); |
||
139 | } |
||
141 | } |