-
-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1363 from clarkwinkelmann/extension-rollback
Add extension rollback command
- Loading branch information
Showing
3 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters