コード例 #1
0
ファイル: Up.php プロジェクト: groovey/migration
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = $this->app;
     $yaml = new Parser();
     $dir = Migration::getDirectory();
     $files = Migration::getUnMigratedFiles($app);
     $output = Output::style($output);
     $total = count($files);
     $helper = $this->getHelper('question');
     if ($total == 0) {
         $output->writeln('<error>No new files to be migrated.</error>');
         return;
     }
     $output->writeln('<highlight>Migration will run the following files:</highlight>');
     foreach ($files as $file) {
         $output->writeln("<info>- {$file}</info>");
     }
     $question = new ConfirmationQuestion('<question>Are you sure you want to proceed? (Y/n):</question> ', false);
     if (!$helper->ask($input, $output, $question)) {
         return;
     }
     foreach ($files as $file) {
         $output->writeln("<info>- Migrating ({$file})</info>");
         $content = $yaml->parse(file_get_contents($dir . '/' . $file));
         $up = explode(';', trim($content['up']));
         $up = array_filter($up);
         $date = element('date', $content);
         $author = element('author', $content);
         $changelog = element('changelog', $content);
         $dateFormat = validate_date($date);
         $fileFormat = Migration::validateFileFormat($file);
         if (!$fileFormat) {
             $output->writeln('<error>Invalid file format.</error>');
             return;
         } elseif (!$dateFormat) {
             $output->writeln('<error>Invalid date (YYYY-mm-dd HH:mm:ss).</error>');
             return;
         } elseif (!$author) {
             $output->writeln('<error>Invalid author.</error>');
             return;
         } elseif (!$changelog) {
             $output->writeln('<error>Invalid changelog.</error>');
             return;
         }
         foreach ($up as $query) {
             $app['db']::statement(trim($query));
         }
         $info = Migration::getFileInfo($file);
         $app['db']->table('migrations')->insert(['version' => $info['version'], 'author' => $author, 'filename' => $file, 'changelog' => $changelog, 'created_at' => $date, 'updated_at' => new \DateTime()]);
     }
 }
コード例 #2
0
ファイル: Status.php プロジェクト: groovey/migration
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output = Output::style($output);
     $files = [];
     foreach (Migration::getUnMigratedFiles($this->app) as $file) {
         $files[] = [$file];
     }
     if (!$files) {
         $output->writeln('<highlight>Nothing to migrate.</highlight>');
         return;
     }
     $table = new Table($output);
     $table->setHeaders(['Unmigrated YML'])->setRows($files);
     $table->render();
 }