public function actionMark($version)
{
$originalVersion = $version;
if (preg_match('/^m?(\\d{6}_\\d{6})(_.*?)?$/', $version, $matches)) {
$version = 'm' . $matches[1];
} else {
throw new Exception("The version argument must be either a timestamp (e.g. 101129_185401)\nor the full name of a migration (e.g. m101129_185401_create_user_table).");
}
// try mark up
$migrations = $this->getNewMigrations();
$i = 0;
foreach ($migrations as $migration => $alias) {
$stack[$migration] = $alias;
if (strpos($migration, $version . '_') === 0) {
if ($this->confirm("Set migration history at {$originalVersion}?")) {
$command = $this->db->createCommand();
foreach ($stack as $applyMigration => $applyAlias) {
$command->insert($this->migrationTable, ['version' => $applyMigration, 'alias' => $applyAlias, 'apply_time' => time()])->execute();
}
echo "The migration history is set at {$originalVersion}.\nNo actual migration was performed.\n";
}
return;
}
$i++;
}
// try mark down
$migrations = array_keys($this->getMigrationHistory(-1));
foreach ($migrations as $i => $migration) {
if (strpos($migration, $version . '_') === 0) {
if ($i === 0) {
echo "Already at '{$originalVersion}'. Nothing needs to be done.\n";
} else {
if ($this->confirm("Set migration history at {$originalVersion}?")) {
$command = $this->db->createCommand();
for ($j = 0; $j < $i; ++$j) {
$command->delete($this->migrationTable, ['version' => $migrations[$j]])->execute();
}
echo "The migration history is set at {$originalVersion}.\nNo actual migration was performed.\n";
}
}
return;
}
}
throw new Exception("Unable to find the version '{$originalVersion}'.");
}