console\controllers\MigrateController::actionRedo PHP Метод

actionRedo() публичный Метод

This command will first revert the specified migrations, and then apply them again. For example, ~~~ yii migrate/redo # redo the last applied migration yii migrate/redo 3 # redo the last 3 applied migrations ~~~
public actionRedo ( integer $limit = 1 )
$limit integer the number of migrations to be redone. Defaults to 1, meaning the last applied migration will be redone.
    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";
        }
    }