public function actionMark($version)
{
$originalVersion = $version;
if (($namespaceVersion = $this->extractNamespaceMigrationVersion($version)) !== false) {
$version = $namespaceVersion;
} elseif (($migrationName = $this->extractMigrationVersion($version)) !== false) {
$version = $migrationName;
} 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)\nor the full name of a namespaced migration (e.g. app\\migrations\\M101129185401CreateUserTable).");
}
// try mark up
$migrations = $this->getNewMigrations();
foreach ($migrations as $i => $migration) {
if (strpos($migration, $version) === 0) {
if ($this->confirm("Set migration history at {$originalVersion}?")) {
for ($j = 0; $j <= $i; ++$j) {
$this->addMigrationHistory($migrations[$j]);
}
$this->stdout("The migration history is set at {$originalVersion}.\nNo actual migration was performed.\n", Console::FG_GREEN);
}
return self::EXIT_CODE_NORMAL;
}
}
// try mark down
$migrations = array_keys($this->getMigrationHistory(null));
foreach ($migrations as $i => $migration) {
if (strpos($migration, $version) === 0) {
if ($i === 0) {
$this->stdout("Already at '{$originalVersion}'. Nothing needs to be done.\n", Console::FG_YELLOW);
} else {
if ($this->confirm("Set migration history at {$originalVersion}?")) {
for ($j = 0; $j < $i; ++$j) {
$this->removeMigrationHistory($migrations[$j]);
}
$this->stdout("The migration history is set at {$originalVersion}.\nNo actual migration was performed.\n", Console::FG_GREEN);
}
}
return self::EXIT_CODE_NORMAL;
}
}
throw new Exception("Unable to find the version '{$originalVersion}'.");
}