| Conditions | 10 |
| Paths | 38 |
| Total Lines | 163 |
| Code Lines | 113 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 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 |
||
| 234 | private function make_install() { |
||
| 235 | $this->load->helper('file'); |
||
| 236 | $this->load->helper('url'); |
||
| 237 | |||
| 238 | $db_server = $this->input->post('db_host'); |
||
| 239 | $db_user = $this->input->post('db_user'); |
||
| 240 | $db_pass = $this->input->post('db_pass'); |
||
| 241 | $db_name = $this->input->post('db_name'); |
||
| 242 | |||
| 243 | $link = mysqli_connect($db_server, $db_user, $db_pass, $db_name); |
||
| 244 | |||
| 245 | // Drop all tables in DB |
||
| 246 | $tables = []; |
||
| 247 | $sql = "SHOW TABLES FROM $db_name"; |
||
| 248 | if ($result = mysqli_query($link, $sql)) { |
||
| 249 | while ($row = mysqli_fetch_row($result)) { |
||
| 250 | $tables[] = $row[0]; |
||
| 251 | } |
||
| 252 | } |
||
| 253 | |||
| 254 | if (count($tables) > 0) { |
||
| 255 | foreach ($tables as $t) { |
||
| 256 | $sql = "DROP TABLE `{$db_name}`.`{$t}`"; |
||
| 257 | if (!mysqli_query($link, $sql)) { |
||
| 258 | die("MySQL error. Can\'t delete `{$db_name}`.`{$t}`"); |
||
| 259 | } |
||
| 260 | } |
||
| 261 | } |
||
| 262 | |||
| 263 | mysqli_query($link, 'SET NAMES `utf8`'); |
||
| 264 | $sqlFileData = read_file(__DIR__ . '/' . $this->useSqlFile); |
||
| 265 | |||
| 266 | $queries = explode(";\n", str_replace(';\r\n', ';\n', $sqlFileData)); |
||
| 267 | |||
| 268 | foreach ($queries as $q) { |
||
| 269 | $q = trim($q); |
||
| 270 | |||
| 271 | if (!empty($q)) { |
||
| 272 | mysqli_query($link, $q); |
||
| 273 | } |
||
| 274 | } |
||
| 275 | |||
| 276 | // Update site title |
||
| 277 | mysqli_query($link, 'UPDATE `settings_i18n` SET `name`=\'' . mysqli_escape_string($link, $this->input->post('site_title')) . '\' '); |
||
| 278 | mysqli_query($link, 'UPDATE `settings_i18n` SET `short_name`=\'' . mysqli_escape_string($link, $this->input->post('site_title')) . '\' '); |
||
| 279 | mysqli_query($link, 'UPDATE `settings` SET `lang_sel`=\'' . mysqli_escape_string($link, $this->input->post('lang_sel')) . '\' '); |
||
| 280 | |||
| 281 | // TRUNCATE if "no demodata" checked |
||
| 282 | if ($this->input->post('product_samples') != 'on') { |
||
| 283 | mysqli_query($link, 'TRUNCATE `category`;'); |
||
| 284 | mysqli_query('INSERT INTO `category` (`id`, `name`, `url`, `per_page`, `order_by`) VALUES (\'1\', \'test\', \'test\', \'1\', \'publish_date\');', $link); |
||
| 285 | mysqli_query('UPDATE `settings` SET `main_type`=\'category\', `main_page_cat`=\'1\';', $link); |
||
| 286 | mysqli_query($link, 'TRUNCATE `comments`;'); |
||
| 287 | mysqli_query($link, 'TRUNCATE `content`;'); |
||
| 288 | mysqli_query($link, 'TRUNCATE `content_fields`;'); |
||
| 289 | mysqli_query($link, 'TRUNCATE `content_fields_data`;'); |
||
| 290 | mysqli_query($link, 'TRUNCATE `content_fields_groups_relations`;'); |
||
| 291 | mysqli_query($link, 'TRUNCATE `content_field_groups`;'); |
||
| 292 | mysqli_query($link, 'TRUNCATE `gallery_albums`;'); |
||
| 293 | mysqli_query($link, 'TRUNCATE `gallery_category`;'); |
||
| 294 | mysqli_query($link, 'TRUNCATE `gallery_images`;'); |
||
| 295 | mysqli_query($link, 'TRUNCATE `menus`;'); |
||
| 296 | mysqli_query($link, 'TRUNCATE `menus_data`;'); |
||
| 297 | mysqli_query($link, 'TRUNCATE `support_comments`;'); |
||
| 298 | mysqli_query($link, 'TRUNCATE `support_departments`;'); |
||
| 299 | mysqli_query($link, 'TRUNCATE `support_tickets`;'); |
||
| 300 | mysqli_query($link, 'TRUNCATE `tags`;'); |
||
| 301 | mysqli_query($link, 'TRUNCATE `content_permissions`;'); |
||
| 302 | mysqli_query($link, 'TRUNCATE `content_tags`;'); |
||
| 303 | mysqli_query($link, 'TRUNCATE `logs`;'); |
||
| 304 | |||
| 305 | $this->load->helper('file'); |
||
| 306 | |||
| 307 | if (moduleExists('shop')) { |
||
| 308 | delete_files('./uploads/shop', TRUE); |
||
| 309 | |||
| 310 | mysqli_query('UPDATE `settings` SET `main_type`=\'module\', `main_page_module`=\'shop\';', $link); |
||
| 311 | mysqli_query($link, 'TRUNCATE `shop_category`;'); |
||
| 312 | mysqli_query($link, 'TRUNCATE `shop_category_i18n`;'); |
||
| 313 | mysqli_query($link, 'TRUNCATE `shop_comulativ_discount`;'); |
||
| 314 | mysqli_query($link, 'TRUNCATE `shop_discounts`;'); |
||
| 315 | mysqli_query($link, 'TRUNCATE `shop_gifts`;'); |
||
| 316 | mysqli_query($link, 'TRUNCATE `shop_kit`;'); |
||
| 317 | mysqli_query($link, 'TRUNCATE `shop_kit_product`;'); |
||
| 318 | mysqli_query($link, 'TRUNCATE `shop_notifications`;'); |
||
| 319 | mysqli_query($link, 'TRUNCATE `shop_notification_statuses`;'); |
||
| 320 | mysqli_query($link, 'TRUNCATE `shop_notification_statuses_i18n`;'); |
||
| 321 | mysqli_query($link, 'TRUNCATE `shop_orders`;'); |
||
| 322 | mysqli_query($link, 'TRUNCATE `shop_orders_products`;'); |
||
| 323 | mysqli_query($link, 'TRUNCATE `shop_orders_status_history`;'); |
||
| 324 | mysqli_query($link, 'TRUNCATE `shop_products`;'); |
||
| 325 | mysqli_query($link, 'TRUNCATE `shop_products_i18n`;'); |
||
| 326 | mysqli_query($link, 'TRUNCATE `shop_product_categories`;'); |
||
| 327 | mysqli_query($link, 'TRUNCATE `shop_product_images`;'); |
||
| 328 | mysqli_query($link, 'TRUNCATE `shop_product_properties`;'); |
||
| 329 | mysqli_query($link, 'TRUNCATE `shop_product_properties`;'); |
||
| 330 | mysqli_query($link, 'TRUNCATE `shop_product_properties_categories`;'); |
||
| 331 | mysqli_query($link, 'TRUNCATE `shop_product_properties_data`;'); |
||
| 332 | mysqli_query($link, 'TRUNCATE `shop_product_properties_data_i18n`;'); |
||
| 333 | mysqli_query($link, 'TRUNCATE `shop_product_properties_i18n`;'); |
||
| 334 | mysqli_query($link, 'TRUNCATE `shop_product_variants`;'); |
||
| 335 | mysqli_query($link, 'TRUNCATE `shop_product_variants_i18n`;'); |
||
| 336 | mysqli_query($link, 'TRUNCATE `shop_banners`;'); |
||
| 337 | mysqli_query($link, 'TRUNCATE `shop_banners_i18n`;'); |
||
| 338 | mysqli_query($link, 'TRUNCATE `shop_brands`;'); |
||
| 339 | mysqli_query($link, 'TRUNCATE `shop_brands_i18n`;'); |
||
| 340 | mysqli_query($link, 'TRUNCATE `shop_spy`;'); |
||
| 341 | mysqli_query($link, 'TRUNCATE `shop_warehouse`;'); |
||
| 342 | mysqli_query($link, 'TRUNCATE `shop_warehouse_data`;'); |
||
| 343 | } |
||
| 344 | |||
| 345 | delete_files('./uploads/gallery', TRUE); |
||
| 346 | delete_files('./uploads/images', TRUE); |
||
| 347 | } |
||
| 348 | |||
| 349 | $this->writeDatabaseConfig( |
||
| 350 | [ |
||
| 351 | 'hostname' => $this->input->post('db_host'), |
||
| 352 | 'username' => $this->input->post('db_user'), |
||
| 353 | 'password' => $this->input->post('db_pass'), |
||
| 354 | 'database' => $this->input->post('db_name'), |
||
| 355 | ] |
||
| 356 | ); |
||
| 357 | |||
| 358 | $this->writeCmsConfig( |
||
| 359 | ['is_installed' => 'TRUE'] |
||
| 360 | ); |
||
| 361 | |||
| 362 | $this->load->database(); |
||
| 363 | |||
| 364 | // Create admin account |
||
| 365 | $this->load->helper('cookie'); |
||
| 366 | delete_cookie('autologin'); |
||
| 367 | $this->load->library('DX_Auth'); |
||
| 368 | $admin_pass = crypt($this->dx_auth->_encode($this->input->post('admin_pass'))); |
||
| 369 | |||
| 370 | // $admin_login = $this->input->post('admin_login'); |
||
| 371 | $admin_mail = $this->input->post('admin_mail'); |
||
| 372 | |||
| 373 | $admin_created = date('Y-m-d H:i:s', time()); |
||
| 374 | |||
| 375 | $sql = "INSERT INTO `users` (`id`, `role_id`, `username`, `password`, `email`, `banned`, `ban_reason`, `newpass`, `newpass_key`, `newpass_time`, `last_ip`, `last_login`, `created`, `modified`) |
||
| 376 | VALUES (1, 1, 'Administrator', '$admin_pass', '$admin_mail', 0, NULL, NULL, NULL, NULL, '127.0.0.1', '0000-00-00 00:00:00', '$admin_created', '0000-00-00 00:00:00'); "; |
||
| 377 | |||
| 378 | mysqli_query($link, $sql); |
||
| 379 | |||
| 380 | $this->cache->delete_all(); |
||
| 381 | |||
| 382 | $this->writeDatabaseConfig( |
||
| 383 | [ |
||
| 384 | 'hostname' => $this->input->post('db_host'), |
||
| 385 | 'username' => $this->input->post('db_user'), |
||
| 386 | 'password' => $this->input->post('db_pass'), |
||
| 387 | 'database' => $this->input->post('db_name'), |
||
| 388 | ] |
||
| 389 | ); |
||
| 390 | |||
| 391 | // login admin |
||
| 392 | $this->dx_auth->login($this->input->post('admin_login'), $this->input->post('admin_pass'), true); |
||
| 393 | |||
| 394 | //redirect('install/done','refresh'); |
||
| 395 | header('Location: ' . $this->host . '/install/done'); |
||
| 396 | } |
||
| 397 | |||
| 502 | } |