This repository has been archived by the owner on Apr 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tabea David
committed
Dec 15, 2016
1 parent
aafb252
commit fd13483
Showing
3 changed files
with
69 additions
and
65 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,94 @@ | ||
<?php namespace Wireshell\Commands\Module; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Wireshell\Helpers\PwModuleTools; | ||
use Wireshell\Helpers\WsTools as Tools; | ||
|
||
/** | ||
* Class ModuleEnableCommand | ||
* | ||
* Enables provided module(s) | ||
* | ||
* @package Wireshell | ||
* @author Marcus Herrmann | ||
* @author Tabea David <td@kf-interactive.com> | ||
*/ | ||
class ModuleEnableCommand extends PwModuleTools { | ||
|
||
/** | ||
* Configures the current command. | ||
*/ | ||
protected function configure() { | ||
$this | ||
->setName('module:enable') | ||
->setDescription('Enables provided module(s)') | ||
->addArgument('modules', InputOption::VALUE_REQUIRED, | ||
'Provide one or more module class name, comma separated: Foo,Bar') | ||
->addOption('github', null, InputOption::VALUE_OPTIONAL, | ||
'Download module via github. Use this option if the module isn\'t added to the ProcessWire module directory.') | ||
->addOption('branch', null, InputOption::VALUE_OPTIONAL, | ||
'Optional. Define specific branch to download from.'); | ||
} | ||
/** | ||
* Configures the current command. | ||
*/ | ||
protected function configure() { | ||
$this | ||
->setName('module:enable') | ||
->setDescription('Enables provided module(s)') | ||
->addArgument('modules', InputArgument::OPTIONAL, 'Provide one or more module class name, comma separated: Foo,Bar') | ||
->addOption('github', null, InputOption::VALUE_OPTIONAL, 'Download module via github. Use this option if the module isn\'t added to the ProcessWire module directory.') | ||
->addOption('branch', null, InputOption::VALUE_OPTIONAL, 'Optional. Define specific branch to download from.'); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int|null|void | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
parent::init($output, $input); | ||
parent::bootstrapProcessWire($output); | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int|null|void | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
parent::bootstrapProcessWire($output); | ||
$modules = explode(",", $input->getArgument('modules')); | ||
$this->tools = new Tools($output); | ||
$this->tools->setHelper($this->getHelper('question')) | ||
->setInput($input) | ||
->writeBlockCommand($this->getName()); | ||
|
||
foreach ($modules as $module) { | ||
// if module doesn't exist, download the module | ||
if (!$this->checkIfModuleExists($module)) { | ||
$output->writeln("<comment>Cannot find '{$module}' locally, trying to download...</comment>"); | ||
$this->passOnToModuleDownloadCommand($module, $output, $input); | ||
} | ||
$modules = $this->tools->ask($input->getArgument('modules'), 'Modules', null, false, null, 'required'); | ||
if (!is_array($modules)) $modules = explode(',', $modules); | ||
|
||
// check whether module is already installed | ||
if (\ProcessWire\wire('modules')->isInstalled($module)) { | ||
$output->writeln("<info>Module `{$module}` is already installed.</info>"); | ||
exit(1); | ||
} | ||
foreach ($modules as $module) { | ||
// if module doesn't exist, download the module | ||
if (!$this->checkIfModuleExists($module)) { | ||
$this->tools->writeComment("Cannot find '{$module}' locally, trying to download..."); | ||
$this->passOnToModuleDownloadCommand($module, $output, $input); | ||
} | ||
|
||
// install module | ||
if (\ProcessWire\wire('modules')->getModule($module, array('noPermissionCheck' => true, 'noInit' => true))) { | ||
$output->writeln("<info>Module `{$module}` installed successfully.</info>"); | ||
} else { | ||
$output->writeln("<error>Module `{$module}` does not exist.</error>"); | ||
} | ||
} | ||
// check whether module is already installed | ||
if (\ProcessWire\wire('modules')->isInstalled($module)) { | ||
$this->tools->writeInfo(" Module `{$module}` is already installed."); | ||
continue; | ||
} | ||
|
||
// install module | ||
if (\ProcessWire\wire('modules')->getModule($module, array('noPermissionCheck' => true, 'noInit' => true))) { | ||
$this->tools->writeSuccess(" Module `{$module}` installed successfully."); | ||
} else { | ||
$this->tools->writeError(" Module `{$module}` does not exist."); | ||
} | ||
} | ||
|
||
private function checkIfModuleExistsLocally($module, $output, $input) { | ||
if (!$this->checkIfModuleExists($module)) { | ||
$output->writeln("<comment>Cannot find '{$module}' locally, trying to download...</comment>"); | ||
$this->passOnToModuleDownloadCommand($module, $output, $input); | ||
} | ||
} | ||
|
||
private function checkIfModuleExistsLocally($module, $output, $input) { | ||
if (!$this->checkIfModuleExists($module)) { | ||
$output->writeln("<comment>Cannot find '{$module}' locally, trying to download...</comment>"); | ||
$this->passOnToModuleDownloadCommand($module, $output, $input); | ||
} | ||
|
||
private function passOnToModuleDownloadCommand($module, $output, $input) { | ||
$command = $this->getApplication()->find('mod:download'); | ||
} | ||
|
||
$arguments = array( | ||
'command' => 'mod:download', | ||
'modules' => $module, | ||
'--github' => $input->getOption('github'), | ||
'--branch' => $input->getOption('branch') | ||
); | ||
private function passOnToModuleDownloadCommand($module, $output, $input) { | ||
$command = $this->getApplication()->find('mod:download'); | ||
|
||
$passOnInput = new ArrayInput($arguments); | ||
$command->run($passOnInput, $output); | ||
} | ||
$arguments = array( | ||
'command' => 'mod:download', | ||
'modules' => $module, | ||
'--github' => $input->getOption('github'), | ||
'--branch' => $input->getOption('branch') | ||
); | ||
|
||
$passOnInput = new ArrayInput($arguments); | ||
$command->run($passOnInput, $output); | ||
} | ||
} |
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