| @@ 14-64 (lines=51) @@ | ||
| 11 | /**  | 
                                |
| 12 | * MigrateCommand  | 
                                |
| 13 | */  | 
                                |
| 14 | class MigrateUpCommand extends Command  | 
                                |
| 15 | { | 
                                |
| 16 | use DbHelper;  | 
                                |
| 17 | ||
| 18 | /**  | 
                                |
| 19 | * Configuration of command  | 
                                |
| 20 | */  | 
                                |
| 21 | protected function configure()  | 
                                |
| 22 |     { | 
                                |
| 23 | $this  | 
                                |
| 24 |             ->setName('migrate:up') | 
                                |
| 25 |             ->setDescription('Command for run migration') | 
                                |
| 26 | ;  | 
                                |
| 27 | }  | 
                                |
| 28 | ||
| 29 | /**  | 
                                |
| 30 | * Execute method of command  | 
                                |
| 31 | *  | 
                                |
| 32 | * @param InputInterface $input  | 
                                |
| 33 | * @param OutputInterface $output  | 
                                |
| 34 | *  | 
                                |
| 35 | * @return void  | 
                                |
| 36 | */  | 
                                |
| 37 | protected function execute(InputInterface $input, OutputInterface $output)  | 
                                |
| 38 |     { | 
                                |
| 39 |         if (!is_dir(MIGRATIONS_PATH) || !is_readable(MIGRATIONS_PATH)) { | 
                                |
| 40 |             throw new \RunTimeException(sprintf('Migrations path `%s` is not good', MIGRATIONS_PATH)); | 
                                |
| 41 | }  | 
                                |
| 42 | ||
| 43 | $output->writeln([  | 
                                |
| 44 | '<info>Run migrations</info>',  | 
                                |
| 45 |             sprintf('Ensure table `%s` presence', $this->migrationsTable) | 
                                |
| 46 | ]);  | 
                                |
| 47 | ||
| 48 |         try { | 
                                |
| 49 | $this->safeCreateTable($this->migrationsTable);  | 
                                |
| 50 |         } catch (\Exception $e) { | 
                                |
| 51 | $output->writeln([  | 
                                |
| 52 |                 sprintf('Can\'t ensure table `%s` presence. Please verify DB connection params and presence of database named', $this->migrationsTable), | 
                                |
| 53 |                 sprintf('Error: `%s`', $e->getMessage()), | 
                                |
| 54 | ]);  | 
                                |
| 55 | }  | 
                                |
| 56 | ||
| 57 | $finder = new Finder();  | 
                                |
| 58 |         $finder->files()->name('*.php')->in(MIGRATIONS_PATH); | 
                                |
| 59 | ||
| 60 | $this->runActions($finder, $output, $this->migrationsTable, 'up');  | 
                                |
| 61 | ||
| 62 | return;  | 
                                |
| 63 | }  | 
                                |
| 64 | }  | 
                                |
| 65 | ||
| @@ 14-64 (lines=51) @@ | ||
| 11 | /**  | 
                                |
| 12 | * SeedCommand  | 
                                |
| 13 | */  | 
                                |
| 14 | class RunSeedCommand extends Command  | 
                                |
| 15 | { | 
                                |
| 16 | use DbHelper;  | 
                                |
| 17 | ||
| 18 | /**  | 
                                |
| 19 | * Configuration of command  | 
                                |
| 20 | */  | 
                                |
| 21 | protected function configure()  | 
                                |
| 22 |     { | 
                                |
| 23 | $this  | 
                                |
| 24 |             ->setName('run:seed') | 
                                |
| 25 |             ->setDescription('Command for run seed') | 
                                |
| 26 | ;  | 
                                |
| 27 | }  | 
                                |
| 28 | ||
| 29 | /**  | 
                                |
| 30 | * Execute method of command  | 
                                |
| 31 | *  | 
                                |
| 32 | * @param InputInterface $input  | 
                                |
| 33 | * @param OutputInterface $output  | 
                                |
| 34 | *  | 
                                |
| 35 | * @return int|null|void  | 
                                |
| 36 | */  | 
                                |
| 37 | protected function execute(InputInterface $input, OutputInterface $output)  | 
                                |
| 38 |     { | 
                                |
| 39 |         if (!is_dir(SEEDS_PATH) || !is_readable(SEEDS_PATH)) { | 
                                |
| 40 |             throw new \RunTimeException(sprintf('Seeds path `%s` is not good', SEEDS_PATH)); | 
                                |
| 41 | }  | 
                                |
| 42 | ||
| 43 | $output->writeln([  | 
                                |
| 44 | '<info>Run seeds</info>',  | 
                                |
| 45 |             sprintf('Ensure table `%s` presence', $this->seedsTable) | 
                                |
| 46 | ]);  | 
                                |
| 47 | ||
| 48 |         try { | 
                                |
| 49 | $this->safeCreateTable($this->seedsTable);  | 
                                |
| 50 |         } catch (\Exception $e) { | 
                                |
| 51 | $output->writeln([  | 
                                |
| 52 |                 sprintf('Can\'t ensure table `%s` presence. Please verify DB connection params and presence of database named', $this->seedsTable), | 
                                |
| 53 |                 sprintf('Error: `%s`', $e->getMessage()), | 
                                |
| 54 | ]);  | 
                                |
| 55 | }  | 
                                |
| 56 | ||
| 57 | $finder = new Finder();  | 
                                |
| 58 |         $finder->files()->name('*.php')->in(SEEDS_PATH); | 
                                |
| 59 | ||
| 60 | $this->runActions($finder, $output, $this->seedsTable, 'run');  | 
                                |
| 61 | ||
| 62 | return;  | 
                                |
| 63 | }  | 
                                |
| 64 | }  | 
                                |
| 65 | ||