| Conditions | 17 |
| Paths | 359 |
| Total Lines | 77 |
| Code Lines | 54 |
| 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 |
||
| 41 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 42 | { |
||
| 43 | if (!$this->connected) { |
||
| 44 | $path = $input->getArgument('config'); |
||
| 45 | if (empty($path)) { |
||
| 46 | if (file_exists(OPENPSA_PROJECT_BASEDIR . 'config/midgard-portable.inc.php')) { |
||
|
|
|||
| 47 | $path = OPENPSA_PROJECT_BASEDIR . 'config/midgard-portable.inc.php'; |
||
| 48 | } else { |
||
| 49 | $dialog = $this->getHelper('question'); |
||
| 50 | $path = $dialog->ask($input, $output, new Question('<question>Enter path to config file</question>')); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | if (!file_exists($path)) { |
||
| 54 | throw new \RuntimeException('Config file ' . $path . ' not found'); |
||
| 55 | } |
||
| 56 | //we have to delay startup so that we can delete the entity class file before it gets included |
||
| 57 | connection::set_autostart(false); |
||
| 58 | require $path; |
||
| 59 | } |
||
| 60 | |||
| 61 | $mgd_config = midgard_connection::get_instance()->config; |
||
| 62 | $mgdschema_file = $mgd_config->vardir . '/mgdschema_classes.php'; |
||
| 63 | if ( file_exists($mgdschema_file) |
||
| 64 | && !unlink($mgdschema_file)) { |
||
| 65 | throw new \RuntimeException('Could not unlink ' . $mgdschema_file); |
||
| 66 | } |
||
| 67 | if (connection::get_parameter('dev_mode') !== true) { |
||
| 68 | $driver = connection::get_parameter('driver'); |
||
| 69 | $classgenerator = new classgenerator($driver->get_manager(), $mgdschema_file); |
||
| 70 | $classgenerator->write($driver->get_namespace()); |
||
| 71 | } |
||
| 72 | if (!file_exists($mgd_config->blobdir . '/0/0')) { |
||
| 73 | $mgd_config->create_blobdir(); |
||
| 74 | } |
||
| 75 | connection::startup(); |
||
| 76 | $em = connection::get_em(); |
||
| 77 | connection::invalidate_cache(); |
||
| 78 | $cms = $em->getMetadataFactory()->getAllMetadata(); |
||
| 79 | |||
| 80 | // create storage |
||
| 81 | if ( !midgard_storage::create_base_storage() |
||
| 82 | && midgard_connection::get_instance()->get_error_string() != 'MGD_ERR_OK') { |
||
| 83 | throw new \Exception("Failed to create base database structures" . midgard_connection::get_instance()->get_error_string()); |
||
| 84 | } |
||
| 85 | $force = $input->getOption('force'); |
||
| 86 | $to_update = []; |
||
| 87 | $to_create = []; |
||
| 88 | |||
| 89 | foreach ($cms as $cm) { |
||
| 90 | if (!$em->getConnection()->getSchemaManager()->tablesExist([$cm->getTableName()])) { |
||
| 91 | $to_create[] = $cm; |
||
| 92 | } else { |
||
| 93 | $to_update[] = $cm; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | if (!empty($to_create)) { |
||
| 98 | $output->writeln('Creating <info>' . count($to_create) . '</info> new tables'); |
||
| 99 | $tool = new SchemaTool($em); |
||
| 100 | try { |
||
| 101 | $tool->createSchema($to_create); |
||
| 102 | } catch (\Exception $e) { |
||
| 103 | if (!$force) { |
||
| 104 | throw $e; |
||
| 105 | } else { |
||
| 106 | $output->writeln('<error>' . $e->getMessage() . '</error>'); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | } |
||
| 110 | if (!empty($to_update)) { |
||
| 111 | $delete = $input->getOption('delete'); |
||
| 112 | $this->process_updates($to_update, $output, $force, $delete); |
||
| 113 | } |
||
| 114 | $output->writeln('Generating proxies'); |
||
| 115 | $this->generate_proxyfiles($cms); |
||
| 116 | |||
| 117 | $output->writeln('Done'); |
||
| 118 | } |
||
| 184 |