public function actionRedo($limit = 1)
{
$limit = (int) $limit;
if ($limit < 1) {
throw new Exception("The step argument must be greater than 0.");
}
$migrations = $this->getMigrationHistory($limit);
if (empty($migrations)) {
echo "No migration has been done before.\n";
return;
}
$n = count($migrations);
echo "Total {$n} " . ($n === 1 ? 'migration' : 'migrations') . " to be redone:\n";
foreach ($migrations as $migration => $info) {
echo " {$migration}\n";
}
echo "\n";
if ($this->confirm('Redo the above ' . ($n === 1 ? 'migration' : 'migrations') . "?")) {
foreach ($migrations as $migration => $info) {
if (!$this->migrateDown($migration, $info['alias'])) {
echo "\nMigration failed. The rest of the migrations are canceled.\n";
return;
}
}
foreach (array_reverse($migrations) as $migration => $info) {
if (!$this->migrateUp($migration, $info['alias'])) {
echo "\nMigration failed. The rest of the migrations migrations are canceled.\n";
return;
}
}
echo "\nMigration redone successfully.\n";
}
}