Beispiel #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $class = $input->getArgument('class');
     $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../Templates/');
     $twig = new \Twig_Environment($loader);
     $fs = new Filesystem();
     $output = Output::style($output);
     $dir = getcwd() . '/database/seeds';
     $file = $dir . '/' . ucfirst($class) . '.php';
     $helper = $this->getHelper('question');
     if (!$fs->exists($dir)) {
         $output->writeln('<error>The seeder directory does not exist. Make sure you run groovey seed:init first.</error>');
         return;
     }
     $output->writeln('<highlight>Creating seeder file:</highlight>');
     $output->writeln("<info>- {$file}</info>");
     if ($fs->exists($file)) {
         $question = new ConfirmationQuestion('<question>The seeder file already exist. Are you sure you want to replace it? (Y/N):</question> ', false);
         if (!$helper->ask($input, $output, $question)) {
             return;
         }
     } else {
         $question = new ConfirmationQuestion('<question>Are you sure you want to proceed? (Y/n):</question> ', false);
         if (!$helper->ask($input, $output, $question)) {
             return;
         }
     }
     $contents = $twig->render('seeder.twig', ['class' => ucfirst($class), 'table' => strtolower($class)]);
     file_put_contents($file, $contents);
     $output->writeln('<info>Sucessfully created seed file.</info>');
 }
Beispiel #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = $this->app;
     $description = $input->getArgument('description');
     $directory = Migration::getDirectory();
     $data = Migration::getTemplate();
     $underscore = implode('_', $description);
     $version = Migration::getNextVersion($app);
     $filename = $version . '_' . $underscore . '.yml';
     $helper = $this->getHelper('question');
     $question = new ConfirmationQuestion('<question>Are you sure you want to proceed? (Y/n):</question> ', false);
     $output = Output::style($output);
     $output->writeln('<highlight>Creating migration file:</highlight>');
     $output->writeln("<info> - {$filename}</info>");
     if (!$helper->ask($input, $output, $question)) {
         return;
     }
     if (file_exists($directory . '/' . $filename)) {
         $output->writeln("<error>The migration file already {$filename} exists.</error>");
         return;
     }
     file_put_contents($directory . '/' . $filename, $data);
     $text = '<info>Sucessfully created migration file.</info>';
     $output->writeln($text);
 }
Beispiel #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $class = $input->getArgument('class');
     $total = $input->getArgument('total');
     $fs = new Filesystem();
     $output = Output::style($output);
     $filename = getcwd() . "/database/seeds/{$class}.php";
     $helper = $this->getHelper('question');
     if (!$fs->exists($filename)) {
         $output->writeln('<error>The seeder class does not exits.</error>');
         return;
     }
     $output->writeln('<highlight>Running seeder file:</highlight>');
     $output->writeln("<info>{$filename}</info>");
     $question = new ConfirmationQuestion('<question>Are you sure you want to proceed? (Y/n):</question> ', false);
     if (!$helper->ask($input, $output, $question)) {
         return;
     }
     include_once __DIR__ . '/../Factory.php';
     include_once __DIR__ . '/../Seeder.php';
     include_once $filename;
     $instance = new $class();
     $instance->inject($output, $this->app, coalesce($total, 1));
     $instance->init();
     $instance->run();
 }
Beispiel #4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output = Output::style($output);
     $helper = $this->getHelper('question');
     $output->writeln('<warning>Warning!!!</warning>');
     $question = new ConfirmationQuestion('<question>Migrations table will be deleted, are you sure you want to proceed? (y/N):</question> ', false);
     if (!$helper->ask($input, $output, $question)) {
         return;
     }
     $this->drop();
     $text = '<highlight>Migrations table has been deleted.</highlight>';
     $output->writeln($text);
 }
Beispiel #5
0
 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()]);
     }
 }
Beispiel #6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = $this->app;
     $helper = $this->getHelper('question');
     $output = Output::style($output);
     $output->writeln('<warning>Warning!!!</warning>');
     $question = new ConfirmationQuestion('<question>All migration entries will be cleared, are you sure you want to proceed? (y/N):</question> ', false);
     if (!$helper->ask($input, $output, $question)) {
         return;
     }
     $app['db']->table('migrations')->truncate();
     $text = '<highlight>All migration entries has been cleared.</highlight>';
     $output->writeln($text);
 }
Beispiel #7
0
 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();
 }
Beispiel #8
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->init();
     $output = Output::style($output);
     $folder = getcwd() . '/database/migrations';
     if (false === @mkdir($folder, 0755, true) && !file_exists($folder)) {
         $output->writeln('<error>Unable to create folder. Check file permissions.</error>');
         return;
     }
     if (file_exists($folder) && is_dir($folder)) {
         $output->writeln('<highlight>Sucessfully created migrations database folder.</highlight>');
         $output->writeln('<info>Place all your migration files in:</info>');
         $output->writeln("<comment>{$folder}</comment>");
     }
 }
Beispiel #9
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $fs = new Filesystem();
     $output = Output::style($output);
     $folder = getcwd() . '/database/seeds';
     try {
         $fs->mkdir($folder, 755);
     } catch (IOExceptionInterface $e) {
         $output->writeln("<error>An error occurred while creating your directory at {$e->getPath()}</error>");
         return;
     }
     if (file_exists($folder) && is_dir($folder)) {
         $output->writeln('<highlight>Sucessfully created seeder folder.</highlight>');
         $output->writeln('<info>Place all your seeder files in:</info>');
         $output->writeln("<comment>{$folder}</comment>");
     }
 }
Beispiel #10
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = $this->app;
     $dir = Migration::getDirectory();
     $output = Output::style($output);
     $yaml = new Parser();
     $version = $input->getArgument('version');
     $helper = $this->getHelper('question');
     $question = new ConfirmationQuestion('<question>Are you sure you want to proceed? (y/N):</question> ', false);
     if ($version) {
         $record = $app['db']->table('migrations')->where('version', '=', $version)->first();
         if (!$record) {
             $output->writeln('<error>Unable to find migration version.</error>');
             return;
         }
         $records = $app['db']->table('migrations')->where('id', '>=', $record->id)->orderBy('version', 'DESC')->get();
     } else {
         $records = $app['db']->table('migrations')->orderBy('version', 'DESC')->take(1)->get();
     }
     if (count($records) == 0) {
         $output->writeln('<error>Nothing to downgrade.</error>');
         return;
     }
     $output->writeln('<highlight>Migration will downgrade to the following files:</highlight>');
     foreach ($records as $record) {
         $output->writeln("<info>- {$record->filename}</info>");
     }
     if (!$helper->ask($input, $output, $question)) {
         return;
     }
     foreach ($records as $record) {
         $id = $record->id;
         $version = $record->version;
         $filename = $record->filename;
         $output->writeln("<info>- Downgrading ({$filename})</info>");
         $value = $yaml->parse(file_get_contents($dir . '/' . $filename));
         $down = explode(';', trim($value['down']));
         $down = array_filter($down);
         foreach ($down as $query) {
             $app['db']::statement(trim($query));
         }
         $app['db']->table('migrations')->delete($id);
     }
 }