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

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

For example, ~~~ yii migrate/down # revert the last migration yii migrate/down 3 # revert the last 3 migrations ~~~
public actionDown ( integer $limit = 1 )
$limit integer the number of migrations to be reverted. Defaults to 1, meaning the last applied migration will be reverted.
    public function actionDown($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 reverted:\n";
        foreach ($migrations as $migration => $info) {
            echo "    {$migration} (" . $info['alias'] . ")\n";
        }
        echo "\n";
        if ($this->confirm('Revert 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;
                }
            }
            echo "\nMigrated down successfully.\n";
        }
    }