diff --git a/CHANGELOG.md b/CHANGELOG.md index c5f82ff..b3b51b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CliTools Changelog ================== +2.1.2 - 2015-07-22 +------------------ +- Fixed smaller issues +- Rollback to Symfony 2.7.1 + 2.1.1 - 2015-07-17 ------------------ - Fixed `php:composer` global command usage diff --git a/Makefile b/Makefile index 58f910f..80ab517 100644 --- a/Makefile +++ b/Makefile @@ -8,3 +8,6 @@ install: autoload: sh -c "cd src ; composer dump-autoload --optimize --no-dev" + +sloccount: + sloccount src/app/ src/command.php diff --git a/src/app/CliTools/Console/Command/Common/FixRightsCommand.php b/src/app/CliTools/Console/Command/Common/FixRightsCommand.php new file mode 100644 index 0000000..a0bf82e --- /dev/null +++ b/src/app/CliTools/Console/Command/Common/FixRightsCommand.php @@ -0,0 +1,125 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Output\OutputInterface; + +class FixRightsCommand extends \CliTools\Console\Command\AbstractCommand { + + /** + * Configure command + */ + protected function configure() { + $this + ->setName('fix-rights') + ->setDescription('Fix rights of multiple directories and files') + ->addArgument( + 'path', + InputArgument::REQUIRED | InputArgument::IS_ARRAY, + 'Path (multiple)' + ); + } + + /** + * Execute command + * + * @param InputInterface $input Input instance + * @param OutputInterface $output Output instance + * + * @return int|null|void + */ + public function execute(InputInterface $input, OutputInterface $output) { + $pathList = $this->input->getArgument('path'); + + $this->checkPathList($pathList); + + + foreach ($pathList as $path) { + if (is_dir($path)) { + $iterator = new \RecursiveDirectoryIterator($path); + $iterator = new \RecursiveIteratorIterator($iterator); + + /** @var \SplFileInfo $entry */ + foreach ($iterator as $entry) { + $this->setRights($entry); + } + } else { + $entry = new \SplFileInfo($path); + $this->setRights($entry); + } + } + } + + /** + * Set rights for file + * + * @param \SplFileInfo $file + */ + protected function setRights(\SplFileInfo $file) { + $isDir = false; + + if ($file->isDir()) { + $perms = fileperms($file->getPathname()); + $isDir = true; + } elseif ($file->isFile()) { + $perms = fileperms($file->getPathname()); + } + + // Owner + $perms = $perms | 0x0100; + $perms = $perms | 0x0080; + if ($isDir) { + $perms = $perms | 0x0800; + } + + // Group + $perms = $perms | 0x0020; + $perms = $perms | 0x0010; + if ($isDir) { + $perms = $perms | 0x0800; + } + + // Others + $perms = $perms | 0x0004; + $perms = $perms | 0x0002; + if ($isDir) { + $perms = $perms | 0x0800; + } + + chmod($file->getPathname(), $perms); + } + + /** + * Check path list + * + * @param $pathList + * @throws \RuntimeException + */ + protected function checkPathList($pathList) { + foreach ($pathList as $path) { + if (!file_exists($path)) { + throw new \RuntimeException('Path "' . $path . '" does not exists or is not writeable'); + } + } + } +} diff --git a/src/app/CliTools/Shell/CommandBuilder/AbstractCommandBuilder.php b/src/app/CliTools/Shell/CommandBuilder/AbstractCommandBuilder.php index 45781b9..8bc47ad 100644 --- a/src/app/CliTools/Shell/CommandBuilder/AbstractCommandBuilder.php +++ b/src/app/CliTools/Shell/CommandBuilder/AbstractCommandBuilder.php @@ -20,7 +20,7 @@ * along with this program. If not, see . */ -use CliTools\Console\Shell\Executor; +use CliTools\Shell\Executor; class AbstractCommandBuilder implements CommandBuilderInterface { diff --git a/src/app/CliTools/Shell/CommandBuilder/CommandBuilderInterface.php b/src/app/CliTools/Shell/CommandBuilder/CommandBuilderInterface.php index 6d9bc9b..cfa3b59 100644 --- a/src/app/CliTools/Shell/CommandBuilder/CommandBuilderInterface.php +++ b/src/app/CliTools/Shell/CommandBuilder/CommandBuilderInterface.php @@ -20,7 +20,7 @@ * along with this program. If not, see . */ -use CliTools\Console\Shell\Executor; +use CliTools\Shell\Executor; interface CommandBuilderInterface { /** @@ -245,28 +245,28 @@ public function build(); /** * Get executor * - * @return \CliTools\Console\Shell\Executor + * @return \CliTools\Shell\Executor */ public function getExecutor(); /** * Set executor * - * @param \CliTools\Console\Shell\Executor $executor + * @param \CliTools\Shell\Executor $executor */ - public function setExecutor(\CliTools\Console\Shell\Executor $executor); + public function setExecutor(\CliTools\Shell\Executor $executor); /** * Execute command * - * @return \CliTools\Console\Shell\Executor + * @return \CliTools\Shell\Executor */ public function execute(); /** * Execute command * - * @return \CliTools\Console\Shell\Executor + * @return \CliTools\Shell\Executor */ public function executeInteractive(); diff --git a/src/app/CliTools/Shell/Executor.php b/src/app/CliTools/Shell/Executor.php index f57fcbf..34a6814 100644 --- a/src/app/CliTools/Shell/Executor.php +++ b/src/app/CliTools/Shell/Executor.php @@ -1,6 +1,6 @@