Skip to content

Commit

Permalink
Fixes #1907
Browse files Browse the repository at this point in the history
  • Loading branch information
angrybrad committed Dec 12, 2017
1 parent 7775e75 commit 93f1c10
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Control Panel templates can now define `.info` elements with multiple paragraphs or line breaks. ([#2185](https://github.com/craftcms/cms/issues/2185))
- Control Panel content tabs now shrink to fit if they’re too wide for the tab bar. ([#2186](https://github.com/craftcms/cms/issues/2186))
- Craft’s bootstrap scripts now ensure that the server is running PHP 7+ before loading any files that would cause a syntax error on lower PHP versions.
- The `migrate/up` console command will now update a plugin’s or Craft’s schema version in the database after successfully completing all migrations. ([#1907](https://github.com/craftcms/cms/issues/1907))

### Fixed
- Fixed a bug where the “New entry” and “New category” buttons on entry/category index pages weren’t getting translated. ([#2164](https://github.com/craftcms/cms/issues/2164))
Expand Down
62 changes: 62 additions & 0 deletions src/console/controllers/MigrateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use craft\helpers\FileHelper;
use yii\console\controllers\BaseMigrateController;
use yii\console\Exception;
use yii\console\ExitCode;
use yii\helpers\Console;

/**
Expand Down Expand Up @@ -197,6 +198,67 @@ public function actionCreate($name)
}
}

public function actionUp($limit = 0)
{
$migrations = $this->getNewMigrations();
if (empty($migrations)) {
$this->stdout("No new migrations found. Your system is up-to-date.\n", Console::FG_GREEN);

return ExitCode::OK;
}

$total = count($migrations);
$limit = (int) $limit;
if ($limit > 0) {
$migrations = array_slice($migrations, 0, $limit);
}

$n = count($migrations);
if ($n === $total) {
$this->stdout("Total $n new " . ($n === 1 ? 'migration' : 'migrations') . " to be applied:\n", Console::FG_YELLOW);
} else {
$this->stdout("Total $n out of $total new " . ($total === 1 ? 'migration' : 'migrations') . " to be applied:\n", Console::FG_YELLOW);
}

foreach ($migrations as $migration) {
$nameLimit = $this->getMigrationNameLimit();
if ($nameLimit !== null && strlen($migration) > $nameLimit) {
$this->stdout("\nThe migration name '$migration' is too long. Its not possible to apply this migration.\n", Console::FG_RED);
return ExitCode::UNSPECIFIED_ERROR;
}
$this->stdout("\t$migration\n");
}
$this->stdout("\n");

$applied = 0;
if ($this->confirm('Apply the above ' . ($n === 1 ? 'migration' : 'migrations') . '?')) {
foreach ($migrations as $migration) {
if (!$this->migrateUp($migration)) {
$this->stdout("\n$applied from $n " . ($applied === 1 ? 'migration was' : 'migrations were') . " applied.\n", Console::FG_RED);
$this->stdout("\nMigration failed. The rest of the migrations are canceled.\n", Console::FG_RED);

return ExitCode::UNSPECIFIED_ERROR;
}
$applied++;
}

if ($limit === 0) {
// Update any schema versions.
switch ($this->type) {
case MigrationManager::TYPE_APP:
Craft::$app->getUpdates()->updateCraftVersionInfo();
break;
case MigrationManager::TYPE_PLUGIN:
Craft::$app->getUpdates()->setNewPluginInfo($this->plugin);
break;
}
}

$this->stdout("\n$n " . ($n === 1 ? 'migration was' : 'migrations were') . " applied.\n", Console::FG_GREEN);
$this->stdout("\nMigrated up successfully.\n", Console::FG_GREEN);
}
}

// Protected Methods
// =========================================================================

Expand Down

0 comments on commit 93f1c10

Please sign in to comment.