Conditions | 36 |
Paths | > 20000 |
Total Lines | 253 |
Code Lines | 165 |
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 |
||
449 | private static function __install() |
||
450 | { |
||
451 | $fields = self::$POST['fields']; |
||
452 | $start = time(); |
||
453 | |||
454 | Symphony::Log()->writeToLog(PHP_EOL . '============================================', true); |
||
455 | Symphony::Log()->writeToLog('INSTALLATION PROCESS STARTED (' . DateTimeObj::get('c') . ')', true); |
||
456 | Symphony::Log()->writeToLog('============================================', true); |
||
457 | |||
458 | // MySQL: Establishing connection |
||
459 | Symphony::Log()->pushToLog('MYSQL: Establishing Connection', E_NOTICE, true, true); |
||
460 | |||
461 | try { |
||
462 | Symphony::Database()->connect( |
||
463 | $fields['database']['host'], |
||
464 | $fields['database']['user'], |
||
465 | $fields['database']['password'], |
||
466 | $fields['database']['port'], |
||
467 | $fields['database']['db'] |
||
468 | ); |
||
469 | } catch (DatabaseException $e) { |
||
470 | self::__abort( |
||
471 | 'There was a problem while trying to establish a connection to the MySQL server. Please check your settings.', |
||
472 | $start); |
||
473 | } |
||
474 | |||
475 | // MySQL: Setting prefix & character encoding |
||
476 | Symphony::Database()->setPrefix($fields['database']['tbl_prefix']); |
||
477 | Symphony::Database()->setCharacterEncoding(); |
||
478 | Symphony::Database()->setCharacterSet(); |
||
479 | |||
480 | // MySQL: Importing schema |
||
481 | Symphony::Log()->pushToLog('MYSQL: Importing Table Schema', E_NOTICE, true, true); |
||
482 | |||
483 | try { |
||
484 | Symphony::Database()->import(file_get_contents(INSTALL . '/includes/install.sql'), true); |
||
485 | } catch (DatabaseException $e) { |
||
486 | self::__abort( |
||
487 | 'There was an error while trying to import data to the database. MySQL returned: ' . $e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(), |
||
488 | $start); |
||
489 | } |
||
490 | |||
491 | // MySQL: Creating default author |
||
492 | Symphony::Log()->pushToLog('MYSQL: Creating Default Author', E_NOTICE, true, true); |
||
493 | |||
494 | try { |
||
495 | Symphony::Database()->insert(array( |
||
496 | 'id' => 1, |
||
497 | 'username' => Symphony::Database()->cleanValue($fields['user']['username']), |
||
498 | 'password' => Cryptography::hash(Symphony::Database()->cleanValue($fields['user']['password'])), |
||
499 | 'first_name' => Symphony::Database()->cleanValue($fields['user']['firstname']), |
||
500 | 'last_name' => Symphony::Database()->cleanValue($fields['user']['lastname']), |
||
501 | 'email' => Symphony::Database()->cleanValue($fields['user']['email']), |
||
502 | 'last_seen' => null, |
||
503 | 'user_type' => 'developer', |
||
504 | 'primary' => 'yes', |
||
505 | 'default_area' => '/blueprints/sections/', |
||
506 | 'auth_token_active' => 'no' |
||
507 | ), 'tbl_authors'); |
||
508 | } catch (DatabaseException $e) { |
||
509 | self::__abort( |
||
510 | 'There was an error while trying create the default author. MySQL returned: ' . $e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(), |
||
511 | $start); |
||
512 | } |
||
513 | |||
514 | // Configuration: Populating array |
||
515 | $conf = Symphony::Configuration()->get(); |
||
516 | |||
517 | if (!is_array($conf)) { |
||
518 | self::__abort('The configuration is not an array, can not continue', $start); |
||
519 | } |
||
520 | foreach ($conf as $group => $settings) { |
||
521 | if (!is_array($settings)) { |
||
522 | continue; |
||
523 | } |
||
524 | foreach ($settings as $key => $value) { |
||
525 | if (isset($fields[$group]) && isset($fields[$group][$key])) { |
||
526 | $conf[$group][$key] = $fields[$group][$key]; |
||
527 | } |
||
528 | } |
||
529 | } |
||
530 | |||
531 | // Create manifest folder structure |
||
532 | Symphony::Log()->pushToLog('WRITING: Creating ‘manifest’ folder (/manifest)', E_NOTICE, true, true); |
||
533 | if (!General::realiseDirectory(MANIFEST, $conf['directory']['write_mode'])) { |
||
534 | self::__abort( |
||
535 | 'Could not create ‘manifest’ directory. Check permission on the root folder.', |
||
536 | $start); |
||
537 | } |
||
538 | |||
539 | Symphony::Log()->pushToLog('WRITING: Creating ‘logs’ folder (/manifest/logs)', E_NOTICE, true, true); |
||
540 | if (!General::realiseDirectory(LOGS, $conf['directory']['write_mode'])) { |
||
541 | self::__abort( |
||
542 | 'Could not create ‘logs’ directory. Check permission on /manifest.', |
||
543 | $start); |
||
544 | } |
||
545 | |||
546 | Symphony::Log()->pushToLog('WRITING: Creating ‘cache’ folder (/manifest/cache)', E_NOTICE, true, true); |
||
547 | if (!General::realiseDirectory(CACHE, $conf['directory']['write_mode'])) { |
||
548 | self::__abort( |
||
549 | 'Could not create ‘cache’ directory. Check permission on /manifest.', |
||
550 | $start); |
||
551 | } |
||
552 | |||
553 | Symphony::Log()->pushToLog('WRITING: Creating ‘tmp’ folder (/manifest/tmp)', E_NOTICE, true, true); |
||
554 | if (!General::realiseDirectory(MANIFEST . '/tmp', $conf['directory']['write_mode'])) { |
||
555 | self::__abort( |
||
556 | 'Could not create ‘tmp’ directory. Check permission on /manifest.', |
||
557 | $start); |
||
558 | } |
||
559 | |||
560 | // Writing configuration file |
||
561 | Symphony::Log()->pushToLog('WRITING: Configuration File', E_NOTICE, true, true); |
||
562 | |||
563 | Symphony::Configuration()->setArray($conf); |
||
564 | |||
565 | if (!Symphony::Configuration()->write(CONFIG, $conf['file']['write_mode'])) { |
||
566 | self::__abort( |
||
567 | 'Could not create config file ‘' . CONFIG . '’. Check permission on /manifest.', |
||
568 | $start); |
||
569 | } |
||
570 | |||
571 | // Writing htaccess file |
||
572 | Symphony::Log()->pushToLog('CONFIGURING: Frontend', E_NOTICE, true, true); |
||
573 | |||
574 | $rewrite_base = ltrim(preg_replace('/\/install$/i', null, dirname($_SERVER['PHP_SELF'])), '/'); |
||
575 | $htaccess = str_replace( |
||
576 | '<!-- REWRITE_BASE -->', $rewrite_base, |
||
577 | file_get_contents(INSTALL . '/includes/htaccess.txt') |
||
578 | ); |
||
579 | |||
580 | if (!General::writeFile(DOCROOT . "/.htaccess", $htaccess, $conf['file']['write_mode'], 'a')) { |
||
581 | self::__abort( |
||
582 | 'Could not write ‘.htaccess’ file. Check permission on ' . DOCROOT, |
||
583 | $start); |
||
584 | } |
||
585 | |||
586 | // Writing /workspace folder |
||
587 | if (!is_dir(DOCROOT . '/workspace')) { |
||
588 | // Create workspace folder structure |
||
589 | Symphony::Log()->pushToLog('WRITING: Creating ‘workspace’ folder (/workspace)', E_NOTICE, true, true); |
||
590 | if (!General::realiseDirectory(WORKSPACE, $conf['directory']['write_mode'])) { |
||
591 | self::__abort( |
||
592 | 'Could not create ‘workspace’ directory. Check permission on the root folder.', |
||
593 | $start); |
||
594 | } |
||
595 | |||
596 | Symphony::Log()->pushToLog('WRITING: Creating ‘data-sources’ folder (/workspace/data-sources)', E_NOTICE, true, true); |
||
597 | if (!General::realiseDirectory(DATASOURCES, $conf['directory']['write_mode'])) { |
||
598 | self::__abort( |
||
599 | 'Could not create ‘workspace/data-sources’ directory. Check permission on the root folder.', |
||
600 | $start); |
||
601 | } |
||
602 | |||
603 | Symphony::Log()->pushToLog('WRITING: Creating ‘events’ folder (/workspace/events)', E_NOTICE, true, true); |
||
604 | if (!General::realiseDirectory(EVENTS, $conf['directory']['write_mode'])) { |
||
605 | self::__abort( |
||
606 | 'Could not create ‘workspace/events’ directory. Check permission on the root folder.', |
||
607 | $start); |
||
608 | } |
||
609 | |||
610 | Symphony::Log()->pushToLog('WRITING: Creating ‘pages’ folder (/workspace/pages)', E_NOTICE, true, true); |
||
611 | if (!General::realiseDirectory(PAGES, $conf['directory']['write_mode'])) { |
||
612 | self::__abort( |
||
613 | 'Could not create ‘workspace/pages’ directory. Check permission on the root folder.', |
||
614 | $start); |
||
615 | } |
||
616 | |||
617 | Symphony::Log()->pushToLog('WRITING: Creating ‘utilities’ folder (/workspace/utilities)', E_NOTICE, true, true); |
||
618 | if (!General::realiseDirectory(UTILITIES, $conf['directory']['write_mode'])) { |
||
619 | self::__abort( |
||
620 | 'Could not create ‘workspace/utilities’ directory. Check permission on the root folder.', |
||
621 | $start); |
||
622 | } |
||
623 | } else { |
||
624 | Symphony::Log()->pushToLog('An existing ‘workspace’ directory was found at this location. Symphony will use this workspace.', E_NOTICE, true, true); |
||
625 | |||
626 | // MySQL: Importing workspace data |
||
627 | Symphony::Log()->pushToLog('MYSQL: Importing Workspace Data...', E_NOTICE, true, true); |
||
628 | |||
629 | if (is_file(WORKSPACE . '/install.sql')) { |
||
630 | try { |
||
631 | Symphony::Database()->import( |
||
632 | file_get_contents(WORKSPACE . '/install.sql'), |
||
633 | true |
||
634 | ); |
||
635 | } catch (DatabaseException $e) { |
||
636 | self::__abort( |
||
637 | 'There was an error while trying to import data to the database. MySQL returned: ' . $e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(), |
||
638 | $start); |
||
639 | } |
||
640 | } |
||
641 | } |
||
642 | |||
643 | // Write extensions folder |
||
644 | if (!is_dir(EXTENSIONS)) { |
||
645 | // Create extensions folder |
||
646 | Symphony::Log()->pushToLog('WRITING: Creating ‘extensions’ folder (/extensions)', E_NOTICE, true, true); |
||
647 | if (!General::realiseDirectory(EXTENSIONS, $conf['directory']['write_mode'])) { |
||
648 | self::__abort( |
||
649 | 'Could not create ‘extension’ directory. Check permission on the root folder.', |
||
650 | $start); |
||
651 | } |
||
652 | } |
||
653 | |||
654 | // Install existing extensions |
||
655 | Symphony::Log()->pushToLog('CONFIGURING: Installing existing extensions', E_NOTICE, true, true); |
||
656 | $disabled_extensions = array(); |
||
657 | foreach (new DirectoryIterator(EXTENSIONS) as $e) { |
||
658 | if ($e->isDot() || $e->isFile() || !is_file($e->getRealPath() . '/extension.driver.php')) { |
||
659 | continue; |
||
660 | } |
||
661 | |||
662 | $handle = $e->getBasename(); |
||
663 | try { |
||
664 | if (!ExtensionManager::enable($handle)) { |
||
665 | $disabled_extensions[] = $handle; |
||
666 | Symphony::Log()->pushToLog('Could not enable the extension ‘' . $handle . '’.', E_NOTICE, true, true); |
||
667 | } |
||
668 | } catch (Exception $ex) { |
||
669 | $disabled_extensions[] = $handle; |
||
670 | Symphony::Log()->pushToLog('Could not enable the extension ‘' . $handle . '’. '. $ex->getMessage(), E_NOTICE, true, true); |
||
671 | } |
||
672 | } |
||
673 | |||
674 | // Loading default language |
||
675 | if (isset($_REQUEST['lang']) && $_REQUEST['lang'] != 'en') { |
||
676 | Symphony::Log()->pushToLog('CONFIGURING: Default language', E_NOTICE, true, true); |
||
677 | |||
678 | $language = Lang::Languages(); |
||
679 | $language = $language[$_REQUEST['lang']]; |
||
680 | |||
681 | // Is the language extension enabled? |
||
682 | if (in_array('lang_' . $language['handle'], ExtensionManager::listInstalledHandles())) { |
||
683 | Symphony::Configuration()->set('lang', $_REQUEST['lang'], 'symphony'); |
||
684 | if (!Symphony::Configuration()->write(CONFIG, $conf['file']['write_mode'])) { |
||
685 | Symphony::Log()->pushToLog('Could not write default language ‘' . $language['name'] . '’ to config file.', E_NOTICE, true, true); |
||
686 | } |
||
687 | } else { |
||
688 | Symphony::Log()->pushToLog('Could not enable the desired language ‘' . $language['name'] . '’.', E_NOTICE, true, true); |
||
689 | } |
||
690 | } |
||
691 | |||
692 | // Installation completed. Woo-hoo! |
||
693 | Symphony::Log()->writeToLog('============================================', true); |
||
694 | Symphony::Log()->writeToLog(sprintf('INSTALLATION COMPLETED: Execution Time - %d sec (%s)', |
||
695 | max(1, time() - $start), |
||
696 | date('d.m.y H:i:s') |
||
697 | ), true); |
||
698 | Symphony::Log()->writeToLog('============================================' . PHP_EOL . PHP_EOL . PHP_EOL, true); |
||
699 | |||
700 | return $disabled_extensions; |
||
701 | } |
||
702 | |||
712 |