Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
improve module:enable command
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabea David committed Dec 15, 2016
1 parent aafb252 commit fd13483
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 65 deletions.
121 changes: 64 additions & 57 deletions src/Commands/Module/ModuleEnableCommand.php
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);
}
}
9 changes: 4 additions & 5 deletions src/Commands/User/UserCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ public function configure() {
public function execute(InputInterface $input, OutputInterface $output) {
parent::init($output, $input);
parent::bootstrapProcessWire($output);

$tools = new Tools($output);
$tools
->setHelper($this->getHelper('question'))
->setInput($input);

$tools->writeBlockCommand($this->getName());
->setInput($input)
->writeBlockCommand($this->getName());

$name = '';
while (!$name) $name = $tools->ask($input->getArgument('name'), 'Username');
$name = $tools->ask($input->getArgument('name'), 'Username', null, false, null, 'required');
$email = $tools->ask($input->getOption('email'), 'E-Mail-Address', null, false, null, 'email');
$pass = $tools->ask($input->getOption('password'), 'Password', $tools->generatePassword(), true);

Expand Down
4 changes: 1 addition & 3 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ Improve Commands
## module

- module:disable Disable provided module(s)
- module:download Downloads ProcessWire module(s).
- module:enable Enables provided module(s)
- module:generate Generates a boilerplate module
- module:upgrade Upgrades given module(s)

Done: 31 of 37 ~ 84%
Done: 33 of 37 ~ 89%

Sections Done: 8 of 9

Expand Down

0 comments on commit fd13483

Please sign in to comment.