-
-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cli command for enabling or disabling an extension (#3816)
- Loading branch information
Showing
2 changed files
with
81 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
78 changes: 78 additions & 0 deletions
78
framework/core/src/Extension/Console/ToggleExtensionCommand.php
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,78 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Extension\Console; | ||
|
||
use Flarum\Console\AbstractCommand; | ||
use Flarum\Extension\ExtensionManager; | ||
|
||
class ToggleExtensionCommand extends AbstractCommand | ||
{ | ||
/** | ||
* @var ExtensionManager | ||
*/ | ||
protected $extensionManager; | ||
|
||
public function __construct(ExtensionManager $extensionManager) | ||
{ | ||
$this->extensionManager = $extensionManager; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('extension:enable') | ||
->setAliases(['extension:disable']) | ||
->setDescription('Enable or disable an extension.') | ||
->addArgument('extension-id', null, 'The ID of the extension to enable or disable.'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function fire() | ||
{ | ||
$name = $this->input->getArgument('extension-id'); | ||
$enabling = $this->input->getFirstArgument() === 'extension:enable'; | ||
|
||
if ($this->extensionManager->getExtension($name) === null) { | ||
$this->error("There are no extensions by the ID of '$name'."); | ||
|
||
return; | ||
} | ||
|
||
switch ($enabling) { | ||
case true: | ||
if ($this->extensionManager->isEnabled($name)) { | ||
$this->info("The '$name' extension is already enabled."); | ||
|
||
return; | ||
} else { | ||
$this->info("Enabling '$name' extension..."); | ||
$this->extensionManager->enable($name); | ||
} | ||
break; | ||
case false: | ||
if (! $this->extensionManager->isEnabled($name)) { | ||
$this->info("The '$name' extension is already disabled."); | ||
|
||
return; | ||
} else { | ||
$this->info("Disabling '$name' extension..."); | ||
$this->extensionManager->disable($name); | ||
} | ||
break; | ||
} | ||
} | ||
} |