Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension rollback command #1363

Merged
merged 4 commits into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Console/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Flarum\Console\Event\Configuring;
use Flarum\Database\Console\GenerateMigrationCommand;
use Flarum\Database\Console\MigrateCommand;
use Flarum\Database\Console\ResetCommand;
use Flarum\Foundation\Application;
use Flarum\Foundation\Console\CacheClearCommand;
use Flarum\Foundation\Console\InfoCommand;
Expand Down Expand Up @@ -58,6 +59,7 @@ protected function getConsoleApplication()
$commands = [
InstallCommand::class,
MigrateCommand::class,
ResetCommand::class,
GenerateMigrationCommand::class,
];

Expand Down
82 changes: 82 additions & 0 deletions src/Database/Console/ResetCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

/*
* This file is part of Flarum.
*
* (c) Toby Zerner <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Flarum\Database\Console;

use Flarum\Console\AbstractCommand;
use Flarum\Extension\ExtensionManager;
use Symfony\Component\Console\Input\InputOption;

class ResetCommand extends AbstractCommand
{
/**
* @var ExtensionManager
*/
protected $manager;

/**
* @param ExtensionManager $manager
*/
public function __construct(ExtensionManager $manager)
{
$this->manager = $manager;

parent::__construct();
}

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('migrate:reset')
->setDescription('Run all migrations down for an extension')
->addOption(
'extension',
null,
InputOption::VALUE_REQUIRED,
'The extension to reset migrations for.'
);
}

/**
* {@inheritdoc}
*/
protected function fire()
{
$extensionName = $this->input->getOption('extension');

if (! $extensionName) {
$this->info('No extension specified. Please check command syntax.');

return;
}

$extension = $this->manager->getExtension($extensionName);

if (! $extension) {
$this->info('Could not find extension '.$extensionName);

return;
}

$this->info('Rolling back extension: '.$extensionName);

$notes = $this->manager->migrateDown($extension);

foreach ($notes as $note) {
$this->info($note);
}

$this->info('DONE.');
}
}
3 changes: 2 additions & 1 deletion src/Extension/ExtensionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,11 @@ public function migrate(Extension $extension, $up = true)
* Runs the database migrations to reset the database to its old state.
*
* @param Extension $extension
* @return array Notes from the migrator.
*/
public function migrateDown(Extension $extension)
{
$this->migrate($extension, false);
return $this->migrate($extension, false);
}

/**
Expand Down