mirror of
https://github.com/flarum/core.git
synced 2025-07-13 21:06:24 +02:00
Merge pull request #1363 from clarkwinkelmann/extension-rollback
Add extension rollback command
This commit is contained in:
@ -14,6 +14,7 @@ namespace Flarum\Console;
|
|||||||
use Flarum\Console\Event\Configuring;
|
use Flarum\Console\Event\Configuring;
|
||||||
use Flarum\Database\Console\GenerateMigrationCommand;
|
use Flarum\Database\Console\GenerateMigrationCommand;
|
||||||
use Flarum\Database\Console\MigrateCommand;
|
use Flarum\Database\Console\MigrateCommand;
|
||||||
|
use Flarum\Database\Console\ResetCommand;
|
||||||
use Flarum\Foundation\Application;
|
use Flarum\Foundation\Application;
|
||||||
use Flarum\Foundation\Console\CacheClearCommand;
|
use Flarum\Foundation\Console\CacheClearCommand;
|
||||||
use Flarum\Foundation\Console\InfoCommand;
|
use Flarum\Foundation\Console\InfoCommand;
|
||||||
@ -58,6 +59,7 @@ class Server
|
|||||||
$commands = [
|
$commands = [
|
||||||
InstallCommand::class,
|
InstallCommand::class,
|
||||||
MigrateCommand::class,
|
MigrateCommand::class,
|
||||||
|
ResetCommand::class,
|
||||||
GenerateMigrationCommand::class,
|
GenerateMigrationCommand::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
82
src/Database/Console/ResetCommand.php
Normal file
82
src/Database/Console/ResetCommand.php
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Flarum.
|
||||||
|
*
|
||||||
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||||
|
*
|
||||||
|
* 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.');
|
||||||
|
}
|
||||||
|
}
|
@ -247,10 +247,11 @@ class ExtensionManager
|
|||||||
* Runs the database migrations to reset the database to its old state.
|
* Runs the database migrations to reset the database to its old state.
|
||||||
*
|
*
|
||||||
* @param Extension $extension
|
* @param Extension $extension
|
||||||
|
* @return array Notes from the migrator.
|
||||||
*/
|
*/
|
||||||
public function migrateDown(Extension $extension)
|
public function migrateDown(Extension $extension)
|
||||||
{
|
{
|
||||||
$this->migrate($extension, false);
|
return $this->migrate($extension, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user