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
Feb 2, 2017
1 parent
ada58a4
commit 72c196c
Showing
8 changed files
with
240 additions
and
201 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
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,98 +1,109 @@ | ||
<?php namespace Wireshell\Commands\Module; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Wireshell\Helpers\PwConnector; | ||
use Wireshell\Helpers\WsTools as Tools; | ||
|
||
/** | ||
* Class ModuleDisableCommand | ||
* | ||
* Disables provided module(s) | ||
* | ||
* @package Wireshell | ||
* @author Marcus Herrmann | ||
* @author Tabea David <info@justonestep.de> | ||
*/ | ||
class ModuleDisableCommand extends PwConnector { | ||
|
||
/** | ||
* Configures the current command. | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('module:disable') | ||
->setDescription('Disable provided module(s)') | ||
->addArgument('modules', InputOption::VALUE_REQUIRED, | ||
'Provide one or more module class name, comma separated: Foo,Bar') | ||
->addOption('rm', null, InputOption::VALUE_NONE, 'Remove module'); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int|null|void | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
parent::bootstrapProcessWire($output); | ||
/** | ||
* Configures the current command. | ||
*/ | ||
protected function configure() { | ||
$this | ||
->setName('module:disable') | ||
->setDescription('Disable provided module(s)') | ||
->addArgument('modules', InputArgument::IS_ARRAY, 'Module classname (separate multiple names with a space)') | ||
->addOption('rm', null, InputOption::VALUE_NONE, 'Remove module'); | ||
} | ||
|
||
$modules = explode(",", $input->getArgument('modules')); | ||
$remove = $input->getOption('rm') === true ? true : false; | ||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int|null|void | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) { | ||
parent::setOutput($output)::setInput($input)::bootstrapProcessWire(); | ||
|
||
foreach ($modules as $module) { | ||
$this->checkIfModuleExists($module, $output, $remove); | ||
$this->tools = new Tools($output); | ||
$this->tools | ||
->setInput($input) | ||
->setHelper($this->getHelper('question')) | ||
->writeBlockCommand($this->getName()); | ||
|
||
if (\ProcessWire\wire('modules')->uninstall($module)) { | ||
$output->writeln("Module {$module} <comment>uninstalled</comment> successfully."); | ||
} | ||
$modules = $this->tools->ask( | ||
$input->getArgument('modules'), | ||
$this->getDefinition()->getArgument('modules')->getDescription(), | ||
null, | ||
false, | ||
null, | ||
'required' | ||
); | ||
|
||
// remove module | ||
if ($remove === true && is_dir(\ProcessWire\wire('config')->paths->$module)) { | ||
if ($this->recurseRmdir(\ProcessWire\wire('config')->paths->$module)) { | ||
$output->writeln("Module {$module} was <comment>removed</comment> successfully."); | ||
} else { | ||
$output->writeln("Module {$module} could not be removed <fg=red>could not be removed</fg=red>."); | ||
} | ||
} | ||
} | ||
if (!is_array($modules)) $modules = explode(" ", $modules); | ||
$remove = $input->getOption('rm') === true ? true : false; | ||
|
||
} | ||
foreach ($modules as $module) { | ||
$this->checkIfModuleExists($module, $remove); | ||
|
||
private function checkIfModuleExists($module, $output, $remove) | ||
{ | ||
if (!is_dir(\ProcessWire\wire('config')->paths->siteModules . $module)) { | ||
$output->writeln("<error>Module '{$module}' does not exist!</error>"); | ||
exit(1); | ||
} | ||
if (\ProcessWire\wire('modules')->uninstall($module)) { | ||
$this->tools->writeSuccess("Module `{$module}` uninstalled successfully."); | ||
} | ||
|
||
if (!\ProcessWire\wire('modules')->getModule($module, array('noPermissionCheck' => true, 'noInit' => true)) && $remove === false) { | ||
$output->writeln("<info>Module '{$module}' is not installed!</info>"); | ||
exit(1); | ||
// remove module | ||
if ($remove === true && is_dir(\ProcessWire\wire('config')->paths->$module)) { | ||
$this->tools->nl(); | ||
if ($this->recurseRmdir(\ProcessWire\wire('config')->paths->$module)) { | ||
$this->tools->writeInfo("Module `{$module}` was <comment>removed</comment> successfully."); | ||
} else { | ||
$this->tools->writeError("Module `{$module}` could not be removed <fg=red>could not be removed</fg=red>."); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
private function checkIfModuleExists($module, $remove) { | ||
if (!is_dir(\ProcessWire\wire('config')->paths->siteModules . $module)) { | ||
$this->tools->writeError("Module `{$module}` does not exist."); | ||
exit(1); | ||
} | ||
|
||
/** | ||
* remove uninstalled module recursive | ||
* | ||
* @param string $dir | ||
* @return boolean | ||
*/ | ||
private function recurseRmdir($dir) | ||
{ | ||
if (is_dir($dir)) { | ||
chmod($dir, 0775); | ||
$files = array_diff(scandir($dir), array('.', '..')); | ||
foreach ($files as $file) { | ||
(is_dir("$dir/$file")) ? $this->recurseRmdir("$dir/$file") : unlink("$dir/$file"); | ||
} | ||
$removed = rmdir($dir); | ||
} else { | ||
$removed = false; | ||
} | ||
if (!\ProcessWire\wire('modules')->getModule($module, array('noPermissionCheck' => true, 'noInit' => true)) && $remove === false) { | ||
$this->tools->writeError("Module `{$module}` is not installed."); | ||
exit(1); | ||
} | ||
} | ||
|
||
return $removed; | ||
/** | ||
* remove uninstalled module recursive | ||
* | ||
* @param string $dir | ||
* @return boolean | ||
*/ | ||
private function recurseRmdir($dir) { | ||
if (is_dir($dir)) { | ||
chmod($dir, 0775); | ||
$files = array_diff(scandir($dir), array('.', '..')); | ||
foreach ($files as $file) { | ||
(is_dir("$dir/$file")) ? $this->recurseRmdir("$dir/$file") : unlink("$dir/$file"); | ||
} | ||
$removed = rmdir($dir); | ||
} else { | ||
$removed = false; | ||
} | ||
|
||
return $removed; | ||
} | ||
} |
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
Oops, something went wrong.