Exemplo n.º 1
0
 /**
  * render|update|create model model ...
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  * @throws \tf_exception
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     //require('../_tests/loader.php');
     $core = $this->core();
     $this->prepare_db($input->getOption('database'));
     $action = $input->getArgument('action');
     if (empty($action)) {
         throw new \tf_exception("empty action\n");
     }
     $ids = $input->getArgument('models');
     if (empty($ids)) {
         throw new \tf_exception("empty ID\n");
     }
     if ($ids[0] == '*') {
         $ids = Helpers\ModelEnumerator::find();
     }
     /*
      * $action = @$_SERVER['argv'][2] ? : 'render';
        if (in_array('--', $_SERVER['argv'])) {
        }
     */
     $output->writeln('action: ' . $action);
     /** @var collection_generator */
     $generator = \abs_collection::get_generator();
     foreach ($ids as $mid) {
         $_mid = explode('.', trim($mid));
         if (count($_mid) == 1) {
             array_unshift($_mid, 'core');
             $container = core::selfie();
         } else {
             $container = core::module($_mid[0]);
         }
         if (!$container) {
             $output->writeln('skip ' . $mid);
             continue;
         }
         $method = 'get_' . $_mid[1] . '_handle';
         // allow model with params: get_model_handle | model('model')
         $obj = \functions::is_callable(array($container, $method)) ? $container->{$method}() : $container->model($_mid[1]);
         $generator->append_object($obj);
     }
     $output->writeln($generator->render_table_structure(), OutputInterface::OUTPUT_RAW);
     if ($action == 'update') {
         $generator->update_table_structure();
     }
     if ($action == 'create') {
         $generator->update_table_structure(true);
     }
 }
Exemplo n.º 2
0
 /**
  * @param $input
  * @param $output
  */
 function migrateDeprecated($input, $output)
 {
     $root = loader::get_public() . loader::DIR_MODULES . '*/classes';
     $finder = new Finder();
     $finder->directories()->in($root)->name('*')->depth('== 0');
     $generator = \abs_collection::get_generator();
     /** @var \SplFileInfo  $file */
     foreach ($finder as $file) {
         preg_match('@(?P<module>[\\w_+]*)[\\\\/]classes[\\\\/](?P<model>[\\w_+]*)$@', $file, $matches);
         if ('core' == $matches['module'] || core::modules()->is_registered($matches['module'])) {
             $model = $matches['module'] . '.' . $matches['model'];
             $generator->append_object($this->core()->model($model), $model);
             $output->writeln('...' . $model);
         }
     }
     $output->writeln($generator->update_table_structure(true));
 }