Example #1
0
 /**
  * Executes the command.
  *
  * @param  InputInterface  $input
  * @param  OutputInterface $output
  * @return object|OutputInterface
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $migration = file_get_contents(APPPATH . '/config/migration.php');
     $current = MigrationHelper::getLatestVersion($migration);
     $migrationsPath = APPPATH . 'migrations';
     list($filenames, $migrations) = MigrationHelper::getMigrations($migrationsPath);
     $end = count($migrations) - 1;
     $latest = $migrations[$end];
     // Enable migration and change the current version to a latest one
     MigrationHelper::toggleMigration(true);
     MigrationHelper::changeVersion($current, $latest);
     $this->codeigniter->load->library('migration');
     $this->codeigniter->migration->current();
     MigrationHelper::toggleMigration();
     // Show messages of migrated files
     if ($current == $latest) {
         $message = 'Database is up to date.';
         return $output->writeln('<info>' . $message . '</info>');
     }
     $migrationsCount = count($migrations);
     for ($counter = 0; $counter < $migrationsCount; $counter++) {
         if ($current >= $migrations[$counter]) {
             continue;
         }
         $filename = $filenames[$counter];
         $message = "{$filename} has been migrated to the database";
         $output->writeln('<info>' . $message . '</info>');
     }
 }
Example #2
0
 /**
  * Executes the command.
  *
  * @param  InputInterface  $input
  * @param  OutputInterface $output
  * @return object|OutputInterface
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $migration = file_get_contents(APPPATH . '/config/migration.php');
     $current = MigrationHelper::getLatestVersion($migration);
     if ($current <= 0) {
         $message = 'Database\'s version is now in 0.';
         return $output->writeln('<info>' . $message . '</info>');
     }
     // Enables migration and change the current version to 0
     MigrationHelper::toggleMigration(true);
     MigrationHelper::changeVersion($current, 0);
     $this->codeigniter->load->library('migration');
     $this->codeigniter->migration->current();
     MigrationHelper::toggleMigration();
     return $output->writeln('<info>Database has been resetted.</info>');
 }
Example #3
0
 /**
  * Executes the command.
  *
  * @param  InputInterface  $input
  * @param  OutputInterface $output
  * @return object|OutputInterface
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $migration = file_get_contents(APPPATH . '/config/migration.php');
     $current = MigrationHelper::getLatestVersion($migration);
     $migrationsPath = APPPATH . 'migrations';
     list($filenames, $migrations) = MigrationHelper::getMigrations($migrationsPath);
     // Might get the latest or the specified version or revert back
     $end = count($migrations) - 1;
     if (intval($current) <= 0) {
         $message = 'There\'s nothing to be rollbacked at.';
         return $output->writeln('<error>' . $message . '</error>');
     }
     $version = $input->getArgument('version');
     $versionFound = false;
     foreach ($migrations as $migration) {
         if ($migration == $version || empty($version)) {
             $versionFound = true;
             break;
         }
     }
     if (!$versionFound) {
         $message = "Cannot rollback to version {$version}.";
         return $output->writeln('<error>' . $message . '</error>');
     }
     $latest = $migrations[$end];
     $latestFile = $filenames[$end];
     if ($version) {
         $latest = $version;
     }
     // Enable migration and change the current version to a latest one
     MigrationHelper::toggleMigration(true);
     MigrationHelper::changeVersion($current, $latest);
     $this->codeigniter->load->library('migration');
     $this->codeigniter->migration->current();
     MigrationHelper::toggleMigration();
     $message = "Database is reverted back to version {$latest} ({$latestFile})";
     return $output->writeln('<info>' . $message . '</info>');
 }