Conditions | 34 |
Paths | > 20000 |
Total Lines | 238 |
Code Lines | 152 |
Lines | 8 |
Ratio | 3.36 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
388 | private static function __install() |
||
389 | { |
||
390 | $fields = $_POST['fields']; |
||
391 | $start = time(); |
||
392 | |||
393 | Symphony::Log()->info('INSTALLATION PROCESS STARTED (' . DateTimeObj::get('c') . ')'); |
||
394 | |||
395 | // MySQL: Establishing connection |
||
396 | Symphony::Log()->info('MYSQL: Establishing Connection'); |
||
397 | |||
398 | try { |
||
399 | Symphony::Database()->connect( |
||
400 | $fields['database']['host'], |
||
401 | $fields['database']['user'], |
||
402 | $fields['database']['password'], |
||
403 | $fields['database']['port'], |
||
404 | $fields['database']['db'] |
||
405 | ); |
||
406 | } catch (DatabaseException $e) { |
||
407 | self::__abort( |
||
408 | 'There was a problem while trying to establish a connection to the MySQL server. Please check your settings.', |
||
409 | $start); |
||
410 | } |
||
411 | |||
412 | // MySQL: Setting prefix & character encoding |
||
413 | Symphony::Database()->setPrefix($fields['database']['tbl_prefix']); |
||
414 | |||
415 | // MySQL: Importing schema |
||
416 | Symphony::Log()->info('MYSQL: Importing Table Schema'); |
||
417 | |||
418 | try { |
||
419 | Symphony::Database()->import(file_get_contents(INSTALL . '/includes/install.sql')); |
||
420 | } catch (DatabaseException $e) { |
||
421 | self::__abort( |
||
422 | 'There was an error while trying to import data to the database. MySQL returned: ' . $e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(), |
||
423 | $start); |
||
424 | } |
||
425 | |||
426 | // MySQL: Creating default author |
||
427 | Symphony::Log()->info('MYSQL: Creating Default Author'); |
||
428 | |||
429 | try { |
||
430 | Symphony::Database()->insert(array( |
||
431 | 'id' => 1, |
||
432 | 'username' => Symphony::Database()->cleanValue($fields['user']['username']), |
||
433 | 'password' => Cryptography::hash(Symphony::Database()->cleanValue($fields['user']['password'])), |
||
434 | 'first_name' => Symphony::Database()->cleanValue($fields['user']['firstname']), |
||
435 | 'last_name' => Symphony::Database()->cleanValue($fields['user']['lastname']), |
||
436 | 'email' => Symphony::Database()->cleanValue($fields['user']['email']), |
||
437 | 'last_seen' => null, |
||
438 | 'user_type' => 'developer', |
||
439 | 'primary' => 'yes', |
||
440 | 'default_area' => null, |
||
441 | 'auth_token_active' => 'no' |
||
442 | ), 'tbl_authors'); |
||
443 | } catch (DatabaseException $e) { |
||
444 | self::__abort( |
||
445 | 'There was an error while trying create the default author. MySQL returned: ' . $e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(), |
||
446 | $start); |
||
447 | } |
||
448 | |||
449 | // Configuration: Populating array |
||
450 | $conf = Symphony::Configuration()->get(); |
||
451 | |||
452 | foreach ($conf as $group => $settings) { |
||
453 | foreach ($settings as $key => $value) { |
||
454 | if (isset($fields[$group]) && isset($fields[$group][$key])) { |
||
455 | $conf[$group][$key] = $fields[$group][$key]; |
||
456 | } |
||
457 | } |
||
458 | } |
||
459 | |||
460 | // Create manifest folder structure |
||
461 | Symphony::Log()->info('WRITING: Creating ‘manifest’ folder (/manifest)'); |
||
462 | if (!General::realiseDirectory(MANIFEST, $conf['directory']['write_mode'])) { |
||
463 | self::__abort( |
||
464 | 'Could not create ‘manifest’ directory. Check permission on the root folder.', |
||
465 | $start); |
||
466 | } |
||
467 | |||
468 | Symphony::Log()->info('WRITING: Creating ‘logs’ folder (/manifest/logs)'); |
||
469 | if (!General::realiseDirectory(LOGS, $conf['directory']['write_mode'])) { |
||
470 | self::__abort( |
||
471 | 'Could not create ‘logs’ directory. Check permission on /manifest.', |
||
472 | $start); |
||
473 | } |
||
474 | |||
475 | Symphony::Log()->info('WRITING: Creating ‘cache’ folder (/manifest/cache)'); |
||
476 | if (!General::realiseDirectory(CACHE, $conf['directory']['write_mode'])) { |
||
477 | self::__abort( |
||
478 | 'Could not create ‘cache’ directory. Check permission on /manifest.', |
||
479 | $start); |
||
480 | } |
||
481 | |||
482 | Symphony::Log()->info('WRITING: Creating ‘tmp’ folder (/manifest/tmp)'); |
||
483 | if (!General::realiseDirectory(MANIFEST . '/tmp', $conf['directory']['write_mode'])) { |
||
484 | self::__abort( |
||
485 | 'Could not create ‘tmp’ directory. Check permission on /manifest.', |
||
486 | $start); |
||
487 | } |
||
488 | |||
489 | // Writing configuration file |
||
490 | Symphony::Log()->info('WRITING: Configuration File'); |
||
491 | |||
492 | Symphony::Configuration()->setArray($conf); |
||
493 | |||
494 | View Code Duplication | if (!Symphony::Configuration()->write(CONFIG, $conf['file']['write_mode'])) { |
|
495 | self::__abort( |
||
496 | 'Could not create config file ‘' . CONFIG . '’. Check permission on /manifest.', |
||
497 | $start); |
||
498 | } |
||
499 | |||
500 | // Writing htaccess file |
||
501 | Symphony::Log()->info('CONFIGURING: Frontend', E_NOTICE); |
||
502 | |||
503 | $rewrite_base = ltrim(preg_replace('/\/install$/i', null, dirname($_SERVER['PHP_SELF'])), '/'); |
||
504 | $htaccess = str_replace( |
||
505 | '<!-- REWRITE_BASE -->', $rewrite_base, |
||
506 | file_get_contents(INSTALL . '/includes/htaccess.txt') |
||
507 | ); |
||
508 | |||
509 | if (!General::writeFile(DOCROOT . "/.htaccess", $htaccess, $conf['file']['write_mode'], 'a')) { |
||
510 | self::__abort( |
||
511 | 'Could not write ‘.htaccess’ file. Check permission on ' . DOCROOT, |
||
512 | $start); |
||
513 | } |
||
514 | |||
515 | // Writing /workspace folder |
||
516 | if (!is_dir(DOCROOT . '/workspace')) { |
||
517 | // Create workspace folder structure |
||
518 | Symphony::Log()->info('WRITING: Creating ‘workspace’ folder (/workspace)'); |
||
519 | if (!General::realiseDirectory(WORKSPACE, $conf['directory']['write_mode'])) { |
||
520 | self::__abort( |
||
521 | 'Could not create ‘workspace’ directory. Check permission on the root folder.', |
||
522 | $start); |
||
523 | } |
||
524 | |||
525 | Symphony::Log()->info('WRITING: Creating ‘data-sources’ folder (/workspace/data-sources)'); |
||
526 | if (!General::realiseDirectory(DATASOURCES, $conf['directory']['write_mode'])) { |
||
527 | self::__abort( |
||
528 | 'Could not create ‘workspace/data-sources’ directory. Check permission on the root folder.', |
||
529 | $start); |
||
530 | } |
||
531 | |||
532 | Symphony::Log()->info('WRITING: Creating ‘events’ folder (/workspace/events)'); |
||
533 | if (!General::realiseDirectory(EVENTS, $conf['directory']['write_mode'])) { |
||
534 | self::__abort( |
||
535 | 'Could not create ‘workspace/events’ directory. Check permission on the root folder.', |
||
536 | $start); |
||
537 | } |
||
538 | |||
539 | Symphony::Log()->info('WRITING: Creating ‘pages’ folder (/workspace/pages)'); |
||
540 | if (!General::realiseDirectory(PAGES, $conf['directory']['write_mode'])) { |
||
541 | self::__abort( |
||
542 | 'Could not create ‘workspace/pages’ directory. Check permission on the root folder.', |
||
543 | $start); |
||
544 | } |
||
545 | |||
546 | Symphony::Log()->info('WRITING: Creating ‘utilities’ folder (/workspace/utilities)'); |
||
547 | if (!General::realiseDirectory(UTILITIES, $conf['directory']['write_mode'])) { |
||
548 | self::__abort( |
||
549 | 'Could not create ‘workspace/utilities’ directory. Check permission on the root folder.', |
||
550 | $start); |
||
551 | } |
||
552 | } else { |
||
553 | Symphony::Log()->info('An existing ‘workspace’ directory was found at this location. Symphony will use this workspace.'); |
||
554 | |||
555 | // MySQL: Importing workspace data |
||
556 | Symphony::Log()->info('MYSQL: Importing Workspace Data...'); |
||
557 | |||
558 | if (is_file(WORKSPACE . '/install.sql')) { |
||
559 | try { |
||
560 | Symphony::Database()->import(file_get_contents(WORKSPACE . '/install.sql')); |
||
561 | } catch (DatabaseException $e) { |
||
562 | self::__abort( |
||
563 | 'There was an error while trying to import data to the database. MySQL returned: ' . $e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(), |
||
564 | $start); |
||
565 | } |
||
566 | } |
||
567 | } |
||
568 | |||
569 | // Write extensions folder |
||
570 | if (!is_dir(EXTENSIONS)) { |
||
571 | // Create extensions folder |
||
572 | Symphony::Log()->info('WRITING: Creating ‘extensions’ folder (/extensions)'); |
||
573 | if (!General::realiseDirectory(EXTENSIONS, $conf['directory']['write_mode'])) { |
||
574 | self::__abort( |
||
575 | 'Could not create ‘extension’ directory. Check permission on the root folder.', |
||
576 | $start); |
||
577 | } |
||
578 | } |
||
579 | |||
580 | // Install existing extensions |
||
581 | Symphony::Log()->info('CONFIGURING: Installing existing extensions'); |
||
582 | $disabled_extensions = array(); |
||
583 | foreach (new DirectoryIterator(EXTENSIONS) as $e) { |
||
584 | if ($e->isDot() || $e->isFile() || !is_file($e->getRealPath() . '/extension.driver.php')) { |
||
585 | continue; |
||
586 | } |
||
587 | |||
588 | $handle = $e->getBasename(); |
||
589 | try { |
||
590 | if (!ExtensionManager::enable($handle)) { |
||
591 | $disabled_extensions[] = $handle; |
||
592 | Symphony::Log()->warning('Could not enable the extension ‘' . $handle . '’.'); |
||
593 | } |
||
594 | } catch (Exception $ex) { |
||
595 | $disabled_extensions[] = $handle; |
||
596 | Symphony::Log()->warning('Could not enable the extension ‘' . $handle . '’. '. $ex->getMessage()); |
||
597 | } |
||
598 | } |
||
599 | |||
600 | // Loading default language |
||
601 | if (isset($_REQUEST['lang']) && $_REQUEST['lang'] != 'en') { |
||
602 | Symphony::Log()->info('CONFIGURING: Default language'); |
||
603 | |||
604 | $language = Lang::Languages(); |
||
605 | $language = $language[$_REQUEST['lang']]; |
||
606 | |||
607 | // Is the language extension enabled? |
||
608 | if (in_array('lang_' . $language['handle'], ExtensionManager::listInstalledHandles())) { |
||
609 | Symphony::Configuration()->set('lang', $_REQUEST['lang'], 'symphony'); |
||
610 | View Code Duplication | if (!Symphony::Configuration()->write(CONFIG, $conf['file']['write_mode'])) { |
|
611 | Symphony::Log()->warning('Could not write default language ‘' . $language['name'] . '’ to config file.'); |
||
612 | } |
||
613 | } else { |
||
614 | Symphony::Log()->warning('Could not enable the desired language ‘' . $language['name'] . '’.'); |
||
615 | } |
||
616 | } |
||
617 | |||
618 | // Installation completed. Woo-hoo! |
||
619 | Symphony::Log()->info(sprintf('INSTALLATION COMPLETED: Execution Time - %d sec (%s)', |
||
620 | max(1, time() - $start), |
||
621 | date('d.m.y H:i:s') |
||
622 | )); |
||
623 | |||
624 | return $disabled_extensions; |
||
625 | } |
||
626 | |||
636 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: